diff --git a/src/pip/_internal/cli/main_parser.py b/src/pip/_internal/cli/main_parser.py index 548174d8dfe..15f3151de60 100644 --- a/src/pip/_internal/cli/main_parser.py +++ b/src/pip/_internal/cli/main_parser.py @@ -50,27 +50,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. diff --git a/tests/unit/test_cmdoptions.py b/tests/unit/test_cmdoptions.py index d5b4813822f..8c33ca8c18d 100644 --- a/tests/unit/test_cmdoptions.py +++ b/tests/unit/test_cmdoptions.py @@ -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()