From b6685aabd2c7dfccc3e0f89d26c177213b293967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20G=C3=BCnther?= Date: Wed, 21 Oct 2020 21:12:24 +0200 Subject: [PATCH] Add a `pre-commit` hook for `black` 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 --- .pre-commit-config.yaml | 5 +++++ pyproject.toml | 17 +++++++++++++++++ setup.py | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 pyproject.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6e974cba9..8f45cc334 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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+ diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..faa891c2e --- /dev/null +++ b/pyproject.toml @@ -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" diff --git a/setup.py b/setup.py index cc34195a5..c3c0bf9b3 100755 --- a/setup.py +++ b/setup.py @@ -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'],