From f25809e33575c45d5e5503aa187478e7902f1e1a Mon Sep 17 00:00:00 2001 From: Martin Wood Date: Tue, 22 Aug 2023 15:07:42 +0100 Subject: [PATCH] Added pre-commit config files --- .flake8 | 9 +++++++ .pre-commit-config.yaml | 55 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 .flake8 create mode 100644 .pre-commit-config.yaml diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..e9bfa57 --- /dev/null +++ b/.flake8 @@ -0,0 +1,9 @@ +[flake8] +# Rule definitions: http://flake8.pycqa.org/en/latest/user/error-codes.html +# D203: 1 blank line required before class docstring +# W503: line break before binary operator +exclude = venv*,__pycache__,node_modules,bower_components,migrations +ignore = D203,W503 +max-complexity = 9 +max-line-length = 88 +extend-ignore = E203 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..05a6f8a --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,55 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: + - repo: https://github.com/kynan/nbstripout + rev: 0.6.1 + hooks: + - id: nbstripout + name: nbstripout - Strip outputs from notebooks (auto-fixes) + args: + - --extra-keys + - "metadata.colab metadata.kernelspec cell.metadata.colab cell.metadata.executionInfo cell.metadata.id cell.metadata.outputId" + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-added-large-files + name: Check for files larger than 5 MB + args: [ "--maxkb=5120" ] + - id: end-of-file-fixer + name: Check for a blank line at the end of scripts (auto-fixes) + exclude: '\.Rd' + - id: trailing-whitespace + name: Check for trailing whitespaces (auto-fixes) + - repo: https://github.com/pycqa/isort + rev: 5.12.0 + hooks: + - id: isort + name: isort - Sort Python imports (auto-fixes) + types: [ cython, pyi, python ] + args: [ "--profile", "black", "--filter-files" ] + - repo: https://github.com/psf/black + rev: 23.3.0 # Replace by any tag/version: https://github.com/psf/black/tags + hooks: + - id: black + name: black - consistent Python code formatting (auto-fixes) + language_version: python # Should be a command that runs python3.6+ + - repo: https://github.com/PyCQA/flake8 + rev: 6.0.0 + hooks: + - id: flake8 + name: flake8 - Python linting + - repo: https://github.com/nbQA-dev/nbQA + rev: 1.6.4 + hooks: + - id: nbqa-isort + name: nbqa-isort - Sort Python imports (notebooks; auto-fixes) + args: [ --nbqa-mutate ] + additional_dependencies: [ isort==5.8.0 ] + - id: nbqa-black + name: nbqa-black - consistent Python code formatting (notebooks; auto-fixes) + args: [ --nbqa-mutate ] + additional_dependencies: [ black==22.3.0 ] + # TODO: Disabled for now until it's clear how to add noqa to specific cells of a Jupyter notebook + #- id: nbqa-flake8 + # name: nbqa-flake8 - Python linting (notebooks) + # additional_dependencies: [ flake8==3.9.2 ]