From e2176f896c0b41e77800efc6a61f95a69bf7d918 Mon Sep 17 00:00:00 2001 From: Lorenzo Balzani Date: Fri, 10 May 2024 17:43:41 +0200 Subject: [PATCH] STYLE: enforce PEP8 and linting --- .github/workflows/lint_and_style.yaml | 34 ++++++++++++++ .pre-commit-config.yaml | 65 +++++++++++++++++++++++++++ .pylintrc | 0 setup.cfg | 27 +++++++++++ 4 files changed, 126 insertions(+) create mode 100644 .github/workflows/lint_and_style.yaml create mode 100644 .pre-commit-config.yaml create mode 100644 .pylintrc create mode 100644 setup.cfg diff --git a/.github/workflows/lint_and_style.yaml b/.github/workflows/lint_and_style.yaml new file mode 100644 index 0000000..555c8d9 --- /dev/null +++ b/.github/workflows/lint_and_style.yaml @@ -0,0 +1,34 @@ +name: lint_and_style + +on: + pull_request: + push: + branches: + - main + - master + +jobs: + pre-commit: + runs-on: ubuntu-latest + if: github.event_name == 'pull_request' || (github.ref == 'refs/heads/main' && github.event_name == 'push') || (github.ref == 'refs/heads/master' && github.event_name == 'push') + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + with: + python-version: '3.9' + - run: pip install pylint & pip install -r docker/requirements.txt + - uses: pre-commit/action@v3.0.1 + pylint: + runs-on: ubuntu-latest + needs: pre-commit + continue-on-error: true + if: false #github.event_name == 'pull_request' || (github.ref == 'refs/heads/main' && github.event_name == 'push') || (github.ref == 'refs/heads/master' && github.event_name == 'push') + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + with: + python-version: '3.9' + - run: pip install pylint & pip install -r docker/requirements.txt + - uses: pre-commit/action@v3.0.1 + with: + extra_args: --hook-stage manual pylint-all --all-files diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..5e7fc18 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,65 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-docstring-first + - id: check-toml + - id: check-yaml + - id: mixed-line-ending + args: [--fix=lf] + - id: end-of-file-fixer + - repo: https://gitlab.com/bmares/check-json5 + rev: v1.0.0 + hooks: + - id: check-json5 + exclude: data/.* + - repo: https://github.com/hhatto/autopep8 + rev: v2.1.0 + hooks: + - id: autopep8 + args: [--in-place, --aggressive, --exit-code] + types: [python] + - repo: local + hooks: + - id: pylint + name: pylint + entry: pylint + language: system + types: [python] + args: + [ + "--max-line-length=120", + "--errors-only", + ] + - id: pylint + alias: pylint-all + name: pylint-all + entry: pylint + language: system + types: [python] + args: + [ + "--max-line-length=120", + ] + stages: [manual] + - repo: https://github.com/pycqa/flake8 + rev: 7.0.0 + hooks: + - id: flake8 + args: [--config=setup.cfg] + additional_dependencies: + - flake8-bugbear==22.10.27 + - flake8-comprehensions==3.10.1 + - torchfix==0.0.2 + - repo: https://github.com/facebook/usort + rev: v1.0.7 + hooks: + - id: usort + name: Sort imports with µsort + description: Safe, minimal import sorting + language: python + types_or: + - python + - pyi + entry: usort format + require_serial: true diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..e69de29 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..659f94b --- /dev/null +++ b/setup.cfg @@ -0,0 +1,27 @@ +[metadata] +description-file = README.md +license_file = LICENSE + +[build_sphinx] +source-dir = docs/source +build-dir = docs/build +all_files = 1 + +[pycodestyle] +max-line-length = 120 +statistics = True +show-pep8 = True +show-source = True +ignore = W391, W605, W503 + +[pep8] +max-line-length=120 +show-pep8 = true +statistics = true +ignore = W391, W503 + +[flake8] +max-line-length = 120 +ignore = E203, E402, W503, W391 +exclude = venv +extend-select = B901, C401, C408, C409