Skip to content
Snippets Groups Projects

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

Merged duniterpy#169: Update pre-commit doc. Document CI linter hook usage
All threads resolved!
Merged Moul requested to merge dp_169_gitlab_ci_hooks into dev
All threads resolved!
1 file
+ 33
7
Compare changes
  • Side-by-side
  • Inline
+ 33
7
@@ -30,7 +30,7 @@ silkaj> cd ..
@@ -30,7 +30,7 @@ silkaj> cd ..
git clone https://git.duniter.org/clients/python/duniterpy
git clone https://git.duniter.org/clients/python/duniterpy
```
```
Use DuniterPy as a [path dependency](https://python-poetry.org/docs/versions/#path-dependencies):
Use DuniterPy as a [path dependency](https://python-poetry.org/docs/dependency-specification/#path-dependencies):
```bash
```bash
poetry add ../duniterpy
poetry add ../duniterpy
```
```
@@ -47,19 +47,45 @@ Please read their documentations on how to use them the best possible.
@@ -47,19 +47,45 @@ Please read their documentations on how to use them the best possible.
## Pre-commit
## Pre-commit
We are using [`pre-commit`](https://pre-commit.com/) tool to perform checks on staged changes before committing.
We are using [`pre-commit`](https://pre-commit.com/) 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.
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`:
```bash
```bash
sudo apt install pre-commit
sudo apt install pre-commit
silkaj> pre-commit install
pip install --user pre-commit
```
```
 
To install the `git-hooks`, run:
```bash
```bash
silkaj> poetry shell
> pre-commit install
(silkaj-58dUTebQ-py3.9) 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`):
 
```bash
 
> pre-commit run --all-files isort
 
```
 
To run all checks on all files:
 
```bash
 
> 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](https://stackoverflow.com/a/7230886) 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:
 
```bash
 
export GITLAB_PRIVATE_TOKEN=""
 
```
 
 
With Fish, in `$HOME/.config/fish/config.fish` add the following:
 
```fish
 
set -xg GITLAB_PRIVATE_TOKEN ""
```
```
 
Check out duniterpy#169 for more details.
### Black formatting
### Black formatting
We are using [Black](https://github.com/psf/black) formatter tool.
We are using [Black](https://github.com/psf/black) formatter tool.
Loading