diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 7b59df75..00000000 --- a/.flake8 +++ /dev/null @@ -1,4 +0,0 @@ -[flake8] -exclude = meta/migrations/ -max-line-length = 100 -extend-ignore = E203 \ No newline at end of file diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 00000000..a0319cee --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,32 @@ +name: Pre-commit Checks + +on: + pull_request: + branches: + - production + - develop + push: + branches: + - production + - develop + +jobs: + pre-commit: + runs-on: ubuntu-latest + name: Run pre-commit hooks + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pre-commit + + - name: Run pre-commit + run: pre-commit run --all-files --show-diff-on-failure diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 821c6237..9537c213 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,43 @@ +# Global excludes - apply to all hooks +exclude: ^(build/|dist/|.*\.egg-info/|\.tox/|\.pytest_cache/|\.mypy_cache/|__pycache__/|postprocessing/|open_mastr/soap_api/|scripts/) + repos: - - repo: https://github.com/psf/black - rev: 22.6.0 + # Base pre-commit hooks for common issues + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 hooks: - - id: black - language_version: python3.11 + - id: trailing-whitespace + exclude: \.ipynb$ + - id: end-of-file-fixer + exclude: \.ipynb$ + - id: check-yaml + - id: check-added-large-files + args: ['--maxkb=1000'] + - id: check-json + - id: check-toml + - id: check-merge-conflict + - id: debug-statements + - id: check-case-conflict + - id: check-docstring-first + - id: mixed-line-ending + args: ['--fix=lf'] + + # Ruff - fast, comprehensive linter and formatter (replaces flake8, isort, pylint, pyupgrade, black, pydocstyle) + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.14.9 + hooks: + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + - id: ruff-format + + # mypy - static type checking + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.19.1 + hooks: + - id: mypy + additional_dependencies: + - types-requests + - types-PyYAML + - types-tqdm + args: [--ignore-missing-imports, --show-error-codes] + exclude: ^(tests/|scripts/|docs/|postprocessing/) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51a38d51..b06c4eae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ and the versioning aims to respect [Semantic Versioning](http://semver.org/spec/ ### Added - Add partial bulk download [#652](https://github.com/OpenEnergyPlatform/open-MaStR/pull/652) +- Modernize linting setup and add pre-commit checks in CI + [#671](https://github.com/OpenEnergyPlatform/open-MaStR/pull/671) ### Changed - Updates the system_catalog dict with missing Einheittyp values [#653](https://github.com/OpenEnergyPlatform/open-MaStR/pull/653) diff --git a/pyproject.toml b/pyproject.toml index 5871bfbe..3ca0cf3f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,8 +49,6 @@ classifiers = [ [project.optional-dependencies] dev = [ - "flake8", - "pylint", "pytest", "pytest-dependency", "xmltodict", @@ -59,7 +57,8 @@ dev = [ "mkdocstrings[python]", "mkdocs-material", "mkdocs-include-markdown-plugin", - "black", + "ruff", + "mypy", ] [project.urls] @@ -80,3 +79,25 @@ include = ["open_mastr", "open_mastr.soap_api", "open_mastr.soap_api.metadata", # from setup.py - not yet included in here # download_url="https://github.com/OpenEnergyPlatform/open-MaStR/archive""/refs/tags/v0.16.0.tar.gz", + +[tool.ruff] +line-length = 88 +target-version = "py39" + +[tool.ruff.lint] +# Enable: +# E - pycodestyle errors +# F - pyflakes +# I - isort (import sorting) +# N - pep8-naming +# W - pycodestyle warnings +# UP - pyupgrade (modernize Python code) +# D - pydocstyle (docstring conventions) +select = ["E", "F", "I", "N", "W", "UP", "D"] +ignore = [] + +[tool.ruff.lint.pydocstyle] +convention = "numpy" + +[tool.ruff.lint.isort] +known-first-party = ["open_mastr"]