Home | Ubuntu/Mint | Arch/Manjaro | ssh/gpg | texlive | python | git | steam
To add pre-commit hooks following pre-commit.com↗, install pre-commit
via
pip3 install --user --no-cache-dir --upgrade --break-system-packages pre-commit
, add a .pre-commit-config.yaml
file, containing, e.g.,
and, finally, activate via# See https://pre-commit.com/ for documentation # For installation: # - install via # pip install pre-commit # - activate via # pre-commit install # Now the below hooks will run at any invocation of # git commit # To check all files in the repositoy run # pre-commit run --all-files repos: - repo: meta # this repo checks pre-commit itself hooks: - id: check-hooks-apply # configured hooks apply to at least one file - id: check-useless-excludes # ensures exclude directives apply to at least one file - repo: https://gitlab.com/vojko.pribudic.foss/pre-commit-update rev: v0.4.0post1 hooks: - id: pre-commit-update args: [--dry-run] - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.6.0 hooks: - id: check-added-large-files - id: check-ast - id: check-builtin-literals - id: check-case-conflict - id: check-executables-have-shebangs - id: check-json - id: check-merge-conflict - id: check-shebang-scripts-are-executable - id: check-toml - id: check-xml - id: check-yaml - id: debug-statements - id: end-of-file-fixer - id: mixed-line-ending - id: no-commit-to-branch - id: pretty-format-json args: ["--autofix"] - id: requirements-txt-fixer - id: sort-simple-yaml - id: trailing-whitespace types: [text] - repo: https://github.com/koalaman/shellcheck-precommit rev: v0.10.0 hooks: - id: shellcheck # args: ["--severity=warning"] # Optionally only show errors and warnings - repo: https://github.com/codespell-project/codespell rev: v2.3.0 hooks: - id: codespell args: ['--skip', '*.csv,*.txt'] - repo: https://github.com/rstcheck/rstcheck rev: v6.2.4 hooks: - id: rstcheck args: ["--ignore-directives", "uml"] additional_dependencies: ["rstcheck[sphinx]", "sphinxcontrib-plantuml"] exclude: docs/_templates/ - repo: https://github.com/pre-commit/pygrep-hooks rev: v1.10.0 hooks: - id: python-check-blanket-noqa - id: python-check-blanket-type-ignore - id: python-check-mock-methods - id: python-no-eval - id: python-no-log-warn - id: python-use-type-annotations - id: rst-backticks - id: rst-directive-colons - id: rst-inline-touching-normal - id: text-unicode-replacement-char - repo: https://github.com/thclark/pre-commit-sphinx rev: 0.0.3 hooks: - id: build-docs args: ['--html-dir', 'docs/_build/html', '--source-dir', 'docs/'] language_version: python3 additional_dependencies: [sphinx, sphinx-autoapi, furo, sphinxcontrib-plantuml] - repo: https://github.com/hhatto/autopep8 rev: v2.3.1 hooks: - id: autopep8 - repo: https://github.com/PyCQA/bandit rev: 1.7.9 hooks: - id: bandit args: ["-c", "pyproject.toml"] additional_dependencies: ["bandit[toml]"] - repo: https://github.com/asottile/pyupgrade rev: v3.17.0 hooks: - id: pyupgrade args: ["--py311-plus"] - repo: https://github.com/psf/black-pre-commit-mirror rev: 24.8.0 hooks: - id: black # It is recommended to specify the latest version of Python # supported by your project here, or alternatively use # pre-commit's default_language_version, see # https://pre-commit.com/#top_level-default_language_version language_version: python3.12 - repo: local hooks: - id: isort name: isort entry: isort language: system types: [python] args: ["--settings=setup.cfg", "--line-length=120", "--profile=black", "--force-grid-wrap=2", "--multi-line=3"] - id: flake8 name: flake8 entry: flake8 language: system types: [python] # E265 block comment should start with '# ' # E266 too many leading '#' for block comment # E704 multiple statements on one line (def) # W503 line break before binary operator args: [ "--config=setup.cfg", "--ignore=E265,E266,E704,W503,", "--max-line-length=120", "--exclude=.git,__pycache__", "--select=C,E,F,W,B,B9" ] - id: pycodestyle name: pycodestyle entry: pycodestyle language: system types: [python] # E203 whitespace before ‘,’, ‘;’, or ‘:’ - falsely triggers on list slices # E265 block comment should start with '# ' # E266 too many leading '#' for block comment # E704 multiple statements on one line (def) # W503 line break before binary operator args: [ "--config=setup.cfg", "--ignore=E203,E265,E266,E704,W503,", "--max-line-length=120", "--exclude=.git,__pycache__" ] - id: pydocstyle name: pydocstyle entry: pydocstyle language: system types: [python] args: ["--config=setup.cfg", "--convention=numpy"] - id: sphinx-lint name: sphinx-lint entry: sphinx-lint language: system - id: pylint name: pylint entry: pylint language: system types: [python] # C0302 too many lines # C0325 superfluous-parens # R0801 duplicate-code # R0912 too-many-branches # R0913 too-many-arguments # R0914 too-many-locals # R0915 too-many-statements # W0511 fixme args: [ "-rn", "-sn", "--rcfile=pylintrc", "--disable=C0302,C0325,R0801,R0912,R0913,R0914,R0915,W0511,", "--max-line-length=120", "--ignore=.git,__pycache__" ] - id: mypy name: mypy pass_filenames: false # suppress the normal filename passing entry: mypy . verbose: true language: system types: [python] args: ["--config-file=setup.cfg", "--exclude=(.git|__pycache__)"] - id: pyright name: pyright entry: pyright . language: system types: [python] - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.6.3 hooks: - id: ruff
pre-commit install
.
To run the hook(s) on all files of the repository, run pre-commit run --all-files
or for individual file(s), run pre-commit run --file ...
.
Ensure to have the proper linters, etc. installed (see python).