-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Rewrite direct URL reinstallation logic #10564
base: main
Are you sure you want to change the base?
Conversation
322c2ef
to
e098905
Compare
e098905
to
b936e8f
Compare
ad9cff7
to
59faab5
Compare
I think we should reinstall the sdist, when specified explicitly as a "local path". |
Does this include |
Both of those should have direct urls set, while the local path should not? |
Yea, as implemented, the behaviour in the case we're discussing is... suboptimal. |
Meh, I don't know. PEP 610 doesn't directly answer this question (duh!) because it only defines things in terms of PEP 440 / PEP 508. The question of "are local paths supposed to be treated the exact same as PEP 508/440 URL requirements" is... not something I'm touching at 00:30 on a Sunday. :) |
I think it's reasonable to always reinstall from You can check for that by reaching into the underlying
|
As I mentioned elsewhere before (can't find where now), it is not at all obvious to me that we should do something different based on whether the user put a I'm wondering if things are now mature enough to finish this matrix that I posted before and then make a test suite out of it. |
I think I agree with Stéphane, treating
|
5387547
to
59ff7ed
Compare
OK, so I revised the aforementioned condition. Now all three of
are automatically reinstalled. |
aaa5d94
to
85faa80
Compare
I think this is ready! |
Haven't done a proper clone-and-play-with-it routine, but this PR feels like it's missing a bunch of tests for the reinstall behaviour that this is going to provide users. |
Any thoughts on how this can be best tested? Since we’re always re-installing |
We have a You can use that, with http and https, with custom responses set up. |
@uranusjr I spent a couple of hours experimenting with your suggestion to leverage I'm also preparing a comparison of what this does vs pip 22.1 (and possibly the legacy resolver). It will take time though, so in the meantime you may want to have a look and see if it goes in the right direction for you. |
Light bump to see where peeps are at on this effort. |
Now --upgrade can trigger a non-URL requirement to upgrade an existing URL-installed distribution. Some logic is also tweaked so legacy editable installations (which lack direct_url.json) is also considered URL-specified and treated the same as non-editable direct URL and modern (PEP 660) editable installations.
Given this simple setup.py:
I'd expect a second With latest pip version (23.0) installation resulting time is over 20 seconds and more importantly, the log clearly shows:
So a full clone still occurs. With your patched version |
Are you testing it right? I just tried and a second |
@uranusjr just mentioning this is still on my radar, but I need to set aside enough contiguous hours to dive into this again. |
@uranusjr $> pip -V
pip 23.0.dev0. .... $> time pip install . --quiet 3.95s user 1.26s system 25% cpu 20.303 total
pip install . --quiet 3.95s user 1.26s system 25% cpu 20.303 total If there is anything wrong I am done, would love to help testing here. |
I don’t know, I simply don’t see what you see. Maybe it would be easier to communicate if you can provide something like a script or Dockerfile for reproduction. |
@uranusjr I finally found some time to come back to this. I created a dedicated test harness with my view of the expected re-installation behaviour. Here is the current result, comparing pip 23.0.1 with this PR: report.html.gz I see the following areas where we still need refinement and/or more discussion:
Basically, what I'm after is a mechanism to efficiently install the output of pip freeze and make sure the direct URLs in the frozen requirements are installed, and also make sure that version-specified requirements are reinstalled from index when already installed from a direct URL. I think overloading
My current thinking is that it would be reasonable not to reinstall if the version match, but also overload
Let me know your thoughts. |
How about if we also add a warning if the hashes don’t match? That would help users debug the situation.
Not re-installing immutable refs by default (but always re-install typically mutable ones) seems reasonable. And |
If this is the route chosen, would like to request an escape hatch if possible which doesn't require pinning a hash, as that doesn't work well for library dependencies. Worth noting that this eager-by-default is not the current behavior of |
I think this problem fundamentally represents how mutable dependencies are too loose by design and used in very different scenarios that require different treatments. From past reports, these are mainly used for development, where people tend to want auto upgrades. So what I would personally suggest is to not use them if you are depending on those URLs in production; either use constraints (that pin to immutable hashes), or produce versioned wheels instead. |
This isn't the case for me. I could provide some more color on my use-case, but I'm not really looking for alternatives. This is a bug in pip that was introduced with the new resolver, or a feature that was removed and no longer possible, whichever way you want to look at it. At the very least, some way to ask pip to not reach out to the internet when a package is already installed, like it does with every other dependency specification except VCS URLs, seems like something that could be supported directly with a flag if not the default behavior. This would solve my issues, but also isn't specific to my use-case. A branch is mutable in the same way that a non-pinned PyPI dependency is, but you get different feature sets with these specifications. I understand that the metadata being available via PyPI makes these dependency specifications very different in implementation, but from a user PoV, they have very similar semantics. |
Zulip uses Pip in both production and development; it has been stuck on Pip 20.3 with
This seems like a reasonable thing to expect a package manager to be able to do. |
Since |
Trying to clear out things. After the proposal is implemented, pip would:
So if you
No network requirements will be induced because the commit ID in the However, it would not work if you also supply a requirement to the same package using a mutable VCS URL, since the mutable URL would differ from the URL from |
@uranusjr curious if this has gotten more attention since the last comment. I ask because pip's VCS documentation does not mention the logic of when an installed package from a VCS will be upgraded nor is there a satisfying answer on stack overflow. With the current release, will a package installed with |
I feel the logic is done, the blocker is not me. |
I'm not blocking anything, just commenting ;) I've quickly reviewed the report I had attached to #10564 (comment). I think my main concern is about the scenarios where this PR reinstalls with For instance: The rest can be considered improvements that I'd find nice to address at the same time but could also be addressed in followups. |
Fix #5780.
The logic is almost #5780 (comment), but I dropped the last part about non-PEP-508 paths since it turns out to not be actually viable without major refactoring (pip does not currently pass the original argument format to the resolver; all requirements are URLs when they reach this part).
@pradyunsg It also turns out this has some effect on #10543; with this implementation, sdist will not be automatically reinstalled, but
--upgrade
(not--force-reinstall
as described in the deprecation message) can actually be used to override that behaviour. But since we have removed that deprecation warning, should we continue to keep the behaviour of always reinstalling sdists (this implementation currently does not), and/or show that deprecation message again?