Skip to content

Commit 44c40cd

Browse files
authored
Fix ' old ' CI lockfile validation for SPEC0 workflow (#14021)
1 parent 6a44cdd commit 44c40cd

3 files changed

Lines changed: 34 additions & 6 deletions

File tree

tools/dev/spec_zero_update_versions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def update_specifiers(dependencies, releases, changed=None, label=None):
113113
[
114114
f"{label} dependency ``{new}``"
115115
for new, old in zip(dependencies, old_deps)
116-
if new != old
116+
if new.replace(" ", "") != old.replace(" ", "")
117117
]
118118
)
119119
return changed

tools/github_actions_check_old_env.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,21 @@
3232
mod_name, pyproject_ver = get_min_pinned_ver(dep)
3333
mod_import_name = mod_name_mapping.get(mod_name, mod_name)
3434

35-
# Need to handle logic for checking Python version vs. module versions differently.
35+
# Be wary of uv treating lowest Python vs. module versions differently.
3636
# For Python, the latest micro version for the major.minor release specified will be
3737
# used. E.g., if we ask for 3.10 when creating the old env, we will get 3.10.19.
3838
# However, for modules, uv's `lowest-direct` option will resolve to the lowest
3939
# major.minor.micro version, even if a micro version isn't specified. E.g., if
4040
# `pyproject.toml` asks for numpy >= 1.26, the lockfile will have 1.26.0.
41+
# However, the non-lowest micro version of a module may be selected for
42+
# compatibility reasons. E.g., if `pyproject.toml` asks for pandas >= 2.2 and numpy
43+
# >= 2.0, pandas 2.2.2 will be placed in the lockfile, as that was the first version
44+
# to support numpy 2.0. Non-lowest micro versions of modules may also not be used if
45+
# they were yanked.
46+
# Therefore, if the micro version of a module isn't specified in `pyproject.toml`,
47+
# we don't check the micro version of the module in the environment.
4148
if mod_name == "python":
4249
env_ver = sys.version_info[:3] # take major, minor, and micro info
43-
if len(Version(pyproject_ver).release) == 2: # only major and minor specified
44-
env_ver = env_ver[:2] # only compare major and minor info
4550
env_ver = ".".join(str(x) for x in env_ver)
4651
else:
4752
try:
@@ -55,7 +60,14 @@
5560

5661
if pyproject_ver is None:
5762
continue # no min version specified, so no check needed
58-
if Version(env_ver) != Version(pyproject_ver):
63+
pyproject_ver = Version(pyproject_ver)
64+
env_ver = Version(env_ver)
65+
66+
# Discard micro info from env version if it's not specified in pyproject.toml
67+
if len(pyproject_ver.release) == 2:
68+
env_ver = Version(f"{env_ver.major}.{env_ver.minor}")
69+
70+
if env_ver != pyproject_ver:
5971
bad_version.append(
6072
f"{mod_name}: is {env_ver}; {pyproject_ver} expected from `pyproject.toml`"
6173
)

tools/github_actions_check_old_lockfile.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,37 @@
3838
)
3939

4040
# Check that the versions in the lockfile match the minimum versions in pyproject.toml
41+
# For modules, uv's `lowest-direct` option will resolve to the lowest
42+
# major.minor.micro version, even if a micro version isn't specified. E.g., if
43+
# `pyproject.toml` asks for numpy >= 1.26, the lockfile will have 1.26.0.
44+
# However, the non-lowest micro version of a module may be selected for
45+
# compatibility reasons. E.g., if `pyproject.toml` asks for pandas >= 2.2 and numpy
46+
# >= 2.0, pandas 2.2.2 will be placed in the lockfile, as that was the first version
47+
# to support numpy 2.0. Non-lowest micro versions of modules may also not be used if
48+
# they were yanked.
49+
# Therefore, if the micro version of a module isn't specified in `pyproject.toml`,
50+
# we don't check the micro version of the module in the environment.
4151
mod_name_mapping = {"lazy_loader": "lazy-loader"}
4252
bad_missing = []
4353
bad_version = []
4454
for dep in check_deps:
4555
mod_name, pyproject_ver = get_min_pinned_ver(dep)
4656
if pyproject_ver is None:
4757
continue # no min version specified, so no check needed
58+
pyproject_ver = Version(pyproject_ver)
4859
name = mod_name_mapping.get(mod_name, mod_name)
4960

5061
if name not in lockfile_modules.keys():
5162
bad_missing.append(name)
5263
continue
5364
lockfile_ver = lockfile_modules[name]
65+
lockfile_ver = Version(lockfile_ver)
5466

55-
if Version(lockfile_ver) != Version(pyproject_ver):
67+
# Discard micro info from lockfile version if it's not specified in pyproject.toml
68+
if len(pyproject_ver.release) == 2:
69+
lockfile_ver = Version(f"{lockfile_ver.major}.{lockfile_ver.minor}")
70+
71+
if lockfile_ver != pyproject_ver:
5672
bad_version.append(
5773
f"lower pin on {name} in `pyproject.toml` is {pyproject_ver}, "
5874
f"but `pylock.ci-old.toml` has {lockfile_ver}"

0 commit comments

Comments
 (0)