Avoid network/index related imports for pip uninstall & list (unless necessary)#12637
Conversation
584fc59 to
ca34f36
Compare
|
Hey @pradyunsg, I would like to add this PR in addition to #12646 to the 24.1 milestone. Together with #12566 (and the pyparsing removal scheduled via the packaging bump), it would be a solid responsiveness improvement overall. Feel free to reject this request if you would prefer to preserve the churn budget (or your time 🙂) for something else this release cycle. |
|
@ichard26 This has an outstanding merge conflict, presumably since we've actually had a bunch of activity and merges in the last few days. |
While it's reasonable to put this function in req_install.py, putting it there unfortunately means importing a bunch of heavy network/index code as well which isn't acceptable.
By moving SessionCommandMixin and IndexGroupCommand into their own module, lazy imports can be easily used.
89e707e to
4a68e4b
Compare
|
Conflicts are fixed @pradyunsg 👍 |
|
Thanks for the quick updates! |
|
I came around today to merge this but it looks this is failing CI now. |
pip uninstall and list currently depend on req_install.py which always imports the expensive network and index machinery. However, it's only in rare situations that these commands actually hit the network: - `pip list --outdated` - `pip list --uptodate` - `pip uninstall --requirement <url>` This commit builds on the previous two refactoring commits and modifies these commands to avoid the expensive imports unless truly necessary.
|
Sorry about that, must've been a botched rebase. It's all green now @pradyunsg. |
|
Thanks for the review @pradyunsg. I realize that I may have been overextending my privilege to add items to milestones this release, let me know if I'm crossing any lines. |
|
Nah, you're fine. I would've said more if there was more that needed to be said. :) |
This reverts commit 71a08a7, reversing changes made to 22142d6. This patch made the pip self-version check import `pip._internal.self_outdated_check` on demand. This blows up when downgrading (and possibly upgrading) pip as it imports the module _after_ the downgrade, which is problematic as the older self-check logic is incompatible with the rest of the pip already loaded into memory.
This PR builds upon the work started in #12566, speeding up
pip listandpip uninstall. Towards #4768.pip uninstall and list currently depend on
req_install.pywhich always imports the expensive network and index machinery. However, it's only in rare situations that these commands actually hit the network:pip list --outdatedpip list --uptodatepip uninstall --requirement <url>This PR refactors
req_install.pyso these commands can avoid the expensive imports unless truly necessary.The news entry is trivial as the one already added in #12566 is sufficient.