Introduce new hooks, upgrade existing and add wrapper script to call pylint

This commit is contained in:
Benjamin Renard 2024-02-13 13:08:46 +01:00
parent 9c98287a6a
commit c6f2d856aa
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC
3 changed files with 80 additions and 42 deletions

View file

@ -1,45 +1,64 @@
# Pre-commit hooks to run tests and ensure code is cleaned. # Pre-commit hooks to run tests and ensure code is cleaned.
# See https://pre-commit.com for more information # See https://pre-commit.com for more information
---
repos: repos:
- repo: https://github.com/asottile/pyupgrade - repo: https://github.com/astral-sh/ruff-pre-commit
rev: v3.15.0 rev: v0.1.6
hooks: hooks:
- id: pyupgrade - id: ruff
args: ['--keep-percent-format', '--py37-plus'] args: ["--fix"]
- repo: https://github.com/psf/black - repo: https://github.com/asottile/pyupgrade
rev: 23.11.0 rev: v3.15.0
hooks: hooks:
- id: black - id: pyupgrade
args: ['--target-version', 'py37', '--line-length', '100'] args: ["--keep-percent-format", "--py37-plus"]
- repo: https://github.com/PyCQA/isort - repo: https://github.com/psf/black
rev: 5.12.0 rev: 23.11.0
hooks: hooks:
- id: isort - id: black
args: ['--profile', 'black', '--line-length', '100'] args: ["--target-version", "py37", "--line-length", "100"]
- repo: https://github.com/PyCQA/flake8 - repo: https://github.com/PyCQA/isort
rev: 6.1.0 rev: 5.12.0
hooks: hooks:
- id: flake8 - id: isort
args: ['--max-line-length=100'] args: ["--profile", "black", "--line-length", "100"]
- repo: local - repo: https://github.com/PyCQA/flake8
hooks: rev: 6.1.0
- id: pylint hooks:
name: pylint - id: flake8
entry: pylint args: ["--max-line-length=100"]
language: system - repo: https://github.com/codespell-project/codespell
types: [python] rev: v2.2.2
require_serial: true hooks:
- repo: https://github.com/PyCQA/bandit - id: codespell
rev: 1.7.5 args:
hooks: - --ignore-words-list=exten
- id: bandit - --skip="./.*,*.csv,*.json,*.ini,*.subject,*.txt,*.html,*.log,*.conf"
args: [--skip, "B101", --recursive, "mylib"] - --quiet-level=2
#- repo: local - --ignore-regex=.*codespell-ignore$
# hooks: #- --write-changes # Uncomment to write changes
# - id: pytest exclude_types: [csv, json]
# name: pytest - repo: https://github.com/adrienverge/yamllint
# entry: python3 -m pytest tests rev: v1.32.0
# language: system hooks:
# types: [python] - id: yamllint
# pass_filenames: false ignore: .github/
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
hooks:
- id: prettier
args: ["--print-width", "100"]
- repo: local
hooks:
- id: pylint
name: pylint
entry: ./.pre-commit-pylint
language: system
types: [python]
require_serial: true
- repo: https://github.com/PyCQA/bandit
rev: 1.7.5
hooks:
- id: bandit
args: [--skip, "B101", --recursive]
minimum_pre_commit_version: 3.2.0 minimum_pre_commit_version: 3.2.0

19
.pre-commit-pylint Executable file
View file

@ -0,0 +1,19 @@
#!/bin/bash
PWD=`pwd`
if [ -d "$PWD/venv" ]
then
echo "Run pylint inside venv ($PWD/venv)..."
$PWD/venv/bin/pylint "$@"
exit $?
elif [ -e "$PWD/pyproject.toml" ]
then
echo "Run pylint using poetry..."
poetry run pylint "$@"
exit $?
else
echo "Run pylint at system scope..."
pylint "$@"
exit $?
fi

View file

@ -3,5 +3,5 @@ from debian:stable-slim
RUN apt-get update && apt-get install --no-install-recommends -y python3-all python3-dev python3-pip python3-venv build-essential pylint git && apt-get clean && rm -fr rm -rf /var/lib/apt/lists/* RUN apt-get update && apt-get install --no-install-recommends -y python3-all python3-dev python3-pip python3-venv build-essential pylint git && apt-get clean && rm -fr rm -rf /var/lib/apt/lists/*
RUN pip install pre-commit --break-system-packages RUN pip install pre-commit --break-system-packages
RUN mkdir /tmp/src RUN mkdir /tmp/src
COPY .pre-commit-config.yaml fake_python_module /tmp/src/ COPY .pre-commit-config.yaml .pre-commit-pylint fake_python_module /tmp/src/
RUN cd /tmp/src && git init && git add * && pre-commit autoupdate && pre-commit run --all-files && rm -fr /tmp/src RUN cd /tmp/src && git init && git add * && pre-commit autoupdate && pre-commit run --all-files && rm -fr /tmp/src