Conversation
|
hey all, here's a snippet based on what we worked out yesterday, for a script to parse pyproject.toml and generate a requirements file from it after hardening the pins: from pathlib import Path
import requests
import tomllib
from packaging.requirements import Requirement
from packaging.specifiers import SpecifierSet
with open("/path/to/mne/python/pyproject.toml", "rb") as fid:
toml = tomllib.load(fid)
deps = toml["project"]["dependencies"] + toml["dependency-groups"]["test"]
reqs = [Requirement(dep) for dep in deps]
pinned_reqs = [req for req in reqs if ">" in str(req.specifier)]
unpinned_reqs = list(set(reqs) - set(pinned_reqs))
# TODO triage handling of > vs >= For now, just assert that we needn't worry
assert all([">=" in str(req) for req in pinned_reqs])
for req in pinned_reqs:
req.specifier = SpecifierSet(str(req.specifier).replace(">=", "=="))
# TODO make sure pinned version isn't yanked
# recombine pinned and not-pinned
all_reqs = sorted(pinned_reqs + unpinned_reqs, key=str)
outfile = Path("/path/to/mne/python/tools/requirements-ci-old.txt")
outfile.write_text("\n".join([str(req) for req in all_reqs]))After that we can in theory run this to get a pylock file: uv pip compile tools/requirements-ci-old.txt --output-file tools/pylock-ci-old.toml --python-version 3.10
mkdir ~/Desktop/some_temp_dir
cd ~/Desktop/some_temp_dir
uv venv --python 3.10
uv pip sync /path/to/mne/python/tools/pylock-ci-old.toml --python-version 3.10Note the TODO in the first script about pinned version being yanked; I get a warning about scipy 1.11.0 when doing the |
regarding the uv pip compile command (uv 0.8.22 (ade2bdbd2 2025-09-23) : pylock-ci-old.toml throws an error:
I renamed the file to pylock.ci-old.toml, that fixed it |
Co-authored-by: Carina Forster <carinaforster0611@gmail.com>
for more information, see https://pre-commit.ci
|
Have had a go at trying to sort this, here is what I found: Fixed outdated
|
Yes please add sensible lower pins to test deps as needed |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
|
Had to adjust some minimum versions further, but the tests are finally passing. Again, I went with what was the latest version available 2 years ago. As part of #13611, We could have a similar check to be super sure the environment matches our expectations, but it might be a bit overkill. WDYT @drammock? |
In principle yes... but that's assuming that we don't accidentally install other packages later in the pipeline somewhere that could install newer versions. So I think there's value in keeping the check in place after any installation steps complete, right before tests are run. The code is very simple and fast to execute so little cost in keeping it around |
This part I think would be overkill... just checking the important ones that we want to change + update (using |
|
@larsoner Okay, I can update the check to compare the main dependencies in the env to those listed in the lockfile. |
|
Also, I'm only just realising that the existing old env approach included
Should we create a new group that only includes |
|
Yeah I think a new group makes sense here |
for more information, see https://pre-commit.ci
| run: | | ||
| uv pip compile pyproject.toml --python "3.10" --python-platform "x86_64-unknown-linux-gnu" --group test --extra ver-auto-bumped --resolution lowest-direct --format pylock.toml --output-file tools/pylock.ci-old.toml | ||
| python tools/check_old_lockfile.py |
There was a problem hiding this comment.
Found when testing that re-compiling the lockfile with --resolution lowest-direct doesn't always lead to the pins in the lockfile being updated if the min version in pyproject.toml is lower than the min version in the lockfile.
If the min version in pyproject.toml is higher than the min version in the lockfile, the lockfile pin gets bumped as expected.
I imagine almost all scenarios would involve increases to the min version in pyproject.toml rather than decreases, but just to be sure the lockfile compiles as expected, I added a check that the versions are as expected.
|
@larsoner Adapted the check that the I added a new extras group Not sure what else is outstanding. WDYT @drammock? |
|
I should update the env check that Python is the expected version. |
@tsbinns @nordme @CarinaFo @scott-huberty
Here's the PR with placeholders. I discussed with @larsoner and he prefers that we try
uvfirst; if it doesn't work or is unweildy we can switch topixi(see item 3 below for thoughts on this). In addition to the in-line comments, here are a few notes:tools/uv-ci-old.lockor similarlinux-64systems, so when creating the lockfile we can skip adding support for other platforms.uv.lockis actually going to work; AFAICTuv lockonly works in uv's "project mode" where it writes a bunch of stuff totool.uv.*tables inpyproject.toml. Right now we don't have such tables (and I don't think we should add them in this PR), so we may need to do something a bit unorthodoxed withuv(e.g., write our pins torequirements-ci-old.txt, use uv to convert that topylock.tomlformat, and restore the environment from the pylock file). See if you can get it to work withuv, but also feel free to experiment withpixito see if the flow is simpler/more natural that way.mneinstalled (specifically, the local-to-the-CI clone ofmnethat reflects the PR being built). It may be possible to get a relative path in the lockfile, but if not, we may need omitmnein the lockfile and add/install the local-to-ci clone of MNE after the environment has been activated.