Fix handling of != intersections in requires-python#7897
Conversation
9b4b1ea to
635bd55
Compare
635bd55 to
e692f89
Compare
| lock, @r###" | ||
| version = 1 | ||
| requires-python = ">=3.11" | ||
| requires-python = ">=3.11b1" |
There was a problem hiding this comment.
We now retain this more-or-less verbatim. I think this is ok since we'll ignore these anywhere that it matters when we actually use it.
| let specifiers = range | ||
| .iter() | ||
| .flat_map(VersionSpecifier::from_release_only_bounds) | ||
| .collect(); |
There was a problem hiding this comment.
This isn't quite correct -- we can't just AND these, since a != specifier gets converted to < and > the value. So instead we retain the actual specifiers now.
e692f89 to
3ed9db4
Compare
3ed9db4 to
298da6f
Compare
| ----- stderr ----- | ||
| Using CPython 3.8.[X] interpreter at: [PYTHON-3.8] | ||
| error: The requested interpreter resolved to Python 3.8.[X], which is incompatible with the project's Python requirement: `>=3.12`. However, a workspace member (`bird-feeder`) supports Python >=3.8. To install the workspace member on its own, navigate to `packages/bird-feeder`, then run `uv venv --python 3.8.[X]` followed by `uv pip install -e .`. | ||
| error: The requested interpreter resolved to Python 3.8.[X], which is incompatible with the project's Python requirement: `>=3.8, >=3.12`. However, a workspace member (`bird-feeder`) supports Python >=3.8. To install the workspace member on its own, navigate to `packages/bird-feeder`, then run `uv venv --python 3.8.[X]` followed by `uv pip install -e .`. |
There was a problem hiding this comment.
This is a pain. Maybe we do want to apply some simplifications here...? Like ignoring redundant clauses?
There was a problem hiding this comment.
I guess we could do something like: only add the specifier if it changes the computed bounds? That could work.
There was a problem hiding this comment.
Here's a POC of using subset_of. I'm guessing this can be done in a simpler way?
There was a problem hiding this comment.
Good idea. I will do something like that to at least avoid these common cases.
There was a problem hiding this comment.
My expectation is that we should be able to represent RequiresPython as a single pubgrub range, extracting the range's lower or upper bound as needed; My quick attempt at that failed though because there seem other constraints too.
There was a problem hiding this comment.
I ended up writing a routine to convert to an "optimal" PEP 440 specifier using similar logic to the existing method, but for multiple bounds. It's kind of tedious but does work as expected.
|
@ibraheemdev -- You may be interested in this too. |
|
Can I get review on this one? |
| let specifiers = combined.into_iter().collect(); | ||
|
|
||
| Ok(Some(Self { | ||
| specifiers, |
There was a problem hiding this comment.
Does the doc comment for this function (intersection) need to be updated?
298da6f to
157367c
Compare
|
I didn't mean to merge this as-is; I thought I had pushed #8060 but apparently I'm tired. |
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [astral-sh/uv](https://github.com/astral-sh/uv) | patch | `0.4.20` -> `0.4.21` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>astral-sh/uv (astral-sh/uv)</summary> ### [`v0.4.21`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#0421) [Compare Source](astral-sh/uv@0.4.20...0.4.21) ##### Enhancements - Add support for managed installations of free-threaded Python ([#​8100](astral-sh/uv#8100)) - Add note about `uvx` to `uv tool run` short help ([#​7695](astral-sh/uv#7695)) - Enable HTTP/2 requests ([#​8049](astral-sh/uv#8049)) - Support `uv tree --no-dev` ([#​8109](astral-sh/uv#8109)) - Support PEP 723 metadata with `uv run -` ([#​8111](astral-sh/uv#8111)) - Support `pip install --exact` ([#​8044](astral-sh/uv#8044)) - Support `uv export --no-header` ([#​8096](astral-sh/uv#8096)) - ADd Python 3.13 images to Docker publish ([#​8105](astral-sh/uv#8105)) - Support remote (`https://`) scripts in `uv run` ([#​6375](astral-sh/uv#6375)) - Allow comma value-delimited arguments in `uv run --with` ([#​7909](astral-sh/uv#7909)) ##### Configuration - Support wildcards in `UV_INSECURE_HOST` ([#​8052](astral-sh/uv#8052)) ##### Performance - Use shared index when fetching metadata in lock satisfaction routine ([#​8147](astral-sh/uv#8147)) ##### Bug fixes - Add prerelease compatibility check to `uv python` CLI ([#​8020](astral-sh/uv#8020)) - Avoid deleting a project environment directory if we cannot tell if a `pyvenv.cfg` file exists ([#​8012](astral-sh/uv#8012)) - Avoid excluding valid wheels for exact `requires-python` bounds ([#​8140](astral-sh/uv#8140)) - Bump `netrc` crate to latest commit ([#​8021](astral-sh/uv#8021)) - Fix `uv python pin 3.13t` failure when parsing version for project requires check ([#​8056](astral-sh/uv#8056)) - Fix handling of != intersections in `requires-python` ([#​7897](astral-sh/uv#7897)) - Remove the newly created tool environment if sync failed ([#​8038](astral-sh/uv#8038)) - Respect dynamic extras in `uv lock` and `uv sync` ([#​8091](astral-sh/uv#8091)) - Treat resolver failures as fatal in lockfile validation ([#​8083](astral-sh/uv#8083)) - Use `git config --get` for author information for improved backwards compatibility ([#​8101](astral-sh/uv#8101)) - Use comma-separated values for `UV_FIND_LINKS` ([#​8061](astral-sh/uv#8061)) - Use shared resolver state between add and lock to avoid double Git update ([#​8146](astral-sh/uv#8146)) - Make `--relocatable` entrypoints robust to symlinking ([#​8079](astral-sh/uv#8079)) - Improve compatibility with VSCode PS1 prompt ([#​8006](astral-sh/uv#8006)) - Fix "Stream did not contain valid UTF-8" failures in Windows ([#​8120](astral-sh/uv#8120)) - Use `--with-requirements` in `uvx` error hint ([#​8112](astral-sh/uv#8112)) ##### Documentation - Include `uvx` installation in Docker examples ([#​8179](astral-sh/uv#8179)) - Make the instructions for the Windows standalone installer consistent across README and documentation ([#​8125](astral-sh/uv#8125)) - Update pip compatibility guide to note transitive URL dependency support ([#​8081](astral-sh/uv#8081)) - Document `--reinstall` with `--exclude-newer` to ensure downgrades ([#​6721](astral-sh/uv#6721)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM3LjQ0MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Summary
The issue here is that, if you user has a
requires-pythonlike>= 3.7, != 3.8.5, this gets expanded to the following bounds:[3.7, 3.8.5)(3.8.5, ...We then convert this to the specific
>= 3.7, < 3.8.5, > 3.8.5. But the commas in that expression are conjunctions... So it's impossible to satisfy? No version is both< 3.8.5and> 3.8.5.Instead, we now preserve the input
requires-pythonand just concatenate the terms, only using PubGrub to compute the bounds.Closes #7862.