-
Couldn't load subscription status.
- Fork 3.2k
Description
What's the problem this feature will solve?
At the moment, pip can only fully1 manage the current Python environment. This makes it hard to have environments without pip installed (for example, when preparing a zipapp, or an embedded Python installation).
Being able to specify a target "environment" (in the sense of a set of paths like sysconfig scheme) which pip can manage, would allow a single shared pip to be used for multiple Python environments.
Describe the solution you'd like
Add a global option to pip that sets the "environment" to be managed. The UI for this option is yet to be decided - in the most explicit case, values are needed for the 5 sysconfig paths that pip can install data into, but shortcuts for common cases would be important for a good user experience.
All pip commands will use the specified environment.
Alternative Solutions
- The existing
--target,--rootand--prefixoptions all attempt to handle this, but they lack support for upgrades and uninstalls, as well as not being integrated with informational commands likelist. - Running pip with the Python environment's
pythonexecutable works, but only when the target environment is a virtual environment. This does not cover cases like preparing a zipapp, or installing into the library area of an app that embeds Python. - Rather than having a UI for selecting a scheme, it would be possible to have a (simple) programmatic API to allow people to set a scheme, and then invoke pip1. But that would make "manage another environment" inaccessible from the fundamental
python -m pipcommand.
Additional context
This is closely related to #4575. A lot of the discussion on that issue covered handling environments that "shadow" each other (user shadowing system, and --use-system-site virtual environments). This issue explicitly avoids that problem, focusing on the case of a single standalone environment, with shadowing being left as an issue for how the user sets up their sys.path.
This proposal doesn't stand a chance of working with the "legacy" direct setup.py install method (for editables or normal installs), as that method delegates installation to setuptools, and it is impractical to force setuptools to conform to the scheme selected in pip1. So maybe it's time to finally pull the plug on that method? What remains to do to make that happen? At an absolute minimum, we should make the legacy install method fail if a custom scheme is set by this option.
Testing will be a possible issue. In theory, we should test as much of pip's functionality as possible with a custom scheme, as well as with the default scheme. But that will be a fairly massive increase in our already large test times2. I feel like it would be worth reorganising the test suite to have a "core functionality" section that's run on a matrix basis (normal, zipapp, custom scheme, ...) with the remaining functional tests being normal scheme only (but if we do that, are we just crossing our fingers that there's no edge cases?) I don't feel anything like confident enough in my understanding of our test suite to tackle something like this, though. For now, I'll probably just add "custom scheme" tests as I go, ignoring the test runtime issue, and leave refactoring the test suite to someone with more expertise...
Code of Conduct
- I agree to follow the PSF Code of Conduct.