Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-91985: Fix sys.path calculation with PYTHONHOME on Windows #92288

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
11 changes: 11 additions & 0 deletions Lib/test/test_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,17 @@ def test_init_setpythonhome(self):
# Because we are specifying 'home', module search paths
# are fairly static
expected_paths = [paths[0], stdlib, os.path.join(home, 'DLLs')]
# gh-91985 insert a dll build path
p = os.path.dirname(self.test_exe)
try:
with open(os.path.join(p, 'pybuilddir.txt'), encoding="utf8") as f:
p = os.path.normpath(
os.path.join(p, f'{f.read()}\n$'.splitlines()[0])
)
if p != expected_paths[-1]:
expected_paths.insert(-1, p)
except FileNotFoundError:
pass
else:
version = f'{sys.version_info.major}.{sys.version_info.minor}'
stdlib = os.path.join(home, sys.platlibdir, f'python{version}')
Expand Down
12 changes: 12 additions & 0 deletions Modules/getpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,18 @@ def search_up(prefix, *landmarks, test=isfile):
if stdlib_dir:
pythonpath.append(stdlib_dir)
if platstdlib_dir:
if os_name == 'nt' and real_executable_dir and \
isfile(joinpath(real_executable_dir, BUILDDIR_TXT)):
p = platstdlib_dir
neonene marked this conversation as resolved.
Show resolved Hide resolved
try:
p = joinpath(
real_executable_dir,
readlines(joinpath(real_executable_dir, BUILDDIR_TXT))[0],
)
except IndexError:
p = real_executable_dir
if p != platstdlib_dir:
pythonpath.append(p) # prior to platstdlib_dir
pythonpath.append(platstdlib_dir)

config['module_search_paths'] = pythonpath
Expand Down