-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize upgrade of already-satisfied pinned requirement #7132
Conversation
25a003f
to
685012a
Compare
685012a
to
d4191c3
Compare
Updated as requested. |
d4191c3
to
ae76388
Compare
We'd want to add tests for this -- I'm thinking a bit about how that'd work. We'll want to start having unit tests for the resolver, and this functionality might just be the best reason to justify adding it. |
Example: after installing six 1.12.0, `pip install -Uv six==1.12.0` now returns immediately, instead of going to the index to check for a version that can’t possibly be considered better. This optimization is most significant when upgrading via a requirements file with many pinned versions and some non-pinned versions. Signed-off-by: Anders Kaseorg <[email protected]>
ae76388
to
0492e80
Compare
@andersk Would you be OK if I pick this PR up from here? I'll have to figure out how we'd want to unit-test the resolver, in a situation where we're planning to replace it in the future. |
Go for it, thanks! |
Thank you for the contribution! It's much appreciated! I'd thought about doing this a while back, but had dropped the ball on this because... "life happened". I doubt I'd have remembered that this can be done unless you'd filed this PR! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll merge this in as-is since to the best of my judgement, this works exactly how we want it to. :)
Unfortunately PEP 440 does not allow such optimization. |
I'll revert this, to have a broader discussion about this change then. :) |
Reverted in #7158. >>> from packaging.version import parse
>>> v1 = parse("1.12.0")
>>> v2 = parse("1.12.0+foobar")
>>> v2 == v1
False
>>> v2 > v1
True
>>> from packaging.specifiers import SpecifierSet
>>> spec1 = SpecifierSet("== 1.12.0")
>>> v1 in spec1
True
>>> v2 in spec1
True |
Amazing. I'm not the first one to make this mistake then. :P |
Yea, we could. I'm thinking that we may want some way to "ignore local versions from <this source>" and just have |
lol this is the sort of example that makes me think that no matter how simple something in packaging looks, there will always be a complication someone didn't think if :-(
Maybe, but I'm wary of adding yet more choices to the UI and making the user decide. I think we should try to aim for deciding what the right behaviour should be (not that it's easy to do that!), and then implementing that and not making the user choose - this does mean we need to be prepared to defend our choice, of course. I quite like @pradyunsg's idea that "is allowed to host local versions" should be a property of the package source. (Isn't there an issue somewhere that talks about creating a "repository" abstraction which pulls together stuff that's linked to the index like this?) |
I am looking for this, I swear I remember us having this discussion. |
FWIW, we have a |
Okay, my GitHub-foo isn't strong enough right now, to find our past discussion on that. If someone could file a new issue for discussion of this stuff, that'd be great! |
I'll hunt for it later (maybe tomorrow, I'm busy this evening). I think the key term was "repo", FWIW. |
If you're thinking about #4263, that's a good one. It could clean things up quite a bit. |
Yep, that was the one, thanks @chrahunt |
Hmm. This optimization should still be allowed in the case where the requirement is |
Or if a hash is specified, since a different local version can’t match the same hash? |
All I'd say is that having found the problem with the original version of this PR (and seeing how many people had made the same mistake previously!) I'd be nervous about making any assumptions here :-) |
Well I’d counter that, seeing how many people had made the same mistake previously, there’s clearly some demand for this optimization, so maybe it’s worth putting a bit more careful thought into what we can improve without sacrificing correctness? |
It definitely is. |
Example: after installing six 1.12.0,
pip install -Uv six==1.12.0
now returns immediately, instead of going to the index to check for a version that can’t possibly be considered better.This optimization is most significant when upgrading via a requirements file with many pinned versions and some non-pinned versions.