Skip to content

MNT Fix pre-commit #31013

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 4 commits into from
Mar 22, 2025
Merged

Conversation

DimitriPapadopoulos
Copy link
Contributor

@DimitriPapadopoulos DimitriPapadopoulos commented Mar 18, 2025

Reference Issues/PRs

See also #30976.

What does this implement/fix? Explain your changes.

Fix the pre-commit configuration.

Any other comments?

It's not a good idea to run the linter and other tools from existing CI jobs and pre-commit. The main reason is that tools such as black operate on a different fileset when run on a whole directory (black .) or run by pre-commit on each individual file separately (black sklearn/externals/_arff.py). Aligning teh exclude lists of black/ruff and pre-commit is tedious and error-prone.

Instead, I would recommend running black/ruff only once in pre-commit instead of running these tools on a handful of different CI jobs (Azure, GitHub, etc.) for no reason (as far as I can see).

Copy link

github-actions bot commented Mar 18, 2025

✔️ Linting Passed

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

Generated for commit: 22eff44. Link to the linter CI: here

@DimitriPapadopoulos DimitriPapadopoulos force-pushed the pre-commit branch 2 times, most recently from e94835a to fcf111e Compare March 18, 2025 17:41
[WARNING] repo `https://github.com/pre-commit/pre-commit-hooks` uses deprecated stage names (commit, push) which will be removed in a future version.  Hint: often `pre-commit autoupdate --repo https://github.com/pre-commit/pre-commit-hooks` will fix this.  if it does not -- consider reporting an issue to that repo.
Based on the exclude lists of black and ruff.
	$ pre-commit run end-of-file-fixer -a
	fix end of files.........................................................Failed
	- hook id: end-of-file-fixer
	- exit code: 1
	- files were modified by this hook

	Fixing CODE_OF_CONDUCT.md
	Fixing examples/miscellaneous/README.txt
	Fixing doc/whats_new/upcoming_changes/sklearn.inspection/29797.enhancement.rst
	Fixing sklearn/datasets/images/README.txt
	Fixing examples/gaussian_process/README.txt
	Fixing examples/frozen/README.txt
	Fixing examples/developing_estimators/README.txt
	Fixing examples/decomposition/README.txt
	Fixing examples/manifold/README.txt
	Fixing examples/inspection/README.txt
	Fixing doc/testimonials/README.txt
	Fixing examples/cross_decomposition/README.txt
	Fixing doc/modules/biclustering.rst
	Fixing doc/whats_new/upcoming_changes/sklearn.inspection/26202.enhancement.rst
	Fixing sklearn/svm/src/liblinear/linear.h
	Fixing sklearn/utils/src/MurmurHash3.cpp

	$
	$ pre-commit run trailing-whitespace  -a
	trim trailing whitespace.................................................Failed
	- hook id: trailing-whitespace
	- exit code: 1
	- files were modified by this hook

	Fixing doc/logos/README.md
	Fixing doc/whats_new/v1.6.rst
	Fixing doc/modules/svm.rst
	Fixing doc/developers/maintainer.rst.template
	Fixing asv_benchmarks/benchmarks/config.json
	Fixing sklearn/datasets/tests/data/svmlight_classification.txt
	Fixing doc/modules/biclustering.rst
	Fixing doc/modules/feature_selection.rst
	Fixing sklearn/datasets/tests/data/svmlight_multilabel.txt

	$
@DimitriPapadopoulos DimitriPapadopoulos marked this pull request as ready for review March 18, 2025 17:41
@adrinjalali
Copy link
Member

We run linters for two reasons:

  • to make sure the rest of the CI doesn't burn CPU cycles if the linter's failing
  • to create the message posted in PRs by the linter bot

@adrinjalali adrinjalali merged commit 4cd9d78 into scikit-learn:main Mar 22, 2025
37 of 38 checks passed
@DimitriPapadopoulos DimitriPapadopoulos deleted the pre-commit branch March 22, 2025 13:54
@DimitriPapadopoulos
Copy link
Contributor Author

DimitriPapadopoulos commented Mar 22, 2025

* to make sure the rest of the CI doesn't burn CPU cycles if the linter's failing

Good point. However, that's only useful for linters (ruff check and mypy). The formatter can be run automatically, typically by pre-commit.ci. Also, pre-commit is able to apply some linter rules automatically.

I don't know if it's possible to run other pipelines (Azure, CircleCI and GitHub Actions) only if pre-commit.ci succeeds.

* to create the message posted in PRs by the linter bot

pre-commit does that.

@adrinjalali
Copy link
Member

I actually did study pre-commit.ci a while ago, and we've had discussions about pushing formatting to the PR directly from the CI, and the consensus has been that we don't want to do that. It creates conflicts when beginner contributors get conflicts between remote and local copy, and more advanced users would handle formatting on their own.

As for getting the messages themselves for the bot, I don't mind moving to pre-commit.

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