Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b5f56a0

Browse files
committedApr 10, 2025
refactor(project): set up dynamic scripts location lookup
Removed custom logic for determining the scripts/ location, in favor of using the virtualenv mechanism. Fixes: #5978
1 parent fab3dd7 commit b5f56a0

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed
 

‎pipenv/project.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
system_which,
7070
)
7171
from pipenv.utils.toml import cleanup_toml, convert_toml_outline_tables
72+
from pipenv.utils.virtualenv import virtualenv_scripts_dir
7273
from pipenv.vendor import plette, tomlkit
7374

7475
try:
@@ -412,10 +413,11 @@ def is_venv_in_project(self) -> bool:
412413
def virtualenv_exists(self) -> bool:
413414
venv_path = Path(self.virtualenv_location)
414415
if venv_path.exists():
416+
415417
if os.name == "nt":
416-
activate_path = venv_path / "Scripts" / "activate.bat"
418+
activate_path = self.scripts_dir / "activate.bat"
417419
else:
418-
activate_path = venv_path / "bin" / "activate"
420+
activate_path = self.scripts_dir / "activate"
419421
return activate_path.is_file()
420422

421423
return False
@@ -612,6 +614,10 @@ def virtualenv_src_location(self) -> Path:
612614
loc.mkdir(parents=True, exist_ok=True)
613615
return loc
614616

617+
@property
618+
def virtualenv_scripts_location(self) -> Path:
619+
return virtualenv_scripts_dir(self.virtualenv.location)
620+
615621
@property
616622
def download_location(self) -> Path:
617623
if self._download_location is None:
@@ -1422,10 +1428,9 @@ def proper_case_section(self, section):
14221428
def finders(self):
14231429
from .vendor.pythonfinder import Finder
14241430

1425-
scripts_dirname = "Scripts" if os.name == "nt" else "bin"
1426-
scripts_dir = Path(self.virtualenv_location) / scripts_dirname
14271431
finders = [
1428-
Finder(path=str(scripts_dir), global_search=gs, system=False)
1432+
Finder(path=str(self.virtualenv_scripts_location), global_search=gs,
1433+
system=False)
14291434
for gs in (False, True)
14301435
]
14311436
return finders
@@ -1463,12 +1468,14 @@ def _which(self, command, location=None, allow_global=False):
14631468
is_python = command in ("python", Path(sys.executable).name, version_str)
14641469

14651470
if not allow_global:
1471+
scripts_location = virtualenv_scripts_dir(location_path)
1472+
14661473
if os.name == "nt":
1467-
p = find_windows_executable(str(location_path / "Scripts"), command)
1474+
p = find_windows_executable(str(scripts_location), command)
14681475
# Convert to Path object if it's a string
14691476
p = Path(p) if isinstance(p, str) else p
14701477
else:
1471-
p = location_path / "bin" / command
1478+
p = scripts_location / command
14721479
elif is_python:
14731480
p = Path(sys.executable)
14741481
else:

0 commit comments

Comments
 (0)
Please sign in to comment.