mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
bpo-46049: Fixes ._pth support on non-Windows (GH-30051)
This commit is contained in:
parent
971ece8e17
commit
bfc59ed0a0
4 changed files with 52 additions and 41 deletions
|
@ -407,24 +407,22 @@ pth_dir = None
|
|||
# Calling Py_SetPythonHome() or Py_SetPath() will override ._pth search,
|
||||
# but environment variables and command-line options cannot.
|
||||
if not py_setpath and not home_was_set:
|
||||
# Check adjacent to the main DLL/dylib/so
|
||||
if library:
|
||||
try:
|
||||
pth = readlines(library.rpartition('.')[0] + '._pth')
|
||||
pth_dir = dirname(library)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
# Check adjacent to the original executable, even if we
|
||||
# redirected to actually launch Python. This may allow a
|
||||
# venv to override the base_executable's ._pth file, but
|
||||
# it cannot override the library's one.
|
||||
if not pth_dir:
|
||||
try:
|
||||
pth = readlines(executable.rpartition('.')[0] + '._pth')
|
||||
pth_dir = dirname(executable)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
# 1. Check adjacent to the main DLL/dylib/so (if set)
|
||||
# 2. Check adjacent to the original executable
|
||||
# 3. Check adjacent to our actual executable
|
||||
# This may allow a venv to override the base_executable's
|
||||
# ._pth file, but it cannot override the library's one.
|
||||
for p in [library, executable, real_executable]:
|
||||
if p:
|
||||
if os_name == 'nt' and (hassuffix(p, 'exe') or hassuffix(p, 'dll')):
|
||||
p = p.rpartition('.')[0]
|
||||
p += '._pth'
|
||||
try:
|
||||
pth = readlines(p)
|
||||
pth_dir = dirname(p)
|
||||
break
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
# If we found a ._pth file, disable environment and home
|
||||
# detection now. Later, we will do the rest.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue