Skip to content

Commit

Permalink
Norm path before compare (#11719)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorddavidiii authored Mar 27, 2023
1 parent 78ab4cf commit d894759
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions news/11719.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Normalize paths before checking if installed scripts are on PATH.
8 changes: 5 additions & 3 deletions src/pip/_internal/operations/install/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,18 @@ def message_about_scripts_not_on_PATH(scripts: Sequence[str]) -> Optional[str]:

# We don't want to warn for directories that are on PATH.
not_warn_dirs = [
os.path.normcase(i).rstrip(os.sep)
os.path.normcase(os.path.normpath(i)).rstrip(os.sep)
for i in os.environ.get("PATH", "").split(os.pathsep)
]
# If an executable sits with sys.executable, we don't warn for it.
# This covers the case of venv invocations without activating the venv.
not_warn_dirs.append(os.path.normcase(os.path.dirname(sys.executable)))
not_warn_dirs.append(
os.path.normcase(os.path.normpath(os.path.dirname(sys.executable)))
)
warn_for: Dict[str, Set[str]] = {
parent_dir: scripts
for parent_dir, scripts in grouped_by_dir.items()
if os.path.normcase(parent_dir) not in not_warn_dirs
if os.path.normcase(os.path.normpath(parent_dir)) not in not_warn_dirs
}
if not warn_for:
return None
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,12 @@ def test_multi_script__single_dir_on_PATH(self) -> None:
)
assert retval is None

def test_PATH_check_path_normalization(self) -> None:
retval = self._template(
paths=["/a/./b/../b//c/", "/d/e/bin"], scripts=["/a/b/c/foo"]
)
assert retval is None

def test_single_script__single_dir_on_PATH(self) -> None:
retval = self._template(paths=["/a/b", "/c/d/bin"], scripts=["/a/b/foo"])
assert retval is None
Expand Down

0 comments on commit d894759

Please sign in to comment.