Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Lib/test/test_getpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,32 @@ def test_normal_posix(self):
actual = getpath(ns, expected)
self.assertEqual(expected, actual)

def test_relative_path_env_posix(self):
"Resolving the executable from a relative PATH entry yields an absolute path (gh-154160)"
ns = MockPosixNamespace(
PREFIX="/usr",
argv0="python",
ENV_PATH="usr/bin",
)
ns.add_known_xfile("usr/bin/python")
ns.add_known_xfile("/Absolute/usr/bin/python")
ns.add_known_file("/usr/lib/python9.8/os.py")
ns.add_known_dir("/usr/lib/python9.8/lib-dynload")
expected = dict(
executable="/Absolute/usr/bin/python",
base_executable="/Absolute/usr/bin/python",
prefix="/usr",
exec_prefix="/usr",
module_search_paths_set=1,
module_search_paths=[
"/usr/lib/python98.zip",
"/usr/lib/python9.8",
"/usr/lib/python9.8/lib-dynload",
],
)
actual = getpath(ns, expected)
self.assertEqual(expected, actual)

def test_buildpath_posix(self):
"""Test an in-build-tree layout on POSIX.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixed :data:`sys.executable` being a relative path when the interpreter was
found through a relative entry in :envvar:`PATH`. It is now made absolute, as
documented.
4 changes: 3 additions & 1 deletion Modules/getpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ def search_up(prefix, *landmarks, test=isfile):
for p in ENV_PATH.split(DELIM):
p = joinpath(p, program_name)
if isxfile(p):
executable = p
# A relative PATH entry would otherwise leave executable
# relative, contrary to the documented behaviour (gh-154160).
executable = abspath(p)
break

if not executable:
Expand Down
Loading