Skip to content

Commit 243e2ff

Browse files
authored
Use pre-commit to prevent breaking CI due to ruff version update (#507)
1 parent b1a0afa commit 243e2ff

5 files changed

Lines changed: 37 additions & 18 deletions

File tree

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,13 @@ updates:
55
directory: "/"
66
schedule:
77
interval: "weekly"
8+
# Keeps pinned pre-commit hooks (ruff, rstcheck) up to date. Dependabot opens
9+
# a PR when a hook's rev has a new release, and CI runs on that PR.
10+
- package-ecosystem: "pre-commit"
11+
directory: "/"
12+
schedule:
13+
interval: "weekly"
14+
commit-message:
15+
prefix: "chore"
16+
cooldown:
17+
default-days: 7

.github/workflows/pyscal.yml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,10 @@ jobs:
8383
if: ${{ always() }}
8484
run: uv pip freeze
8585

86-
- name: Ruff check
86+
- name: Linting using pre-commit
8787
if: ${{ always() }}
8888
run: |
89-
ruff check .
90-
91-
- name: Ruff format
92-
if: ${{ always() }}
93-
run: |
94-
ruff format . --check
89+
pre-commit run --all-files --show-diff-on-failure
9590
9691
- name: Check typing with mypy
9792
if: ${{ always() }}
@@ -104,11 +99,6 @@ jobs:
10499
python -c "import pyscal"
105100
pytest -n auto --strict-markers --hypothesis-profile ci tests/
106101
107-
- name: Syntax check documentation
108-
if: ${{ always() }}
109-
run: |
110-
rstcheck -r docs
111-
112102
- name: Install font (xkcd) for documentation
113103
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == env.DEFAULT_PYTHON_VERSION }}
114104
run: |

.pre-commit-config.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# The ruff version below is the single source of truth for linting/formatting.
2+
# CI runs these same hooks, so local and CI ruff versions can never diverge.
3+
# Bump the rev here (e.g. via `pre-commit autoupdate`) to upgrade ruff.
4+
repos:
5+
- repo: https://github.com/astral-sh/ruff-pre-commit
6+
rev: v0.16.0
7+
hooks:
8+
- id: ruff-check
9+
- id: ruff-format
10+
- repo: https://github.com/rstcheck/rstcheck
11+
rev: v6.2.5
12+
hooks:
13+
- id: rstcheck
14+
# Scope to docs/ to match the previous CI `rstcheck -r docs`.
15+
files: ^docs/.*\.rst$
16+
# sphinx is needed so sphinx-specific roles/directives (e.g. :func:)
17+
# resolve; matches the docs extra's `sphinx < 9` pin.
18+
additional_dependencies: ["sphinx<9"]

CONTRIBUTING.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Create pull request
3333
source ~/venv/pyscal/bin/activate
3434
pip install -U pip
3535
pip install -e ".[tests,docs]"
36+
pre-commit install
3637
3738
4. Run the tests to ensure everything works:
3839

@@ -49,12 +50,12 @@ Create pull request
4950
Now you can make your changes locally.
5051

5152
6. When you're done making changes, check that your changes pass ruff, mypy and the
52-
tests:
53+
tests. Ruff runs automatically on ``git commit`` via pre-commit, or run it
54+
manually with:
5355

5456
.. code-block:: bash
55-
56-
ruff check .
57-
ruff format .
57+
58+
pre-commit run --all-files
5859
mypy src/pyscal
5960
pytest -n auto
6061

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,13 @@ dependencies = [
4747

4848
[project.optional-dependencies]
4949
tests = [
50-
"ruff",
50+
"pre-commit",
5151
"mypy",
5252
"hypothesis",
5353
"pytest",
5454
"pytest-cov",
5555
"pytest-mock",
5656
"pytest-xdist",
57-
"rstcheck",
5857
"pandas-stubs",
5958
"scipy-stubs",
6059
]
@@ -121,6 +120,7 @@ ignore = [
121120
"PLR0911", # Too many return statements
122121
"PLR0912", # Too many branches
123122
"PLR0913", # Too many arguments
123+
"PLR0917", # Too many positional arguments
124124
"PLR0915", # Too many statements
125125
]
126126

0 commit comments

Comments
 (0)