-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11320 from pfmoore/python_option
Add a --python option
- Loading branch information
Showing
8 changed files
with
152 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,5 @@ local-project-installs | |
repeatable-installs | ||
secure-installs | ||
vcs-support | ||
python-option | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Managing a different Python interpreter | ||
|
||
```{versionadded} 22.3 | ||
``` | ||
|
||
Occasionally, you may want to use pip to manage a Python installation other than | ||
the one pip is installed into. In this case, you can use the `--python` option | ||
to specify the interpreter you want to manage. This option can take one of two | ||
values: | ||
|
||
1. The path to a Python executable. | ||
2. The path to a virtual environment. | ||
|
||
In both cases, pip will run exactly as if it had been invoked from that Python | ||
environment. | ||
|
||
One example of where this might be useful is to manage a virtual environment | ||
that does not have pip installed. | ||
|
||
```{pip-cli} | ||
$ python -m venv .venv --without-pip | ||
$ pip --python .venv install SomePackage | ||
[...] | ||
Successfully installed SomePackage | ||
``` | ||
|
||
You could also use `--python .venv/bin/python` (or on Windows, | ||
`--python .venv\Scripts\python.exe`) if you wanted to be explicit, but the | ||
virtual environment name is shorter and works exactly the same. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Add a ``--python`` option to allow pip to manage Python environments other | ||
than the one pip is installed in. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import json | ||
import os | ||
from pathlib import Path | ||
from venv import EnvBuilder | ||
|
||
from tests.lib import PipTestEnvironment, TestData | ||
|
||
|
||
def test_python_interpreter( | ||
script: PipTestEnvironment, | ||
tmpdir: Path, | ||
shared_data: TestData, | ||
) -> None: | ||
env_path = os.fspath(tmpdir / "venv") | ||
env = EnvBuilder(with_pip=False) | ||
env.create(env_path) | ||
|
||
result = script.pip("--python", env_path, "list", "--format=json") | ||
before = json.loads(result.stdout) | ||
|
||
# Ideally we would assert that before==[], but there's a problem in CI | ||
# that means this isn't true. See https://github.com/pypa/pip/pull/11326 | ||
# for details. | ||
|
||
script.pip( | ||
"--python", | ||
env_path, | ||
"install", | ||
"-f", | ||
shared_data.find_links, | ||
"--no-index", | ||
"simplewheel==1.0", | ||
) | ||
|
||
result = script.pip("--python", env_path, "list", "--format=json") | ||
installed = json.loads(result.stdout) | ||
assert {"name": "simplewheel", "version": "1.0"} in installed | ||
|
||
script.pip("--python", env_path, "uninstall", "simplewheel", "--yes") | ||
result = script.pip("--python", env_path, "list", "--format=json") | ||
assert json.loads(result.stdout) == before |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters