-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Add a --python option #11320
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
Merged
Merged
Add a --python option #11320
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
79cd599
Add a --python option
pfmoore 95cf55b
Add a news file
pfmoore 42eae50
More flexible handling of the --python argument
pfmoore 78e7ea8
Make get_runnable_pip public
pfmoore 24c22a3
Check the argument to --python is executable
pfmoore 01e122e
Add tests
pfmoore b1eb912
Added documentation
pfmoore f86a140
Move docs to a topic
pfmoore b5afdd6
Fix test to cater for packages leaked into venv
pfmoore 61249ed
Update docs/html/topics/python-option.md
pfmoore d0b5a8f
Update docs/html/topics/python-option.md
pfmoore b6be01a
Catch errors from running the subprocess
pfmoore ddfa05c
Merge branch 'python_option' of https://github.com/pfmoore/pip into p…
pfmoore 3333891
Check python version in __pip-runner__.py
pfmoore 4dc35b7
Skip the executable check, as subprocess.run will catch this
pfmoore 0d6fada
Merge branch 'main' into python_option
pfmoore ebe491a
Get rid of the --python python/py shortcuts
pfmoore b8aa21b
Revert __pip-runner__.py changes
pfmoore 9b638ec
Update docs to match behaviour
pfmoore File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -18,4 +18,5 @@ local-project-installs | |
repeatable-installs | ||
secure-installs | ||
vcs-support | ||
python-option | ||
``` |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.