Skip to content

Commit

Permalink
Add a pre-commit hook for black
Browse files Browse the repository at this point in the history
Done as [documented][0]. Since one has to have `black` installed in
order to make use of this hook, I added `black` to the dev dependencies.
The "pyproject.toml" file is necessary, because that's the only place
that `black` will look for configuration parameters. Last but not least,
the `[build-system]` section in "pyproject.toml" is because we still use
"setup.py" for packaging and `pip` would get confused by the presence of
"pyproject.toml". The `[build-system]` section just tells it to look for
"setup.py".

[0]: https://black.readthedocs.io/en/stable/version_control_integration.html#version-control-integration
  • Loading branch information
gnn committed Oct 21, 2020
1 parent c6c85f0 commit b6685aa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ repos:
rev: master
hooks:
- id: flake8
- repo: https://github.com/psf/black
rev: stable
hooks:
- id: black
language_version: python3 # Should be a command that runs python3.6+
17 changes: 17 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[tool.black]
line-length = 79
target-version = ["py36", "py37", "py38"]
include = '\.pyi?$'
exclude = '''
/(
\.git
| \.tox
| build
| ci
| dist
)/
'''

[build-system]
requires = ["setuptools>=41.0", "wheel"]
build-backend = "setuptools.build_meta"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def read(*names, **kwargs):
# eg: 'aspectlib==1.1.1', 'six>=1.7',
],
extras_require={
"dev": ["pytest", "tox"]
"dev": ["black", "pytest", "tox"]
# eg:
# 'rst': ['docutils>=0.11'],
# ':python_version=="2.6"': ['argparse'],
Expand Down

0 comments on commit b6685aa

Please sign in to comment.