Skip to content

Commit

Permalink
Switch to using lstat() instead of stat() to not match symlink targets.
Browse files Browse the repository at this point in the history
The convenience function samefile() calls stat() and samestat(), but
this leads to treating a symlink and its target as the same which is
unlikely to be intentional here as that doesn't work well with venv.
  • Loading branch information
roubert committed Jan 26, 2025
1 parent f5ff4fa commit 5e3f8ee
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/13156.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Switch to using lstat() instead of stat() to not match symlink targets.
2 changes: 1 addition & 1 deletion src/pip/_internal/utils/entrypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def get_best_invocation_for_this_python() -> str:

# Try to use the basename, if it's the first executable.
found_executable = shutil.which(exe_name)
if found_executable and os.path.samefile(found_executable, exe):
if found_executable and os.path.samestat(os.lstat(found_executable), os.lstat(exe)):
return exe_name

# Use the full executable name, because we couldn't find something simpler.
Expand Down

0 comments on commit 5e3f8ee

Please sign in to comment.