Skip to content

Commit fa7edde

Browse files
AnneBeyerogrisel
andauthored
CI Add lock files for linting (scikit-learn#34303)
Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
1 parent 4af1831 commit fa7edde

10 files changed

Lines changed: 79 additions & 10 deletions

File tree

.circleci/config.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ jobs:
99
- run:
1010
name: dependencies
1111
command: |
12-
source build_tools/shared.sh
13-
# Include pytest compatibility with mypy
14-
pip install pytest $(get_dep ruff min) $(get_dep mypy min) cython-lint
12+
pip install -r build_tools/github/lint_lock.txt
1513
- run:
1614
name: linting
1715
command: ./build_tools/linting.sh

.github/workflows/lint.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ jobs:
3232

3333
- name: Install dependencies
3434
run: |
35-
source build_tools/shared.sh
36-
# Include pytest compatibility with mypy
37-
pip install pytest $(get_dep ruff min) $(get_dep mypy min) cython-lint
35+
pip install -r build_tools/github/lint_lock.txt
3836
# we save the versions of the linters to be used in the error message later.
37+
python -c "from importlib.metadata import version; print(f\"pytest={version('pytest')}\")" >> /tmp/versions.txt
3938
python -c "from importlib.metadata import version; print(f\"ruff={version('ruff')}\")" >> /tmp/versions.txt
4039
python -c "from importlib.metadata import version; print(f\"mypy={version('mypy')}\")" >> /tmp/versions.txt
4140
python -c "from importlib.metadata import version; print(f\"cython-lint={version('cython-lint')}\")" >> /tmp/versions.txt

.github/workflows/unit-tests.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ jobs:
3737
cache: 'pip'
3838
- name: Install linters
3939
run: |
40-
source build_tools/shared.sh
41-
# Include pytest compatibility with mypy
42-
pip install pytest $(get_dep ruff min) $(get_dep mypy min) cython-lint
40+
pip install -r build_tools/github/lint_lock.txt
4341
- name: Run linters
4442
run: ./build_tools/linting.sh
4543
- name: Run Meson OpenMP checks

.github/workflows/update-lock-files.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
additional_commit_message: "[free-threaded]"
3030
- name: array-api
3131
update_script_args: "--select-tag cuda"
32+
- name: lint
33+
update_script_args: "--select-tag lint"
3234

3335
steps:
3436
- uses: actions/checkout@v7

.pre-commit-config.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,19 @@ repos:
1515
args: ["--fix", "--output-format=full"]
1616
- id: ruff-format
1717
- repo: https://github.com/pre-commit/mirrors-mypy
18+
# NOTE if you update the mypy version here, remember to update
19+
# sklearn/_min_dependencies.py as well
1820
rev: v1.15.0
1921
hooks:
2022
- id: mypy
2123
files: sklearn/
22-
additional_dependencies: [pytest==6.2.4]
24+
# We set `pytest` to an arbitrary recent version to keep it consistent with the
25+
# linting settings in `build_tools/update_environments_and_lock_files.py`. They
26+
# should be updated from time to time in both places.
27+
additional_dependencies: [pytest==9.1.0]
2328
- repo: https://github.com/MarcoGorelli/cython-lint
29+
# NOTE if you update the cython-lint version here, remember to update
30+
# sklearn/_min_dependencies.py as well
2431
rev: v0.21.0
2532
hooks:
2633
# TODO: add the double-quote-cython-strings hook when it's usability has improved:

build_tools/github/lint_lock.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.11
3+
# by the following command:
4+
#
5+
# pip-compile --output-file=build_tools/github/lint_lock.txt build_tools/github/lint_requirements.txt
6+
#
7+
cython==3.2.5
8+
# via cython-lint
9+
cython-lint==0.20.0
10+
# via -r build_tools/github/lint_requirements.txt
11+
iniconfig==2.3.0
12+
# via pytest
13+
mypy==1.15.0
14+
# via -r build_tools/github/lint_requirements.txt
15+
mypy-extensions==1.1.0
16+
# via mypy
17+
packaging==26.2
18+
# via pytest
19+
pluggy==1.6.0
20+
# via pytest
21+
pycodestyle==2.14.0
22+
# via cython-lint
23+
pygments==2.20.0
24+
# via pytest
25+
pytest==9.1.0
26+
# via -r build_tools/github/lint_requirements.txt
27+
ruff==0.12.2
28+
# via -r build_tools/github/lint_requirements.txt
29+
tokenize-rt==6.2.0
30+
# via cython-lint
31+
typing-extensions==4.15.0
32+
# via mypy
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# DO NOT EDIT: this file is generated from the specification found in the
2+
# following script to centralize the configuration for CI builds:
3+
# build_tools/update_environments_and_lock_files.py
4+
pytest
5+
ruff==0.12.2 # min
6+
mypy==1.15 # min
7+
cython-lint==0.20 # min

build_tools/update_environments_and_lock_files.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,28 @@ def remove_from(alist, to_remove):
482482
},
483483
"python_version": "3.12.3",
484484
},
485+
{
486+
"name": "lint",
487+
"type": "pip",
488+
"tag": "lint",
489+
"folder": "build_tools/github",
490+
"pip_dependencies": ["pytest", "ruff", "mypy", "cython-lint"],
491+
"package_constraints": {
492+
# We set `pytest` to an arbitrary recent version to keep it consistent with
493+
# the settings in `.pre-commit-config.yml`. They should be updated from
494+
# time to time in both places.
495+
"pytest": "9.1.0",
496+
# We fix the version of the linters to some arbitrary version to
497+
# avoid changing linting conventions too often.
498+
# The meaning of the "min" values is set in `_min_dependencies.py`
499+
# and should be updated from time to time when we feel the need
500+
# for it.
501+
"ruff": "min",
502+
"mypy": "min",
503+
"cython-lint": "min",
504+
},
505+
"python_version": "3.11",
506+
},
485507
]
486508

487509

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ tests = [
8787
"pytest-cov>=2.9.0",
8888
"ruff>=0.12.2",
8989
"mypy>=1.15",
90+
"cython-lint>=0.21",
9091
"pyamg>=5.0.0",
9192
"polars>=0.20.30",
9293
"pyarrow>=13.0.0",

sklearn/_min_dependencies.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@
3535
"memory_profiler": ("0.57.0", "benchmark, docs"),
3636
"pytest": (PYTEST_MIN_VERSION, "tests"),
3737
"pytest-cov": ("2.9.0", "tests"),
38+
# NOTE if you update ruff, mypy or cython-lint here, remember to update
39+
# .pre-commit-config.yaml as well
3840
"ruff": ("0.12.2", "tests"),
3941
"mypy": ("1.15", "tests"),
42+
"cython-lint": ("0.21", "tests"),
4043
"pyamg": ("5.0.0", "tests"),
4144
"polars": ("0.20.30", "docs, tests"),
4245
"pyarrow": ("13.0.0", "tests"),

0 commit comments

Comments
 (0)