Skip to content

Commit

Permalink
Added poetry checks in pre-commit and actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
djspstfc committed Jul 24, 2024
1 parent 22566bc commit 6f91fe9
Show file tree
Hide file tree
Showing 5 changed files with 501 additions and 473 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ jobs:
- name: Install Dependencies
run: |
poetry env use 3.12
- name: Check Poetry
run: |
poetry check --lock
- name: Run black
run: |
poetry install --only black
Expand Down
84 changes: 52 additions & 32 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,54 @@
fail_fast: true
repos:
- repo: local
hooks:
- id: black
name: black
entry: poetry run black
language: system
types: [file, python]
- id: isort
name: isort
entry: poetry run isort
language: system
types: [file, python]
- id: ruff
name: ruff
entry: poetry run ruff check --fix
language: system
types: [file, python]
- id: bandit
name: bandit
entry: poetry run bandit -c pyproject.toml -r .
language: system
types: [file, python]
- id: xenon
name: xenon
entry: bash -c "poetry run xenon -a $(poetry run python -c \"import tomllib; f = open('pyproject.toml','rb') ; data = tomllib.load(f); f.close(); print(data['tool']['quality']['mccabe']['average'])\") -b $(poetry run python -c \"import tomllib; f = open('pyproject.toml','rb') ; data = tomllib.load(f); f.close(); print(data['tool']['quality']['mccabe']['block'])\") -m $(poetry run python -c \"import tomllib; f = open('pyproject.toml','rb') ; data = tomllib.load(f); f.close(); print(data['tool']['quality']['mccabe']['module'])\") . "
language: system
types: [file, python]
- id: mypy
name: mypy
entry: poetry run mypy --no-namespace-packages --exclude esgf_playground_utils/models/__init__.py
language: system
types: [ file, python ]
- repo: https://github.com/python-poetry/poetry
rev: '1.8.3' # add version here
hooks:
- id: poetry-check
- id: poetry-lock
- repo: local
hooks:
- id: black
name: black
entry: poetry run black
language: system
types: [ file, python ]
- id: isort
name: isort
entry: poetry run isort
language: system
types: [ file, python ]
- id: ruff linter
name: ruff lint
entry: poetry run ruff check --fix
language: system
types: [ file, python ]
- id: bandit
name: bandit
entry: poetry run bandit -c pyproject.toml -r .
language: system
types: [ file, python ]
- id: xenon
name: xenon
entry: bash -c "poetry run xenon -a $(poetry run python -c \"import tomllib; f = open('pyproject.toml','rb') ; data = tomllib.load(f); f.close(); print(data['tool']['quality']['mccabe']['average'])\") -b $(poetry run python -c \"import tomllib; f = open('pyproject.toml','rb') ; data = tomllib.load(f); f.close(); print(data['tool']['quality']['mccabe']['block'])\") -m $(poetry run python -c \"import tomllib; f = open('pyproject.toml','rb') ; data = tomllib.load(f); f.close(); print(data['tool']['quality']['mccabe']['module'])\") . "
language: system
types: [ file, python ]
- id: mypy
name: mypy
entry: poetry run mypy --no-namespace-packages --exclude esgf_playground_utils/models/__init__.py
language: system
types: [ file, python ]
- id: bandit
name: bandit
entry: poetry run bandit -c pyproject.toml -r .
language: system
types: [ file, python ]
- id: xenon
name: xenon
entry: bash -c "poetry run xenon -a $(poetry run python -c \"import tomllib; f = open('pyproject.toml','rb') ; data = tomllib.load(f); f.close(); print(data['tool']['quality']['mccabe']['average'])\") -b $(poetry run python -c \"import tomllib; f = open('pyproject.toml','rb') ; data = tomllib.load(f); f.close(); print(data['tool']['quality']['mccabe']['block'])\") -m $(poetry run python -c \"import tomllib; f = open('pyproject.toml','rb') ; data = tomllib.load(f); f.close(); print(data['tool']['quality']['mccabe']['module'])\") . "
language: system
types: [ file, python ]
- id: mypy
name: mypy
entry: poetry run mypy --no-namespace-packages --exclude esgf_playground_utils/models/__init__.py
language: system
types: [ file, python ]
14 changes: 8 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ foo@bar:~$ poetry run install pre-commit

When you commit, the following checks will be run:

- black[^1] (python style formatter)
- isort[^1] (python import order checker)
- ruff[^1] (python linter)
- mypy (python static type analysis)
- bandit (pythin SAST analyis)
- xenon (McCabe cyclomatc complexity analysis)
- poetry-check (checks the conformity of the pyproject.toml and poetry.lock file)
- poetry-lock[^1] (ensures an up-to-date lock file)
- black[^1] (python style formatter)
- isort[^1] (python import order checker)
- ruff linter[^1] (python linter)
- mypy (python static type analysis)
- bandit (python SAST analyis)
- xenon (McCabe cyclomatc complexity analysis)

You can disable the `pre-commit hooks` per commit with the flag `--no-verify` however all checks will be preformed in the CI.

Expand Down
Loading

0 comments on commit 6f91fe9

Please sign in to comment.