Commit d746a423 authored by Moul's avatar Moul
Browse files

[doc] duniterpy#169: Update pre-commit doc. Document CI linter hook usage

Give the choices to install pre-commit via the distrib or via pip

Fix Poetry link, since the website changed of CMS
parent 7645a726
Pipeline #13156 passed with stages
in 3 minutes and 29 seconds
......@@ -30,7 +30,7 @@ silkaj> cd ..
git clone
Use DuniterPy as a [path dependency](
Use DuniterPy as a [path dependency](
poetry add ../duniterpy
......@@ -47,19 +47,45 @@ Please read their documentations on how to use them the best possible.
## Pre-commit
We are using [`pre-commit`]( tool to perform checks on staged changes before committing.
We are using it for `black` formatting, `isort` imports sorting, and `gitlab-ci` linting. We will use it for `pylint` code linting, `mypy` typing in the future.
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:
Install `pre-commit` from your distribution. In case it is an outdated version, install it from `pip`:
sudo apt install pre-commit
silkaj> pre-commit install
pip install --user pre-commit
To install the `git-hooks`, run:
silkaj> poetry shell
(silkaj-58dUTebQ-py3.9) pre-commit install
> pre-commit install
Then each time you commit changes, the hooks will perform checks.
To manually run one of the tool above, run (eg for `isort`):
> pre-commit run --all-files isort
To run all checks on all files:
> pre-commit run -a
### Authorization for GitLab CI linter hook
`pre-commit run -a (gitlab-ci-linter)` is failing due to authorization required for CI lint API accesses.
When running this command, just ignore this failed hook.
In case you want to commit a `.gitlab-ci.yml` edition, this hook will prevent the commit creation.
You can [skip the hooks]( with `git commit -m "msg" --no-verify`.
This is fine for occasional `.gitlab-ci.yml` editions. In case you would like to edit this file more often and have it checked, ask a maintainer to provide you with `GITLAB_PRIVATE_TOKEN` environment variable that can be set into a shell configuration.
With Bash, in `$HOME/.bashrc` add the following:
With Fish, in `$HOME/.config/fish/` add the following:
Check out duniterpy#169 for more details.
### Black formatting
We are using [Black]( formatter tool.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment