Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to using lstat() instead of stat() to not match symlink targets #13161

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

roubert
Copy link

@roubert roubert commented Jan 12, 2025

Closes #13156.

@pfmoore
Copy link
Member

pfmoore commented Jan 12, 2025

See #13156 (comment) - I think the existing code should work without this change, and we need to understand why it doesn't before trying to "fix" the issue.

@roubert roubert force-pushed the running_under_virtualenv branch from ed0b04b to f6e5730 Compare January 13, 2025 18:49
@pfmoore
Copy link
Member

pfmoore commented Jan 13, 2025

I'll leave this for someone familiar with Unix to comment on whether it's a good fix. It seems reasonable to me.

@roubert roubert changed the title Always use the full executable name when running under virtualenv Switch to using lstat() instead of stat() to not match symlink targets Jan 13, 2025
@roubert roubert force-pushed the running_under_virtualenv branch from f6e5730 to 211596f Compare January 26, 2025 22:28
@roubert roubert force-pushed the running_under_virtualenv branch 2 times, most recently from 5e3f8ee to d989254 Compare January 26, 2025 23:20
@roubert roubert marked this pull request as ready for review January 26, 2025 23:37
Copy link
Member

@ichard26 ichard26 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable and does the right thing locally. My best guess is that this worked in some limited situations because the virtual environment was created using copies instead of symlinks. This seems rare in practice as both venv and virtualenv have defaulted to using symlinks on Linux/macOS for ages, but I dunno what else could make this work.

The get_best_invocation_for_this_pip() logic has the same flaw, although I doubt anyone uses symlinks for the pip binaries in practice (at least on Unix, the scripts' shebang includes a reference to the virtual environment's Python, so they can't be symlinks. Not sure how Windows works...).

news/13156.bugfix.rst Outdated Show resolved Hide resolved
src/pip/_internal/utils/entrypoints.py Show resolved Hide resolved
@roubert roubert force-pushed the running_under_virtualenv branch 4 times, most recently from 625403a to 0e47a0f Compare January 30, 2025 17:26
Copy link
Member

@ichard26 ichard26 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you very much!

I do want someone else to chime in before this lands though. While I've been using Linux daily for a few years ago, I still have my blindspots. I feel like I might've missed something here.

news/13156.bugfix.rst Outdated Show resolved Hide resolved
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.
@roubert roubert force-pushed the running_under_virtualenv branch from 9348ec9 to 127134a Compare January 30, 2025 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Command line for notice update not copy-pasteable for venv
3 participants