Skip to content

CI Add lock files for linting - #34303

Merged
betatim merged 22 commits into
scikit-learn:mainfrom
AnneBeyer:fix_lock_pytest_min_version
Jun 25, 2026
Merged

betatim merged 22 commits into
scikit-learn:mainfrom
AnneBeyer:fix_lock_pytest_min_version

Conversation

@AnneBeyer

@AnneBeyer AnneBeyer commented Jun 15, 2026 •

Copy link
Copy Markdown
Member

Reference Issues/PRs

Follow-up from #34292

What does this implement/fix? Explain your changes.

Uses the min version of pytest in lint.yml as a quick fix to the current mypy failures.
This adds a pip-based lock file workflow for the linting step.

First time contributor introduction

AI usage disclosure

I used AI assistance for:

Any other comments?

@ogrisel

ogrisel commented Jun 15, 2026 •

Copy link
Copy Markdown
Member

@AnneBeyer thanks for the fix. The .github/workflows/unit-tests.yml need a similar update. I am not sure why this is duplicated.

EDIT: same for the circle CI config.

@ogrisel

ogrisel commented Jun 15, 2026

Copy link
Copy Markdown
Member

Pinning is useful (e.g. for security and CI stability) beyond the workaround for the mypy failure.

Pinning to the oldest version of pytest is a bit weird though. I would rather pin to the latest stable version of the dependencies and use the weekly lockfile refresh to also bump up those version to get CI environments that are more closely related to the average dev environments.

But unfortunately we do not have a lock file dedicated for linting environments (yet). Shall we add one in our build_tools/update_environments_and_lock_files.py script along with a dedicated CI job to refresh that lockfile on a weekly basis? There is a concurrent PR to use pixi to manage lockfiles (#34212), however I have the feeling that it cannot be merged as is.

@AnneBeyer

AnneBeyer commented Jun 15, 2026 •

Copy link
Copy Markdown
Member Author

There are actually also a few more places, see the changes here.
But I also found this:

# The second option requires pytest 9.0+ to be active.

so now I'm not sure if the decision to not pin it to the min version was actually on purpose. Should we instead pin on the version before the latest release (similar to the quickfix in #32688)?

@ogrisel

ogrisel commented Jun 15, 2026

Copy link
Copy Markdown
Member

Maybe we could add an inline comment to tell the reader to regularly bump up the pytest dependency (or configure a dedicated lockfile config and register this for automated weekly refresh as we do for other lockfiles).

@AnneBeyer

Copy link
Copy Markdown
Member Author

@ogrisel do you think we also need to update the wheel builder scripts as in the PR linked above?

@AnneBeyer AnneBeyer changed the title MNT Use pytest min version in lint.yml MNT Pin pytest to version before latest to avoid mypy errors Jun 15, 2026
@AnneBeyer AnneBeyer changed the title MNT Pin pytest to version before latest to avoid mypy errors CI Pin pytest to version before latest to avoid mypy errors Jun 15, 2026

@ogrisel ogrisel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

After syncing with main the following should work and then the PR will LGTM.

Comment thread .circleci/config.yml Resolved
Comment thread .github/workflows/lint.yml Resolved
Comment thread .github/workflows/unit-tests.yml Resolved
@ogrisel

ogrisel commented Jun 16, 2026

Copy link
Copy Markdown
Member

@ogrisel do you think we also need to update the wheel builder scripts as in the PR linked above?

Let's stick with a simple manual pin as a first step. It would be great to set the linter version config in pyproject.toml and then update contributor instructions and CI configs to use a shared consistent way to setup their envs using pixi or similar but I think this is a wider ranging change.

@betatim betatim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for working on this fix!

I think this is a good idea and we should merge it once Olivier's suggestions are applied.

I think maybe we once discussed dev environments and decided that having "variety" in what people use was a feature. So maybe that inspired using the oldest version? Either way, I think using a "reasonably new" version of pytest is a good thing.

In https://scikit-learn.org/dev/developers/development_setup.html#set-up-a-dedicated-environment-and-install-dependencies we mention a particular version of ruff in the command to setup a new dev environment. It would be nice if that remained the only case. But that requires that most of the time you can use "what ever the latest version is" of the dev tools. Basically, if on 95% of days running that command leads to a working env, I'd keep the command as is. Otherwise we need to add explicit versions there or consider something like pixi

@AnneBeyer

Copy link
Copy Markdown
Member Author

I'm not sure that I see the usefulness of pinning if it requires a manual update at an undefined point in time. From what I learned from @lesteve, we want to avoid these kinds of pins as much as possible, no?
With the min version pins, the update will be triggered automatically, but as @ogrisel mentioned, setting this up to run automatically for a "reasonably new" linter config

is a wider ranging change.

I might still be missing things here, and I'm happy to make the changes if you still think it's useful.

@betatim

betatim commented Jun 16, 2026

Copy link
Copy Markdown
Member

With the min version pins, the update will be triggered automatically, but as @ogrisel mentioned, setting this up to run automatically for a "reasonably new" linter config

I'm not sure I understand all of this :-/ from what you said and looking at the diff again I now think you are saying we should use $(get_dep pytest min) like we do for ruff?

And after seeing #34300 I am even more puzzled. Doesn't that PR fix what ever was broken with using mypy and the latest pytest? In which case why do we even need this PR anymore?

@AnneBeyer

Copy link
Copy Markdown
Member Author

you are saying we should use $(get_dep pytest min)

That was my intention for a quick fix before we merged #34300. But then the discussion moved towards pinning to a more recent version and setting up a more elaborate linting environment (and lockfile) instead, which would take me some more time to understand and set up. (Plus there are the pixi experiments, which might chnage a lot more of the CI set-up, if I understand correctly.)

In which case why do we even need this PR anymore?

Exactly, I'm not sure we do.

@ogrisel

ogrisel commented Jun 16, 2026 •

Copy link
Copy Markdown
Member

In which case why do we even need this PR anymore?

Pinning is useful (e.g. for security and CI stability to avoid future disruptions on all PRs in a next pytest/mypy update) beyond the need for a workaround for the recent mypy/pytest failure.

@ogrisel ogrisel changed the title CI Pin pytest to version before latest to avoid mypy errors CI pin the pytest version used by linters Jun 16, 2026
@betatim

betatim commented Jun 16, 2026

Copy link
Copy Markdown
Member

Ok, pinning for security and stability makes sense. In that case I think we should use a lockfile like we do for other CI environments. I'm not sure if we should wait for the decision on using pixi or not.

@AnneBeyer
AnneBeyer marked this pull request as draft June 16, 2026 14:08
@AnneBeyer

Copy link
Copy Markdown
Member Author

Ok, I think I understand some parts of the CI better now (with a little help from Claude). I will update the PR towards using a lockfile for the linting steps.

@github-actions github-actions Bot added the CI:Linter failure The linter CI is failing on this PR label Jun 16, 2026
@AnneBeyer AnneBeyer changed the title CI pin the pytest version used by linters CI Add lock files for linting Jun 16, 2026
"type": "pip",
"tag": "lint",
"folder": "build_tools/github",
"pip_dependencies": ["pytest", "ruff", "mypy", "cython-lint"],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We need to keep on using the "min" supported version of ruff, mypy and cython-lint because linters might change their rules and we want to avoid weekly linter-rule-change-induced code churn.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

already changed ;)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh, hang on, for cython-lint this was not done previously, should I add it as well?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should for the sake of consistency.

@ogrisel

ogrisel commented Jun 18, 2026

Copy link
Copy Markdown
Member

FYI, I just merged #34331. We should pin cython-lint and other linters to version that is consistent with what is configured in our .pre-commit-config.yaml file.

@AnneBeyer

AnneBeyer commented Jun 18, 2026 •

Copy link
Copy Markdown
Member Author

We should pin cython-lint and other linters to version that is consistent with what is configured in our .pre-commit-config.yaml file.

That makes sense. I'm still trying to understand how everything fits together. Here is what I have so far (please correct me if I got something wrong):

The version pin for mypy and ruff is set to "min" in the lint entry in update_environments_and_lock_files.py, which is resolved to the version defined in _min_dependencies.py (even though for these two it is not actually read as a "min" dependency but an exact pin). This is the same as it was done before the changes proposed here and is also consistent with pre-commit. Adding cython-lint with the latest version (which should now be 0.20 to be consistent with pre-commit) there is straight forward. [EDIT: Done in the latest commit.]

What I'm not sure about is if and how to pin pytest. The latest release is 9.1.0.

  • In _min_dependencies.py it is set to 7.1.2, but we said that we might want to use a newer version for linting. As far as I can tell, this one is actually only used as a check in conftest.py and raises an ImportError if a lower version is installed. (I have yet to check where conftest.py is used.)
  • In the conda *environment.yaml files, pytest is not pinned and is currently 9.1.0 in the corresponding lock files.
  • In .pre-commit-config.yaml, the mypy entry actually hard codes additional_dependencies: [pytest==6.2.4].

I'm not sure what the best approach is here.
I could

  1. hard code it to 9.1.0 in .pre-commit-config.yaml and update_environments_and_lock_files.py with a note referencing each other and to update it from time to time,
  2. update it to 9.1.0 in .pre-commit-config.yaml and _min_dependencies.py and reference it in the same way as the other packages to at least avoid one additional hard coded reference (though I have to figure out where conftest.py is used before that),
  3. not pin it, but this means that it will either be inconsistent with pre-commit, or, if we remove the pin there, we risk pre-commit being broken by updates before we notice, so this does not seem to be a valid option.

WDYT?

@github-actions github-actions Bot added the CI:Linter failure The linter CI is failing on this PR label Jun 18, 2026
@github-actions github-actions Bot removed the CI:Linter failure The linter CI is failing on this PR label Jun 18, 2026
@ogrisel

ogrisel commented Jun 22, 2026 •

Copy link
Copy Markdown
Member

I would go with option 1. for now. I think we want linters to work on recent enough versions of the dependencies ("min" dependencies are not really intended for that) but the usual weekly update schedule of the "latest" dependencies lock files might introduce too much formatting related code churn.

EDIT: maybe I am overly worried and the "latest" policy of our lock files (with weekly updates) is not that bad for linters. However, the pre-commit config cannot reuse our custom lock files setup I believe and maintaining them in sync would be tedious.

If we ever find a way for pre-commit to leverage some commonly shared lock files (managed by uv or pixi) we can later reexplore this decision.

@ogrisel

ogrisel commented Jun 22, 2026

Copy link
Copy Markdown
Member

Thanks this branch LGTM. @betatim are you still green with the latest changes?

@AnneBeyer AnneBeyer added this to Labs Jun 22, 2026
@github-project-automation github-project-automation Bot moved this to Todo in Labs Jun 22, 2026
@AnneBeyer AnneBeyer moved this from Todo to In progress in Labs Jun 22, 2026
Comment on lines +492 to +495
# We set `pytest` to an arbitrary recent version to keep it consistent with
# the settings in `.pre-commit-config.yml`. They should be updated from
# time to time in both places.
"pytest": "9.1.0",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am puzzled by this, why does pre-commit use pytest? To add to my confusion, when I looked in .pre-commit-config.yml to figure out what is what the only reference I found was as part of mypy, but we require pytest==6.2.4 there. Maybe we can expand the comment here to help future me/readers to understand?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ok, I should have read the full diff first. We set the pytest version that mypy uses in .pre-commit-config.yml to match the one here. So I think the answer is: mypy needs pytest, which is why we mention pre-commit and pytest in the same sentence

@betatim betatim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@betatim
betatim merged commit fa7edde into scikit-learn:main Jun 25, 2026
33 checks passed
@github-project-automation github-project-automation Bot moved this from In progress to Done in Labs Jun 25, 2026
prady0t pushed a commit to prady0t/scikit-learn that referenced this pull request Sep 2, 2026
@AnneBeyer
AnneBeyer deleted the fix_lock_pytest_min_version branch September 2, 2026 11:59
@jeremiedbb jeremiedbb mentioned this pull request Sep 8, 2026
14 tasks done
jeremiedbb pushed a commit to jeremiedbb/scikit-learn that referenced this pull request Sep 9, 2026
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.

3 participants