pep508: add requires-python simplification/complexification to MarkerTree
#7134
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In #6268, we refactored how we handled
requires-python
. Beforethat PR, we simplified markers inside resolution in lock-step with
requires-python version narrowing. But this turns out to be quite hard
to do correctly. After that PR, we now generally only simplify markers
when we write the lock file.
So for example, if a package has this marker:
And we have
requires-python = ">=3.8"
, then its simplified form is this:The problem is that if we use the simplified form in a place where we
shouldn't, perhaps in a place where we don't handle the context of
requires-python
correctly or if it changes, then the marker can leadto incorrect results.
So #6268 fixed this, but there was a hiccup: previously, in order to
actually do the simplification, we did this:
MarkerTree
to "restrict" any Python version expressionssuch that they were limited to the intersection of what was in the
marker and whas was provided by
requires-python
. 2. When printinga
MarkerTree
, we specifically set the lower and upper bounds tonegative and positive infinity, respectively.
The end result is that we had a simplified marker, but it relied on a
subtle trick during printing to work. This made it difficult to reason
about markers since they might internally have finite lower/upper
bounds, but when printed, they had non-finite lower/upper bounds.
In order to access the simplified marker, #6268 would run the
"restrict" operation, print the marker as a string and then parse it.
This removed any "hidden" state and made the internal representation of
the marker match its printed form.
But this is bad juju to do, and having the hidden state when we don't
need it any more makes things very difficult to reason about. So in
this PR, we essentially port the old restrict+print approach to one
routine, and then also add a dedicated routine to do the reverse
operation as well (instead of relying on marker conjunction, as we did
before).