Skip to content

Commit 8dca58a

Browse files
committed
Include a news fragment and use the default executable name to determine if it is a good idea to use the home value for base_executable determination
1 parent 5541061 commit 8dca58a

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

Lib/test/test_getpath.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -870,40 +870,39 @@ def test_venv_w_symlinked_base_executable(self):
870870
we should have it as sys.executable (and sys.prefix should be the resolved location)
871871
"""
872872
ns = MockPosixNamespace(
873-
argv0="/venv/bin/python3",
873+
argv0="/venv/bin/python9",
874874
PREFIX="/some/_internal/prefix",
875-
base_exec_prefix="/foo/bar"
876875
)
877876
# Setup venv
878-
ns.add_known_xfile("/venv/bin/python3")
879-
ns.add_known_xfile("/usr/local/bin/python3")
880-
ns.add_known_xfile("/some/_internal/prefix/bin/python3")
877+
ns.add_known_xfile("/venv/bin/python9")
878+
ns.add_known_xfile("/usr/local/bin/python9")
879+
ns.add_known_xfile("/some/_internal/prefix/bin/python9")
881880

882881
ns.add_known_file("/venv/pyvenv.cfg", [
883882
# The published based executable location is /usr/local/bin - we don't want to
884-
# expose /some/internal/directory (this location can change under our feet)
883+
# expose /some/_internal/prefix (this location can change under our feet)
885884
r"home = /usr/local/bin"
886885
])
887-
ns.add_known_link("/venv/bin/python3", "/usr/local/bin/python3")
888-
ns.add_known_link("/usr/local/bin/python3", "/some/_internal/prefix/bin/python3")
886+
ns.add_known_link("/venv/bin/python9", "/usr/local/bin/python9")
887+
ns.add_known_link("/usr/local/bin/python9", "/some/_internal/prefix/bin/python9")
889888

890889
ns.add_known_file("/some/_internal/prefix/lib/python9.8/os.py")
891890
ns.add_known_dir("/some/_internal/prefix/lib/python9.8/lib-dynload")
892891

893-
# Put a file completely outside of /usr/local to validate that the issue
894-
# in https://github.com/python/cpython/issues/106045 is resolved.
892+
# Put a file completely outside /usr/local to validate that the issue
893+
# in gh-106045 is resolved.
895894
ns.add_known_dir("/usr/lib/python9.8/lib-dynload")
896895

897896
expected = dict(
898-
executable="/venv/bin/python3",
897+
executable="/venv/bin/python9",
899898
prefix="/venv",
900899
exec_prefix="/venv",
901900
base_prefix="/some/_internal/prefix",
902901
base_exec_prefix="/some/_internal/prefix",
903902
# It is important to maintain the link to the original executable, as this
904903
# is used when creating a new virtual environment (which should also have home
905904
# set to /usr/local/bin to avoid bleeding the internal path to the venv)
906-
base_executable="/usr/local/bin/python3",
905+
base_executable="/usr/local/bin/python9",
907906
module_search_paths_set=1,
908907
module_search_paths=[
909908
"/some/_internal/prefix/lib/python98.zip",
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sys._base_executable is no longer always a fully resolved symlink when
2+
running from a venv. The home value in pyvenv.cfg is used to determine the base executable when its realpath is the same as the running executable's realpath. A venv created from another will no longer expose the realpath of the executable in this scenario.

Modules/getpath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def search_up(prefix, *landmarks, test=isfile):
382382
# the base installation — isn't set (eg. when embedded), try to find
383383
# it in 'home'.
384384
if not base_executable:
385-
_home_executable = joinpath(executable_dir, basename(executable))
385+
_home_executable = joinpath(executable_dir, DEFAULT_PROGRAM_NAME)
386386
_realpath_executable = None
387387
try:
388388
_realpath_executable = realpath(executable)

0 commit comments

Comments
 (0)