From a0004349f3a47efb6d71241df614a7145ab53ade Mon Sep 17 00:00:00 2001 From: julien-talkair Date: Thu, 1 Jul 2021 17:37:43 +0200 Subject: [PATCH] :tada: run code quality checks automatically * installs black and flake8 as pre-commit hooks * runs only on modified files --- .pre-commit-config.yaml | 10 ++++++++++ CONTRIBUTING.md | 9 +++++++++ requirements.txt | 1 + 3 files changed, 20 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..7853306ae --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,10 @@ +repos: +- repo: https://github.com/ambv/black + rev: 21.6b0 + hooks: + - id: black + language_version: python3.7 +- repo: https://gitlab.com/pycqa/flake8 + rev: 3.9.2 + hooks: + - id: flake8 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 682e5134c..3a94b9b67 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -177,6 +177,15 @@ tools installed. **⚠️ Note that formatting and linting is currently only possible for Python modules in `.py` files, not Cython modules in `.pyx` and `.pxd` files.** +### Pre-Commit Hooks + +After cloning the repo, after installing the packages from `requirements.txt`, enter the repo folder and run `pre-commit install`. +Each time a `git commit` is initiated, `black` and `flake8` will run automatically on the modified files only. + +In case of error, or when `black` modified a file, the modified file needs to be `git add` once again and a new +`git commit` has to be issued. + + ### Code formatting [`black`](https://github.com/ambv/black) is an opinionated Python code diff --git a/requirements.txt b/requirements.txt index c38380c54..dc2d027b0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,6 +22,7 @@ setuptools packaging>=20.0 typing_extensions>=3.7.4.1,<4.0.0.0; python_version < "3.8" # Development dependencies +pre-commit>=2.13.0 cython>=0.25,<3.0 pytest>=5.2.0 pytest-timeout>=1.3.0,<2.0.0