|
32 | 32 | mod_name, pyproject_ver = get_min_pinned_ver(dep) |
33 | 33 | mod_import_name = mod_name_mapping.get(mod_name, mod_name) |
34 | 34 |
|
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. |
36 | 36 | # For Python, the latest micro version for the major.minor release specified will be |
37 | 37 | # used. E.g., if we ask for 3.10 when creating the old env, we will get 3.10.19. |
38 | 38 | # However, for modules, uv's `lowest-direct` option will resolve to the lowest |
39 | 39 | # major.minor.micro version, even if a micro version isn't specified. E.g., if |
40 | 40 | # `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. |
41 | 48 | if mod_name == "python": |
42 | 49 | 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 |
45 | 50 | env_ver = ".".join(str(x) for x in env_ver) |
46 | 51 | else: |
47 | 52 | try: |
|
55 | 60 |
|
56 | 61 | if pyproject_ver is None: |
57 | 62 | 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: |
59 | 71 | bad_version.append( |
60 | 72 | f"{mod_name}: is {env_ver}; {pyproject_ver} expected from `pyproject.toml`" |
61 | 73 | ) |
|
0 commit comments