Skip to content

MNT Update ruff #30976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 24, 2025
Merged

MNT Update ruff #30976

merged 7 commits into from
Mar 24, 2025

Conversation

DimitriPapadopoulos
Copy link
Contributor

@DimitriPapadopoulos DimitriPapadopoulos commented Mar 11, 2025

What does this implement/fix? Explain your changes.

  • Bump ruff from 0.5.1 to 0.9.10 0.11.0
  • Update comments and URL associated to ruff

Any other comments?

Copy link

github-actions bot commented Mar 11, 2025

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: dea5100. Link to the linter CI: here

@DimitriPapadopoulos DimitriPapadopoulos changed the title MNT Updates around ruff MNT Update ruff Mar 12, 2025
@adrinjalali
Copy link
Member

Could you please also check that pre-commit run --all-files actually passes on all tests?

@DimitriPapadopoulos
Copy link
Contributor Author

Sure, I'll update to ruff 0.11.0 too while I'm at it.

@DimitriPapadopoulos
Copy link
Contributor Author

DimitriPapadopoulos commented Mar 18, 2025

I applied pre-commit to the whole code base, but fixes are actually unrelated to the initial PR.

$ pre-commit run -a
check yaml...............................................................Passed
fix end of files.........................................................Passed
trim trailing whitespace.................................................Passed
ruff.....................................................................Passed
black....................................................................Passed
mypy.....................................................................Passed
cython-lint..............................................................Passed
prettier.................................................................Passed
$ 

@DimitriPapadopoulos
Copy link
Contributor Author

By the way, why not run pre-commit during CI?

@adrinjalali
Copy link
Member

By the way, why not run pre-commit during CI?

I've been thinking the same. I wouldn't be opposed to that actually.

@@ -112,7 +112,7 @@ def test_make_classification_informative_features():
(2, [1 / 2] * 2, 2),
(2, [3 / 4, 1 / 4], 2),
(10, [1 / 3] * 3, 10),
(int(64), [1], 1),
((64), [1], 1),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
((64), [1], 1),
(64, [1], 1),

?

Copy link
Contributor Author

@DimitriPapadopoulos DimitriPapadopoulos Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, but these are automatic fixes and neither ruff nor black seem to be catching this one. But then see my comment #30976 (comment). I suggest deferring pre-commit fixes to a different PR anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should exclude everything in externals from linters.

Copy link
Contributor Author

@DimitriPapadopoulos DimitriPapadopoulos Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore lists are inconsistent between tools such as black and ruff and pre-commit:

scikit-learn/pyproject.toml

Lines 112 to 125 in d2dbcff

exclude = '''
/(
\.eggs # exclude a few common directories in the
| \.git # root of the project
| \.mypy_cache
| \.vscode
| build
| dist
| doc/_build
| doc/auto_examples
| sklearn/externals
| asv_benchmarks/env
)/
'''

- repo: https://github.com/psf/black
rev: 24.3.0
hooks:
- id: black

The problem is that pre-commit will explicitly run black, ruff and other tools on each individual file, without taking into account the filters in pryproject.toml. What happens then depends on whether tools such as black or ruff skip an explicit file argument if the file is part of its ignore list. Clearly black does not (psf/black#438?):

$ black sklearn/externals/_arff.py
reformatted sklearn/externals/_arff.py

All done! ✨ 🍰 ✨
1 file reformatted.
$ 

I suggest deferring pre-commit fixes to a different PR: pre-commit is currently broken and fixing it is unrelated to the initial intent of this PR.

@DimitriPapadopoulos
Copy link
Contributor Author

DimitriPapadopoulos commented Mar 18, 2025

By the way, why not run pre-commit during CI?

I've been thinking the same. I wouldn't be opposed to that actually.

A maintainer should authorize pre-commit.ci as an app in the settings of this repository:
https://pre-commit.ci/

@DimitriPapadopoulos
Copy link
Contributor Author

Also, ruff and black are already run by Azure pipelines. It wouldn't make sense to run these tools both in pre-commit.ci and Azure pipelines.

@DimitriPapadopoulos
Copy link
Contributor Author

I have reverted the pre-commit fixes. Please follow-up in #31013.

RUF007 Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs
RUF040 Non-string literal used as assert message
RUF046 Value being cast to `int` is already an integer
It will infer the Python version from pyproject.toml itself:
	requires-python = ">=3.10"
@adrinjalali adrinjalali merged commit 87d1e19 into scikit-learn:main Mar 24, 2025
36 of 37 checks passed
@adrinjalali
Copy link
Member

A maintainer should authorize pre-commit.ci as an app in the settings of this repository:
https://pre-commit.ci/

I meant running pre-commit as a command in the CI, not the action. That action is a massive one, and rather not depend on it, and we also won't be using its capability of fixing issues in the PRs anyway.

lucyleeow pushed a commit to lucyleeow/scikit-learn that referenced this pull request Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants