Skip to content

Commit 9d52048

Browse files
committed
fix detection of python and pip executables on Windows
1 parent 90a222d commit 9d52048

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

src/poetry/utils/env/generic_env.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import TYPE_CHECKING
99
from typing import Any
1010

11+
from poetry.utils._compat import WINDOWS
1112
from poetry.utils.env.script_strings import GET_PATHS
1213
from poetry.utils.env.virtual_env import VirtualEnv
1314

@@ -39,6 +40,9 @@ def find_executables(self) -> None:
3940
(f"python{major_version}", f"pip{major_version}"),
4041
]
4142

43+
if WINDOWS:
44+
patterns = [(f"{p[0]}.exe", f"{p[1]}.exe") for p in patterns]
45+
4246
python_executable = None
4347
pip_executable = None
4448

tests/utils/env/test_env.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -423,16 +423,14 @@ def test_env_finds_the_correct_executables_for_generic_env(
423423
venv = GenericEnv(parent_venv.path, child_env=VirtualEnv(child_venv_path))
424424

425425
expected_executable = (
426-
f"python{sys.version_info[0]}.{sys.version_info[1]}{'.exe' if WINDOWS else ''}"
426+
"python.exe"
427+
if WINDOWS
428+
else f"python{sys.version_info[0]}.{sys.version_info[1]}"
427429
)
428430
expected_pip_executable = (
429431
f"pip{sys.version_info[0]}.{sys.version_info[1]}{'.exe' if WINDOWS else ''}"
430432
)
431433

432-
if WINDOWS:
433-
expected_executable = "python.exe"
434-
expected_pip_executable = "pip.exe"
435-
436434
assert Path(venv.python).name == expected_executable
437435
assert Path(venv.pip).name == expected_pip_executable
438436

@@ -458,14 +456,14 @@ def test_env_finds_fallback_executables_for_generic_env(
458456
and venv._bin_dir.joinpath(major_executable).exists()
459457
):
460458
venv._bin_dir.joinpath(expected_executable).unlink()
461-
expected_executable = major_executable
459+
expected_executable = major_executable
462460

463461
if (
464462
venv._bin_dir.joinpath(expected_executable).exists()
465463
and venv._bin_dir.joinpath(default_executable).exists()
466464
):
467465
venv._bin_dir.joinpath(expected_executable).unlink()
468-
expected_executable = default_executable
466+
expected_executable = default_executable
469467

470468
default_pip_executable = f"pip{'.exe' if WINDOWS else ''}"
471469
major_pip_executable = f"pip{sys.version_info[0]}{'.exe' if WINDOWS else ''}"
@@ -478,20 +476,14 @@ def test_env_finds_fallback_executables_for_generic_env(
478476
and venv._bin_dir.joinpath(major_pip_executable).exists()
479477
):
480478
venv._bin_dir.joinpath(expected_pip_executable).unlink()
481-
expected_pip_executable = major_pip_executable
479+
expected_pip_executable = major_pip_executable
482480

483481
if (
484482
venv._bin_dir.joinpath(expected_pip_executable).exists()
485483
and venv._bin_dir.joinpath(default_pip_executable).exists()
486484
):
487485
venv._bin_dir.joinpath(expected_pip_executable).unlink()
488-
expected_pip_executable = default_pip_executable
489-
490-
if not venv._bin_dir.joinpath(expected_executable).exists():
491-
expected_executable = default_executable
492-
493-
if not venv._bin_dir.joinpath(expected_pip_executable).exists():
494-
expected_pip_executable = default_pip_executable
486+
expected_pip_executable = default_pip_executable
495487

496488
venv = GenericEnv(parent_venv.path, child_env=VirtualEnv(child_venv_path))
497489

0 commit comments

Comments
 (0)