Skip to content

Commit 39e955f

Browse files
committed
fixup sys._base_executable
1 parent e5d21e0 commit 39e955f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

python/private/site_init_template.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,23 @@ def _maybe_add_path(path):
199199

200200
return coverage_setup
201201

202+
# The pyvenv.cfg created for py_binary leaves the `home` key unset. A
203+
# side-effect of this is `sys._base_executable` points to the venv executable,
204+
# not the actual executable. This mostly doesn't matter, but does affect
205+
# using the venv module to create venvs (they point to the venv executable, not
206+
# the actual executable).
207+
def _fixup_sys_base_executable():
208+
# Must have been set correctly?
209+
if sys.executable != sys._base_executable:
210+
return
211+
# Not in a venv, so don't touch anything.
212+
if sys.prefix == sys.base_prefix:
213+
return
214+
exe = os.path.realpath(sys.executable)
215+
_print_verbose("setting sys._base_executable:", exe)
216+
sys._base_executable = exe
217+
218+
_fixup_sys_base_executable()
202219

203220
COVERAGE_SETUP = _setup_sys_path()
204221
_print_verbose("DONE")

0 commit comments

Comments
 (0)