Skip to content

Commit

Permalink
Get rid of the --python python/py shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
pfmoore committed Aug 1, 2022
1 parent 0d6fada commit ebe491a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 34 deletions.
23 changes: 0 additions & 23 deletions src/pip/_internal/cli/main_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"""

import os
import shutil
import subprocess
import sys
from typing import List, Optional, Tuple
Expand All @@ -12,7 +11,6 @@
from pip._internal.cli.parser import ConfigOptionParser, UpdatingDefaultsHelpFormatter
from pip._internal.commands import commands_dict, get_similar_commands
from pip._internal.exceptions import CommandError
from pip._internal.utils.compat import WINDOWS
from pip._internal.utils.misc import get_pip_version, get_prog

__all__ = ["create_main_parser", "parse_command"]
Expand Down Expand Up @@ -50,27 +48,6 @@ def create_main_parser() -> ConfigOptionParser:


def identify_python_interpreter(python: str) -> Optional[str]:
if python == "python" or python == "py":
# Run the active Python.
# We have to be very careful here, because:
#
# 1. On Unix, "python" is probably correct but there is a "py" launcher.
# 2. On Windows, "py" is the best option if it's present.
# 3. On Windows without "py", "python" might work, but it might also
# be the shim that launches the Windows store to allow you to install
# Python.
#
# We go with getting py on Windows, and if it's not present or we're
# on Unix, get python. We don't worry about the launcher on Unix or
# the installer stub on Windows.
py = None
if WINDOWS:
py = shutil.which("py")
if py is None:
py = shutil.which("python")
if py:
return py

# If the named file exists, use it.
# If it's a directory, assume it's a virtual environment and
# look for the environment's Python executable.
Expand Down
12 changes: 1 addition & 11 deletions tests/unit/test_cmdoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,13 @@ def test_convert_python_version(
assert actual == expected, f"actual: {actual!r}"


def test_identify_python_interpreter_py(monkeypatch: pytest.MonkeyPatch) -> None:
def which(cmd: str) -> str:
assert cmd == "py" or cmd == "python"
return "dummy_value"

monkeypatch.setattr("shutil.which", which)
assert identify_python_interpreter("py") == "dummy_value"
assert identify_python_interpreter("python") == "dummy_value"


def test_identify_python_interpreter_venv(tmpdir: Path) -> None:
env_path = tmpdir / "venv"
env = EnvBuilder(with_pip=False)
env.create(env_path)

# Passing a virtual environment returns the Python executable
interp = identify_python_interpreter(os.fsdecode(env_path))
interp = identify_python_interpreter(os.fspath(env_path))
assert interp is not None
assert Path(interp).exists()

Expand Down

0 comments on commit ebe491a

Please sign in to comment.