You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Reuse the pre-commit linter config in the CI runners #32500
At the moment, our CI runs linting jobs using a custom script build_tools/lintin.sh with manually pip installed dependencies in the Circle CI and Azure Pipelines CI configuration files.
Those linter tool versions are not always consistent with what we configure in .pre-commit-config.yaml and that can cause problems such as the following: #32499 (comment).
I think we should refactor our CI config to reuse the pre-commit command, for instance by running:
pre-commit run --all-files
Instead of our custom build_tools/linting.sh script. However, this might not be that easy:
there are probably linting failures to fix or config to update to ignore specific files or folders;
there might be CI integration to update, in particular the .github/workflows/bot-lint-comment.yml and the ./build_tools/get_comment.py script that generate a helpful user facing comments will need to be reworked and adapted to work with the output of the pre-commit command.
Simplest fix/work-around would be to pip install cython-lint==<manually-fixed-version> which matches the .pre-commit-config.yaml, which we are doing for ruff (and I think we did for some time with black)?
Side-comment: some time ago I looked at using a lock-file for the linters, except that pre-commit has its own opinionated way of managing the environment and I was not able to find anything. Maybe worth another look today to see if things have changed.
The fact that pre-commit has its own way of managing things and that you can't run ruff from your dev environment directly but need to go via pre-commit doesn't make me happy (mostly because I don't really know how to drive pre-commit). So I am a little "against" committing ourselves to pre-commit more.
However, I think having to keep things in sync or tracking down why you sometimes get an error and sometimes not is pretty annoying and uses up a lot of time (with little benefit to the person investing the time).
You can easily do pre-commit run --all-files or if you want to run a single hook, you can do pre-commit run <hook-id>. I don't think it's too hard to remember those 😜 but I personally just have the hooks installed and never have to run either ruff or pre-commit since it goes out of the way and simply works.
There is also the question: do we want to tell contributors through the lint bot comment
use pre-commit to fix all the linting issues or
stick with the current status quo, "let's not require contributors to install pre-commit". The main argument for the status quo is that pre-commit behaviour can be confusing when you need to commit twice
No strong opinion on this personally.
By the way pre-commit run --all-files currently fails for me. I guess because we actually never have run it fully but only on changed files through pre-commit hooks, not 100% sure. This kind of drift could well happen in the future as well?
pre-commit run --all-files was passing, not sure why it's failing now.
For me, if a contributor doesn't want to install pre-commit, I don't want to spend time telling them the alternative route. If they want the alternative, they can figure it out themselves. In practice, this has been pretty much the response on PRs. We just tell people to do pre-commit.
In practice, this has been pretty much the response on PRs. We just tell people to do pre-commit.
Indeed I misremembered and thought the bot linting comment did NOT mention pre-commit only the tool version so that people can use the correct version. Oh well, so I guess the bot linting comment has been nudging contributors towards pre-commit for some time 1.
pre-commit run --all-files was passing, not sure why it's failing now.
One of this caveats you hope this seemingly simple tools never bump into, except they somehow always do (with enough time). My best guess is that we updated the version of all the hooks but did not run the pre-commit on all files so you only then update files when you touch them through pre-commit git hooks?
Footnotes
probably one of many Adrin's cunning masterplans 😜 ↩
You can easily do pre-commit run --all-files or if you want to run a single hook, you can do pre-commit run <hook-id>. I don't think it's too hard to remember those 😜 but I personally just have the hooks installed and never have to run either ruff or pre-commit since it goes out of the way and simply works.
I know I can do it, but it isn't "easily done". I use it rarely when I want to format some stuff without committing it, so I don't remember how to do it, which means I need to find the docs first, look it up, etc. For example, what is the hook ID of the ruff step? How do I only "ruff" this one file here? - I am sure it is possible, maybe Cursor even knows, but it does add some friction. Especially because the pre-commit docs are, unsurprisingly, targeted at "apply all the checks to all the stuff being committed".
Usually finishes before any github CI even starts.
By default it can autofix PRs by pushing commits with fixable things on it, but this can be turned off in the pre-commit config and activated via the github UI by labelling the issue with the proper label: if you don't remember the pre-commit command, just add the label to the PR and pre-commit CI will format things for you
Sure. I consider pre-commit as used on the average OSS Python project quite risky security-wise, because:
It installs/updates packages automatically in a very low-visibility way without much control
Contrast that to, e.g., conda which shows you a list of packages and then allows you to say Yes; pixi/uv as the currently best tools for conda-forge and PyPI respectively are also much better.
Usually the type of things included in pre-commit, like sorting import order or single vs double quotes, are pointing at random projects from a single person that I don't know. Each such project needs inspecting (for me) and is a potential security risk. The risk/reward tradeoffs are generally very poor.
There tend to be frequent updates of the packages pulled in by pre-commit with some bot (not for scikit-learn though it looks like), magnifying the risk.
For SciPy we ended up adding a pre-commit hook but making it fully optional - that was a hard requirement I and a number of others had - so it's opt-in only. Linting is done with spin lint by default, and the pre-commit hook just calls the same script as spin lint does. There's a discussion starting around scipy/scipy#15489 (comment) that may be relevant.
To each their own, so I don't mind it's in the SciPy repo or that other projects use it, but I personally don't want to touch it. If a project uses it in their CI, when I contribute I just let it fail in CI and iterate until green.
To each their own, so I don't mind it's in the SciPy repo or that other projects use it, but I personally don't want to touch it. If a project uses it in their CI, when I contribute I just let it fail in CI and iterate until green.
so in that sense pre-commit CI would help you so that you would not have to run it locally but you could ask it to run the autofixing for you without having you to run it locally
I'm quite against using pre-commit CI. The main reason being that it is quite complicated to recover from having new commits in the remote branch and in your local branch. For example when pre-commit CI pushes a commit without the PR author noticing, and the PR author adding more changes locally. I don't enjoy resolving that state when I have to do it myself and I really don't want to have to explain via text how to do it to someone who is new to this.
In addition using pre-commit's CI ties us to yet another infrastructure provider. I've not invested the time to understand how sustainable the business model of pre-commit CI is, but I suspect like all services it will eventually start charging (which is a fine strategy) or stop existing (also understandable). The more different infrastructures you rely on, the lower the combined availability (multiplying numbers smaller than one always makes an even smaller number).
I had not considered the security aspects of the lack of transparency with pre-commit, I mostly meet it as something that makes it more tricky to replicate it to be able to run "just the formatting on just this particular file"
Regarding security aspects of pre-commit, I am like 🤷 for now. Sure the environment management is opaque and another layer of indirection which could obfuscate things and execute arbitrary code.
At the same time, when you are following the setup instructions of a new repo, it's not like you are checking the implications of running every single commands that you are told to run ... for example to install the environment to build our doc pip install <this-sphinx-plugin-that-i-have-no-idea-who-maintains-it-and-why-we-need-it-but-it-looks-like-we-do> could also run arbitrary code (not to mention the dependencies of the dependencies of the dependencies of this particular sphinx plugin) ...
Activity
ogrisel commentedon Oct 14, 2025
Before starting to work on it, I think we need to make sure that other @scikit-learn/core-devs agree that this is a worthy thing to do.
lesteve commentedon Oct 14, 2025
Simplest fix/work-around would be to
pip install cython-lint==<manually-fixed-version>which matches the.pre-commit-config.yaml, which we are doing forruff(and I think we did for some time with black)?Side-comment: some time ago I looked at using a lock-file for the linters, except that
pre-commithas its own opinionated way of managing the environment and I was not able to find anything. Maybe worth another look today to see if things have changed.betatim commentedon Oct 15, 2025
The fact that pre-commit has its own way of managing things and that you can't run
rufffrom your dev environment directly but need to go via pre-commit doesn't make me happy (mostly because I don't really know how to drive pre-commit). So I am a little "against" committing ourselves to pre-commit more.However, I think having to keep things in sync or tracking down why you sometimes get an error and sometimes not is pretty annoying and uses up a lot of time (with little benefit to the person investing the time).
Maybe Loïc's suggestion is a good compromise?
adrinjalali commentedon Oct 15, 2025
You can easily do
pre-commit run --all-filesor if you want to run a single hook, you can dopre-commit run <hook-id>. I don't think it's too hard to remember those 😜 but I personally just have the hooks installed and never have to run eitherrufforpre-commitsince it goes out of the way and simply works.I wouldn't mind us using https://github.com/pre-commit/action instead of writing our own, but my main concern would be if the bot can extract the right information as it is doing now.
lesteve commentedon Oct 15, 2025
There is also the question: do we want to tell contributors through the lint bot comment
pre-committo fix all the linting issues orNo strong opinion on this personally.
By the way
pre-commit run --all-filescurrently fails for me. I guess because we actually never have run it fully but only on changed files through pre-commit hooks, not 100% sure. This kind of drift could well happen in the future as well?adrinjalali commentedon Oct 15, 2025
pre-commit run --all-fileswas passing, not sure why it's failing now.For me, if a contributor doesn't want to install pre-commit, I don't want to spend time telling them the alternative route. If they want the alternative, they can figure it out themselves. In practice, this has been pretty much the response on PRs. We just tell people to do pre-commit.
lesteve commentedon Oct 15, 2025
Indeed I misremembered and thought the bot linting comment did NOT mention pre-commit only the tool version so that people can use the correct version. Oh well, so I guess the bot linting comment has been nudging contributors towards
pre-commitfor some time 1.One of this caveats you hope this seemingly simple tools never bump into, except they somehow always do (with enough time). My best guess is that we updated the version of all the hooks but did not run the pre-commit on all files so you only then update files when you touch them through pre-commit git hooks?
Footnotes
probably one of many Adrin's cunning masterplans 😜 ↩
betatim commentedon Oct 15, 2025
I know I can do it, but it isn't "easily done". I use it rarely when I want to format some stuff without committing it, so I don't remember how to do it, which means I need to find the docs first, look it up, etc. For example, what is the hook ID of the ruff step? How do I only "ruff" this one file here? - I am sure it is possible, maybe Cursor even knows, but it does add some friction. Especially because the pre-commit docs are, unsurprisingly, targeted at "apply all the checks to all the stuff being committed".
Remi-Gau commentedon Nov 27, 2025
I would use the pre-commit-ci in instead: https://pre-commit.ci/
Usually finishes before any github CI even starts.
By default it can autofix PRs by pushing commits with fixable things on it, but this can be turned off in the pre-commit config and activated via the github UI by labelling the issue with the proper label: if you don't remember the pre-commit command, just add the label to the PR and pre-commit CI will format things for you
GaelVaroquaux commentedon Nov 27, 2025
@rgommers had thought's about security risks with pre-commits. Ralf, do you want to express them here, so that I don't distort what you said?
rgommers commentedon Nov 29, 2025
Sure. I consider pre-commit as used on the average OSS Python project quite risky security-wise, because:
condawhich shows you a list of packages and then allows you to say Yes;pixi/uvas the currently best tools for conda-forge and PyPI respectively are also much better.For SciPy we ended up adding a pre-commit hook but making it fully optional - that was a hard requirement I and a number of others had - so it's opt-in only. Linting is done with
spin lintby default, and the pre-commit hook just calls the same script asspin lintdoes. There's a discussion starting around scipy/scipy#15489 (comment) that may be relevant.To each their own, so I don't mind it's in the SciPy repo or that other projects use it, but I personally don't want to touch it. If a project uses it in their CI, when I contribute I just let it fail in CI and iterate until green.
Remi-Gau commentedon Dec 1, 2025
so in that sense pre-commit CI would help you so that you would not have to run it locally but you could ask it to run the autofixing for you without having you to run it locally
betatim commentedon Dec 2, 2025
I'm quite against using pre-commit CI. The main reason being that it is quite complicated to recover from having new commits in the remote branch and in your local branch. For example when pre-commit CI pushes a commit without the PR author noticing, and the PR author adding more changes locally. I don't enjoy resolving that state when I have to do it myself and I really don't want to have to explain via text how to do it to someone who is new to this.
In addition using pre-commit's CI ties us to yet another infrastructure provider. I've not invested the time to understand how sustainable the business model of pre-commit CI is, but I suspect like all services it will eventually start charging (which is a fine strategy) or stop existing (also understandable). The more different infrastructures you rely on, the lower the combined availability (multiplying numbers smaller than one always makes an even smaller number).
I had not considered the security aspects of the lack of transparency with pre-commit, I mostly meet it as something that makes it more tricky to replicate it to be able to run "just the formatting on just this particular file"
lesteve commentedon Dec 2, 2025
Yeah, my reading of the scikit-learn maintainers' room is also against https://pre-commit.ci.
Regarding security aspects of pre-commit, I am like 🤷 for now. Sure the environment management is opaque and another layer of indirection which could obfuscate things and execute arbitrary code.
At the same time, when you are following the setup instructions of a new repo, it's not like you are checking the implications of running every single commands that you are told to run ... for example to install the environment to build our doc
pip install <this-sphinx-plugin-that-i-have-no-idea-who-maintains-it-and-why-we-need-it-but-it-looks-like-we-do>could also run arbitrary code (not to mention the dependencies of the dependencies of the dependencies of this particular sphinx plugin) ...MarcoGorelli commentedon Feb 28, 2026
My only real opinion here is that, if you have a
.pre-commit-config.yamlfile, thenpre-commit run --all-filesshould passElse as a contributor i just assume that I can run it when I'm done, and then find changes unrelated to my PR which don't even pass CI
So i'd suggest:
.pre-commit-config.yamland check thatpre-commit run --all-filespasses in CI.