Skip to content

Conversation

arrdem
Copy link
Collaborator

@arrdem arrdem commented Oct 14, 2025

Fixes #664

On Linux and MacOS, the current_exe() path has likely been realpath-ed by the system or the libc somewhere along the line. This means that if the user types .venv/bin/python3, the entire symlink chain that may point into will be chased and we'll get a path somewhere inside the Bazel execroot/ output tree. Critically on Linux this symlink tree goes past the .runfiles/ directory entry the user intended to create a symlink to, which prevents our interpreter shim from delegating to a .runfiles/ packaged Python like the user desired.

In order for us to resolve "just enough" symlinks to identify the .runfiles/ tree, we need to manually resolve the path of the current executable. Previously doing so would create a false positive if there was a ./python or ./python3 directory, and the interpreter shim was invoked as python3 which is ambiguous as to whether the user meant ./python3 or python3 from the $PATH.

The fix here centers on two insights:

  • The "real" interpreter can never be a directory (directly fixes the bug)
  • The "real" interpreter's absolute path must have the same absolute path as whatever current_exe() is

Changes are visible to end-users: yes

  • Searched for relevant documentation and updated as needed: yes
  • Breaking change (forces users to change their own code or config): no
  • Suggested release notes appear below: yes

Fixed a bug which would cause the interpreter shims to identify ./python3/ or ./python/ (directories) as the real path of the interpreter "python3" rather than falling back to which() behavior.

Test plan

  • Manual testing

Copy link

e2e/use_release folder: LCOV of commit 545ee19 during CI #2084

Summary coverage rate:
  lines......: 100.0% (2 of 2 lines)
  functions..: 100.0% (1 of 1 function)
  branches...: no data found

Files changed coverage rate: n/a

@arrdem arrdem requested a review from thesayyn October 14, 2025 17:03
@arrdem arrdem merged commit 3512cbe into main Oct 14, 2025
20 checks passed
@arrdem arrdem deleted the arrdem/chore-fix-664 branch October 14, 2025 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: venv python shim crashes when current directory contains file or directory named "python" or "python3"

2 participants