diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..47fe30ad7ce4c27c1d12f386b719909f4c7953d2 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,5 @@ +repos: +- repo: https://github.com/psf/black + rev: 21.5b0 + hooks: + - id: black diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 044ff64add289b3a3858a4cfd8e0525697fdafd9..bc695d8cfa1c75b44d8e15cc09df5fa524aef921 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,7 +1,31 @@ # Contribute guide -## Release workflow +## Pre-commit +We are using [`pre-commit`](https://pre-commit.com/) tool to perform checks on staged changes before committing. Such as black formatting. +Depending whether you prefer to work ouside or inside Poetry virtual environment, you should stick to one usage or use both to still have this usefull checks. +`pre-commit` can be used from the installation on your system or from inside Poetry virtual environment where it is installed. + +To install the `git-hooks`, run: +```bash +pip3 install --user pre-commit +duniterpy> pre-commit install +``` +```bash +duniterpy> poetry shell +(duniterpy-UyTOfZjU-py3.9) pre-commit install +``` + +### Black formatting +We are using [Black](https://github.com/psf/black) formatter tool. +Run Black on a Python file to format it: +```bash +poetry run black duniterpy/file.py +``` +With `pre-commit`, Black is called on staged files, so the commit should fail in case black would make changes. +You will have to add Black changes in order to commit your changes. + +## Release workflow To handle a release, you have to respect this workflow: * Verify all features and bug fixes are merged in the `dev` branch. diff --git a/README.md b/README.md index f1e74b4b174ce653d98a964e783238ffb849f64f..3e70265dd53b3052ad4b482f8734f68275a21933 100644 --- a/README.md +++ b/README.md @@ -73,8 +73,6 @@ poetry run make docs * When writing docstrings, use the reStructuredText format recommended by https://www.python.org/dev/peps/pep-0287/#docstring-significant-features * Use `make` commands to check the code and the format. -Black, the formatting tool, requires Python 3.6 or higher. - * Install runtime dependencies ```bash poetry install --no-dev diff --git a/pyproject.toml b/pyproject.toml index b4da4b698c4aa950a0f0e9290ce584fc808aa183..3c4e5491271d8b39a60d469980e8c7b5c6bf3181 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,5 +38,6 @@ websocket-client = "^0.57" black = {version = "^21.4b2", allow-prereleases = true} mypy = "^0.790" pylint = "^2.7.2" +pre-commit = "^2.12.1" sphinx = "^3.2.1" sphinx_rtd_theme = "^0.5.0"