Skip to content
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

Merged
merged 1 commit into from
Oct 7, 2019

Conversation

andersk
Copy link
Contributor

@andersk andersk commented Oct 3, 2019

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.

@andersk andersk force-pushed the optimize-pinned-upgrade.git branch from 25a003f to 685012a Compare October 3, 2019 03:48
news/7132.feature Outdated Show resolved Hide resolved
src/pip/_internal/index.py Outdated Show resolved Hide resolved
@andersk andersk force-pushed the optimize-pinned-upgrade.git branch from 685012a to d4191c3 Compare October 5, 2019 00:46
@andersk
Copy link
Contributor Author

andersk commented Oct 5, 2019

Updated as requested.

@andersk andersk force-pushed the optimize-pinned-upgrade.git branch from d4191c3 to ae76388 Compare October 5, 2019 00:51
@pradyunsg
Copy link
Member

pradyunsg commented Oct 5, 2019

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.

@pradyunsg pradyunsg added C: dependency resolution About choosing which dependencies to install type: enhancement Improvements to functionality labels Oct 5, 2019
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]>
@andersk andersk force-pushed the optimize-pinned-upgrade.git branch from ae76388 to 0492e80 Compare October 5, 2019 03:15
@pradyunsg
Copy link
Member

pradyunsg commented Oct 6, 2019

@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.

@andersk
Copy link
Contributor Author

andersk commented Oct 6, 2019

Go for it, thanks!

@pradyunsg
Copy link
Member

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!

Copy link
Member

@pradyunsg pradyunsg left a 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. :)

@pradyunsg pradyunsg merged commit f718a8f into pypa:master Oct 7, 2019
@andersk andersk deleted the optimize-pinned-upgrade.git branch October 7, 2019 07:47
@xavfernandez
Copy link
Member

xavfernandez commented Oct 7, 2019

Unfortunately PEP 440 does not allow such optimization.
pip install -U six==1.12.0 should check its indexes and find links location for a possible 1.12.0+foobar version that should be preferred to the currently 1.12.0 installed one.

@pradyunsg
Copy link
Member

I'll revert this, to have a broader discussion about this change then. :)

@xavfernandez
Copy link
Member

xavfernandez commented Oct 7, 2019

Cf #770, #771, #2114, #2493, #2631 and maybe others ;)

Maybe a new value in --upgrade-strategy could now allow us to trigger this new behavior ?

@pradyunsg
Copy link
Member

pradyunsg commented Oct 7, 2019

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

@pradyunsg
Copy link
Member

and maybe others ;)

Amazing. I'm not the first one to make this mistake then. :P

@pradyunsg
Copy link
Member

pradyunsg commented Oct 7, 2019

Maybe a new value in --upgrade-strategy could now allow us to trigger this new behavior ?

Yea, we could. I'm thinking that we may want some way to "ignore local versions from <this source>" and just have pypi.org on that list by default.

@pfmoore
Copy link
Member

pfmoore commented Oct 7, 2019

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 a new value in --upgrade-strategy

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?)

@pradyunsg
Copy link
Member

(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.

@pradyunsg
Copy link
Member

pradyunsg commented Oct 7, 2019

FWIW, we have a PackageIndex model -- https://github.com/pypa/pip/blob/master/src/pip/_internal/models/index.py

@pradyunsg
Copy link
Member

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!

@pfmoore
Copy link
Member

pfmoore commented Oct 7, 2019

I'll hunt for it later (maybe tomorrow, I'm busy this evening). I think the key term was "repo", FWIW.

@chrahunt
Copy link
Member

chrahunt commented Oct 7, 2019

If you're thinking about #4263, that's a good one. It could clean things up quite a bit.

@pfmoore
Copy link
Member

pfmoore commented Oct 7, 2019

Yep, that was the one, thanks @chrahunt

@andersk
Copy link
Contributor Author

andersk commented Oct 7, 2019

Hmm. This optimization should still be allowed in the case where the requirement is === (arbitrary equality), which has no special treatment of local versions, right?

@andersk
Copy link
Contributor Author

andersk commented Oct 7, 2019

Or if a hash is specified, since a different local version can’t match the same hash?

@pfmoore
Copy link
Member

pfmoore commented Oct 7, 2019

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 :-)

@andersk
Copy link
Contributor Author

andersk commented Oct 7, 2019

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?

@pradyunsg
Copy link
Member

maybe it’s worth putting a bit more careful thought into what we can improve without sacrificing correctness?

It definitely is.

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Nov 18, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Nov 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation C: dependency resolution About choosing which dependencies to install type: enhancement Improvements to functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants