From abc21ce3b2687aaaaaff5b1a5324667dd19cda0c Mon Sep 17 00:00:00 2001 From: nesnoj Date: Tue, 21 Oct 2025 18:12:04 +0200 Subject: [PATCH 1/7] Update pre-commit config and modernize linting setup - Consolidate linting with ruff, replaces black and extents linting - Additional file checks (case-conflict, docstring-first, mixed-line-ending) - Configure global excludes for build artifacts and cache directories - Enable ruff docstring checking with numpy convention --- .pre-commit-config.yaml | 45 +++++++++++++++++++++++++++++++++++++---- pyproject.toml | 27 ++++++++++++++++++++++--- 2 files changed, 65 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 821c6237..e0e21c44 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/) + 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.1 + 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.18.2 + 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/pyproject.toml b/pyproject.toml index a4fcb367..57017066 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.15.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"] From b8a76c144b45192963def6a23395998224034b70 Mon Sep 17 00:00:00 2001 From: nesnoj Date: Tue, 21 Oct 2025 18:14:08 +0200 Subject: [PATCH 2/7] Add GH Actions workflow for automated pre-commit checks in CI Ensures consistent checking locally and on GH --- .github/workflows/pre-commit.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/pre-commit.yml 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 From 296486825d507f0df63cc4c81adce9a618232af1 Mon Sep 17 00:00:00 2001 From: nesnoj Date: Tue, 21 Oct 2025 18:38:09 +0200 Subject: [PATCH 3/7] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0eb6fa2c..a743fa3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,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) From f91e00fb58269610eec305d7a5e9c3125a0aaf9b Mon Sep 17 00:00:00 2001 From: nesnoj Date: Tue, 21 Oct 2025 18:48:40 +0200 Subject: [PATCH 4/7] Delete old .flake8 cfg --- .flake8 | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 .flake8 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 From d6513ef36f5e498ebcced40d994197b7f1cf442f Mon Sep 17 00:00:00 2001 From: nesnoj Date: Tue, 21 Oct 2025 18:49:07 +0200 Subject: [PATCH 5/7] Exclude 'open_mastr/soap_api/' and 'scripts/' from linting --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e0e21c44..6dbcdb4d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ # Global excludes - apply to all hooks -exclude: ^(build/|dist/|.*\.egg-info/|\.tox/|\.pytest_cache/|\.mypy_cache/|__pycache__/|postprocessing/) +exclude: ^(build/|dist/|.*\.egg-info/|\.tox/|\.pytest_cache/|\.mypy_cache/|__pycache__/|postprocessing/|open_mastr/soap_api/|scripts/) repos: # Base pre-commit hooks for common issues From 65b1fadd1b0e9e388173ff06befc11ce742a03e0 Mon Sep 17 00:00:00 2001 From: nesnoj Date: Thu, 11 Dec 2025 23:36:24 +0100 Subject: [PATCH 6/7] Fix merge conflict error --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 616e7e29..3ca0cf3f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -78,7 +78,7 @@ open_mastr = [ include = ["open_mastr", "open_mastr.soap_api", "open_mastr.soap_api.metadata", "open_mastr.utils", "open_mastr.utils.config", "open_mastr.xml_download"] # package names should match these glob patterns (["*"] by default) # from setup.py - not yet included in here -# download_url="https://github.com/OpenEnergyPlatform/open-MaStR/archive""/refs/tags/v0.15.0.tar.gz", +# download_url="https://github.com/OpenEnergyPlatform/open-MaStR/archive""/refs/tags/v0.16.0.tar.gz", [tool.ruff] line-length = 88 From 630771cbf90d1f79f21bddb86676284f136b51ec Mon Sep 17 00:00:00 2001 From: nesnoj Date: Mon, 15 Dec 2025 11:54:23 +0100 Subject: [PATCH 7/7] Update pre-commit config --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6dbcdb4d..9537c213 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,7 +24,7 @@ repos: # 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.1 + rev: v0.14.9 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] @@ -32,7 +32,7 @@ repos: # mypy - static type checking - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.18.2 + rev: v1.19.1 hooks: - id: mypy additional_dependencies: