|
69 | 69 | system_which,
|
70 | 70 | )
|
71 | 71 | from pipenv.utils.toml import cleanup_toml, convert_toml_outline_tables
|
| 72 | +from pipenv.utils.virtualenv import virtualenv_scripts_dir |
72 | 73 | from pipenv.vendor import plette, tomlkit
|
73 | 74 |
|
74 | 75 | try:
|
@@ -411,11 +412,19 @@ def is_venv_in_project(self) -> bool:
|
411 | 412 | @property
|
412 | 413 | def virtualenv_exists(self) -> bool:
|
413 | 414 | venv_path = Path(self.virtualenv_location)
|
| 415 | + |
| 416 | + scripts_dir = self.virtualenv_scripts_location |
| 417 | + |
414 | 418 | if venv_path.exists():
|
415 |
| - if os.name == "nt": |
416 |
| - activate_path = venv_path / "Scripts" / "activate.bat" |
| 419 | + |
| 420 | + # existence of active.bat is dependent on the platform path prefix |
| 421 | + # scheme, not platform itself. This handles special cases such as |
| 422 | + # Cygwin/MinGW identifying as 'nt' platform, yet preferring a |
| 423 | + # 'posix' path prefix scheme. |
| 424 | + if scripts_dir.name == "Scripts": |
| 425 | + activate_path = scripts_dir / "activate.bat" |
417 | 426 | else:
|
418 |
| - activate_path = venv_path / "bin" / "activate" |
| 427 | + activate_path = scripts_dir / "activate" |
419 | 428 | return activate_path.is_file()
|
420 | 429 |
|
421 | 430 | return False
|
@@ -612,6 +621,10 @@ def virtualenv_src_location(self) -> Path:
|
612 | 621 | loc.mkdir(parents=True, exist_ok=True)
|
613 | 622 | return loc
|
614 | 623 |
|
| 624 | + @property |
| 625 | + def virtualenv_scripts_location(self) -> Path: |
| 626 | + return virtualenv_scripts_dir(self.virtualenv_location) |
| 627 | + |
615 | 628 | @property
|
616 | 629 | def download_location(self) -> Path:
|
617 | 630 | if self._download_location is None:
|
@@ -1422,10 +1435,10 @@ def proper_case_section(self, section):
|
1422 | 1435 | def finders(self):
|
1423 | 1436 | from .vendor.pythonfinder import Finder
|
1424 | 1437 |
|
1425 |
| - scripts_dirname = "Scripts" if os.name == "nt" else "bin" |
1426 |
| - scripts_dir = Path(self.virtualenv_location) / scripts_dirname |
1427 | 1438 | finders = [
|
1428 |
| - Finder(path=str(scripts_dir), global_search=gs, system=False) |
| 1439 | + Finder( |
| 1440 | + path=str(self.virtualenv_scripts_location), global_search=gs, system=False |
| 1441 | + ) |
1429 | 1442 | for gs in (False, True)
|
1430 | 1443 | ]
|
1431 | 1444 | return finders
|
@@ -1463,12 +1476,14 @@ def _which(self, command, location=None, allow_global=False):
|
1463 | 1476 | is_python = command in ("python", Path(sys.executable).name, version_str)
|
1464 | 1477 |
|
1465 | 1478 | if not allow_global:
|
| 1479 | + scripts_location = virtualenv_scripts_dir(location_path) |
| 1480 | + |
1466 | 1481 | if os.name == "nt":
|
1467 |
| - p = find_windows_executable(str(location_path / "Scripts"), command) |
| 1482 | + p = find_windows_executable(str(scripts_location), command) |
1468 | 1483 | # Convert to Path object if it's a string
|
1469 | 1484 | p = Path(p) if isinstance(p, str) else p
|
1470 | 1485 | else:
|
1471 |
| - p = location_path / "bin" / command |
| 1486 | + p = scripts_location / command |
1472 | 1487 | elif is_python:
|
1473 | 1488 | p = Path(sys.executable)
|
1474 | 1489 | else:
|
|
0 commit comments