Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pre-commit hook with Black #1573

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Dhruv Sondhi <[email protected]> Dhruv <[email protected]>
Dhruv Sondhi <[email protected]> Dhruv Sondhi <[email protected]>
Dhruv Sondhi <[email protected]> DhruvSondhi <[email protected]>

Dmitry Volodin <[email protected]>

Epson Heringer <[email protected]>
Epson Heringer <[email protected]> Heringer-Epson <[email protected]>

Expand Down
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
repos:
- repo: https://github.com/psf/black
rev: 21.5b2
hooks:
- id: black
exclude: |
(?x)^(
(tardis/model
| tardis/montecarlo).*
| setup.py
| docs/conf.py
| tardis/_astropy_init.py
)$
andrewfullard marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ stars (*supernovae*).
.. image:: https://badges.gitter.im/Join%20Chat.svg
:target: https://gitter.im/tardis-sn/tardis

.. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white
:target: https://github.com/pre-commit/pre-commit
:alt: pre-commit

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black

Expand Down
2 changes: 2 additions & 0 deletions docs/development/code_quality.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Black

A better method is to run Black automatically - first `integrate it within the code editor <https://black.readthedocs.io/en/stable/editor_integration.html>`_ you use and then enable the "format on save" or "format on type" option in your editor settings.

Alternatively, Black will run automatically before each commit if you've installed pre-commit hooks (as mentioned in :ref:`Git worklfow <pre-commit-install>`).

.. warning :: If your code doesn't follow the Black code style, then the Black-check action on your PR will fail.

Naming Conventions
Expand Down
13 changes: 13 additions & 0 deletions docs/development/git_workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ TARDIS repository clone.
repository will always be immediately available next time you start a Python
interpreter and ``import tardis``.

.. _pre-commit-install:

#. Install pre-commit hooks::

$ pre-commit install --install-hooks

This will install all pre-commit hooks used in TARDIS, which will then run
before each commit. You can check the full list of hooks in the
`.pre-commit-config.yaml`.

Workflow summary
----------------

Expand Down Expand Up @@ -328,6 +338,9 @@ In more detail
signals that you're going to type a message on the command line. The `git
commit`_ manual page might also be useful.

All pre-commit hooks will run automatically if you've correctly installed
them before.

#. Push the changes up to your forked repo on GitHub with ``git push`` (see
`git push`_).

Expand Down
18 changes: 3 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,14 @@ build-backend = 'setuptools.build_meta'
[tool.black]
line-length = 80
target-version = ['py36']
exclude = '''
extend-exclude = '''
(
/(
\.eggs # all directories in the root of the project
| \.git
| \.hg
| \.mypy_cache
| \.nox
| \.tox
| \.venv
| \.svn
| _build
| buck-out
| build
| dist
| model # temporary - to remove later
model # temporary - to remove later
| montecarlo # temporary
)/
| setup.py
| docs/conf.py
| _astropy_init.py
)
'''
'''
1 change: 1 addition & 0 deletions tardis_env3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ dependencies:
- coverage

# Code quality
- pre-commit
andrewfullard marked this conversation as resolved.
Show resolved Hide resolved
- black

# Other
Expand Down