-
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
Fix for #770: pip install -U shouldn't look at pypi if not needed #2493
Conversation
Please add label: |
req_to_install.satisfied_by = None | ||
# don't install if this exact requirement is already | ||
# installed | ||
if not (self.satisfied_by.version == |
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.
self.satisfied_by
does not seem to be defined, I guess this should be req_to_install.satisfied_by.version
and yes, this needs tests ;)
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.
the not (a == b)
could be replaced by a != b
A unit test could mock |
# an exact version match | ||
if self.upgrade and not ( | ||
req_to_install.satisfied_by.as_requirement() == | ||
req_to_install.req): |
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.
same here for the not (a == b)
vs a != b
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.
Hmmm, I agree that it seems like that would be better, but when I tried it, it seems to break:
As-is:
$ pip install -U wheel==0.24.0
Requirement already satisfied (use --upgrade to upgrade): wheel==0.24.0 in /Users/marca/python/virtualenvs/pip/lib/python2.7/site-packages
but if I do this:
--- a/pip/req/req_set.py
+++ b/pip/req/req_set.py
@@ -230,8 +230,8 @@ class RequirementSet(object):
if req_to_install.satisfied_by:
# check if we are upgrading and that we don't already have
# an exact version match
- if self.upgrade and not (
- req_to_install.satisfied_by.as_requirement() ==
+ if self.upgrade and (
+ req_to_install.satisfied_by.as_requirement() !=
req_to_install.req):
if not self.force_reinstall and not req_to_install.url:
try:
then I get a different and incorrect behavior:
$ pip install -U wheel==0.24.0
processing ~/.pdbrc.py
[5] > /Users/marca/dev/git-repos/pip/pip/index.py(284)find_requirement()
-> def mkurl_pypi_url(url):
Note that now it's calling PackageFinder.find_requirement
, whereas before it wasn't.
I admit to being mystified by this. Any ideas why this is happening?
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 broke logic. Now I have no faith in anything.
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.
what is your version of setuptools ?
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.
Hmmm, pip._vendor.pkg_resources.Requirement
overrides __eq__
and does not override __ne__
... Suspicious....
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.
(Pdb) req_to_install.satisfied_by.as_requirement() == req_to_install.req
True
(Pdb) req_to_install.satisfied_by.as_requirement() != req_to_install.req
True
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.
Adding the following fixes the problem:
def __ne__(self, other):
return not self == other
which of course if this is a legitimate bug, should be fixed in setuptools proper and not in the vendored copy of it.
But is this a bug or was there some intentional reason for omitting __ne__
? @jaraco: Maybe you could shed some light? Let me know if you want me to send a PR to setuptools...
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.
In order to make the code nicer and to workaround what I think is a setuptools problem, I changed it to this:
--- a/pip/req/req_set.py
+++ b/pip/req/req_set.py
@@ -228,7 +228,12 @@ class RequirementSet(object):
if not self.ignore_installed and not req_to_install.editable:
req_to_install.check_if_exists()
if req_to_install.satisfied_by:
- if self.upgrade:
+ # check if we are upgrading and that we don't already have
+ # an exact version match
+ satisfied = (
+ req_to_install.satisfied_by.as_requirement() ==
+ req_to_install.req)
+ if self.upgrade and not satisfied:
if not self.force_reinstall and not req_to_install.url:
try:
url = finder.find_requirement(
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 decided to send a PR to setuptools since it seems likely that it's a bug and I don't want it to get lost in the shuffle:
https://bitbucket.org/pypa/setuptools/pull-request/125/add-__ne__-method-to-requirement-class/diff
ed1cbba
to
c2d5f61
Compare
Please restart Travis CI for just py33, as it failed with an error trying to hit launchpad (ugh):
|
Please add label: |
c2d5f61
to
1da69c8
Compare
OK, I just added a test called |
The Travis CI build passed. Ready for review... |
Contains merge conflicts now. I'll take a look... |
1da69c8
to
d641ee1
Compare
Fixed merge conflicts with d641ee1 |
The Travis CI build passed. Ready for review... |
How does it look now, @xavfernandez? |
I must say I'm not comfortable with the The fact that:
does not help. |
@xavfernandez: What would you change it to? |
Good question :)
|
d641ee1
to
3a2134a
Compare
Updated. Thanks! |
Hmmm, tests are failing with that. I guess the meaning is different than what we had before? |
Maybe once we figure out what the right logic is, we should make it a |
3a2134a
to
c185502
Compare
My bad, Checking if the current specifier is satisfied by the current version is useless, the
|
c185502
to
e3aa6f2
Compare
@xavfernandez: Thanks for the new idea. Just updated it. Crossing fingers... |
I did test my patch ;) |
and Travis CI passed so looking good... |
This breaks |
If an exact version is specified for install, and that version is already installed, then there is no point going to pypi as no install is needed. Adds a test called `test_upgrade_no_look_at_pypi_if_exact_version_installed`. This is a rework of PR pypa#771, because that PR is old and has merge conflicts that were easier to fix by applying the changes manually.
e3aa6f2
to
94fcd18
Compare
Fixed |
Fix for #770: pip install -U shouldn't look at pypi if not needed
Couldn't this work also for |
I was wondering if it was a good idea with the With a |
Hey @pypa/pip-developers (@ncoghlan probably has an opinion too) I merged this 16 days ago, but there's an open question about it.. Right now it assumes that if you do I also notice this has a problem where it won't do the right thing for |
I would think that if all of the versions are 1.0 then they are the exact same bits. Obviously, someone can violate this, but that seems to be very against the concept of semantic versioning and such. I'd hate to penalize the more common case where people play by the rules because of an unusual case. But I'll change this is folks think it is necessary. |
@msabramo The issue here is that all of It's an unusual situation - and I don't have any personal need for it - but if you have a local variant (available via The complaint in the original issue #770 was that if you ran I'm inclined to say that this PR was over-enthusiastic, and should be modified to "not check PyPI" rather than not do any searches at all. Obviously that's a lot harder, though, and may even be sufficiently hard to mean that the change is no longer justifiable. But again, this is only a theoretical concern for me. In practice, the issue doesn't affect me either way. (Actually, the original issue quoted "1000x" slower, under pip 1.2.1. It's quite possible that the caching in recent pip versions will have improved that significantly, maybe even to the extent that this change is no longer needed...) |
I'm considering if we should just revert it all together. Short circuiting the index check for A few things have changed since that original ticket to increase the speed of checking for an update:
In that time period a few things have changed in the meaning of
I do feel like "don't check PyPI" is a bad way of implementing this, either it should not check at all or it should do the normal checks. I'm leaning heavily towards reverting this and just saying that |
Yeah, the fact that it's intended to be an optimisation but changes behaviour seems wrong to me. I'd support reverting. |
Yeah, reverting seems reasonable to me. |
Reverts #2493 - Upgrades will again contact the index
If an exact version is specified for install, and that version is
already installed, then there is no point going to pypi as no install
is needed.
This is a rework of PR #771, because that PR is old and has merge
conflicts that were easier to fix by applying the changes manually.
I would recommend closing #771.