Skip to content

Commit 3e4d886

Browse files
jjhelmusgeofft
authored andcommitted
patch to allow venv creation from symlinks
Patch CPython to allow venvs to be created from symlinks. When inside a venv and base_executable is passed available. Use the resolved path as the executable_dir rather than the one specified by home in pyvenv.cfg
1 parent 10e1330 commit 3e4d886

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

cpython-unix/build-cpython.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,12 @@ if [[ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_14}" ]]; then
636636
patch -p1 -i "${ROOT}/patch-python-getpath-3.14.patch"
637637
fi
638638

639+
# Another, similar change to getpath: When reading inside a venv use the base_executable path to
640+
# determine executable_dir when valid. This allows venv to be created from symlinks and covers some
641+
# cases the above patch doesn't. See:
642+
# https://github.com/python/cpython/issues/106045#issuecomment-2594628161
643+
patch -p1 -i "${ROOT}/patch-getpath-use-base_executable-for-executable_dir.patch"
644+
639645
# We patched configure.ac above. Reflect those changes.
640646
autoconf
641647

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
diff --git a/Modules/getpath.py b/Modules/getpath.py
2+
index ceb605a75c8..164d708ffca 100644
3+
--- a/Modules/getpath.py
4+
+++ b/Modules/getpath.py
5+
@@ -411,6 +411,9 @@ def search_up(prefix, *landmarks, test=isfile):
6+
if isfile(candidate):
7+
base_executable = candidate
8+
break
9+
+ if base_executable and isfile(base_executable):
10+
+ # Update the executable directory to be based on the resolved base executable
11+
+ executable_dir = real_executable_dir = dirname(base_executable)
12+
# home key found; stop iterating over lines
13+
break
14+

0 commit comments

Comments
 (0)