mirror of
https://github.com/python/cpython.git
synced 2025-10-09 08:31:26 +00:00
bpo-37369: Fix initialization of sys members when launched via an app container (GH-14428)
sys._base_executable is now always defined on all platforms, and can be overridden through configuration. Also adds test.support.PythonSymlink to encapsulate platform-specific logic for symlinking sys.executable
This commit is contained in:
parent
80097e089b
commit
9048c49322
17 changed files with 410 additions and 277 deletions
|
@ -20,37 +20,9 @@ class PlatformTest(unittest.TestCase):
|
|||
|
||||
@support.skip_unless_symlink
|
||||
def test_architecture_via_symlink(self): # issue3762
|
||||
# On Windows, the EXE needs to know where pythonXY.dll and *.pyd is at
|
||||
# so we add the directory to the path, PYTHONHOME and PYTHONPATH.
|
||||
env = None
|
||||
if sys.platform == "win32":
|
||||
env = {k.upper(): os.environ[k] for k in os.environ}
|
||||
env["PATH"] = "{};{}".format(
|
||||
os.path.dirname(sys.executable), env.get("PATH", ""))
|
||||
env["PYTHONHOME"] = os.path.dirname(sys.executable)
|
||||
if sysconfig.is_python_build(True):
|
||||
env["PYTHONPATH"] = os.path.dirname(os.__file__)
|
||||
|
||||
def get(python, env=None):
|
||||
cmd = [python, '-c',
|
||||
'import platform; print(platform.architecture())']
|
||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE, env=env)
|
||||
r = p.communicate()
|
||||
if p.returncode:
|
||||
print(repr(r[0]))
|
||||
print(repr(r[1]), file=sys.stderr)
|
||||
self.fail('unexpected return code: {0} (0x{0:08X})'
|
||||
.format(p.returncode))
|
||||
return r
|
||||
|
||||
real = os.path.realpath(sys.executable)
|
||||
link = os.path.abspath(support.TESTFN)
|
||||
os.symlink(real, link)
|
||||
try:
|
||||
self.assertEqual(get(real), get(link, env=env))
|
||||
finally:
|
||||
os.remove(link)
|
||||
with support.PythonSymlink() as py:
|
||||
cmd = "-c", "import platform; print(platform.architecture())"
|
||||
self.assertEqual(py.call_real(*cmd), py.call_link(*cmd))
|
||||
|
||||
def test_platform(self):
|
||||
for aliased in (False, True):
|
||||
|
@ -275,6 +247,11 @@ class PlatformTest(unittest.TestCase):
|
|||
os.path.exists(sys.executable+'.exe'):
|
||||
# Cygwin horror
|
||||
executable = sys.executable + '.exe'
|
||||
elif sys.platform == "win32" and not os.path.exists(sys.executable):
|
||||
# App symlink appears to not exist, but we want the
|
||||
# real executable here anyway
|
||||
import _winapi
|
||||
executable = _winapi.GetModuleFileName(0)
|
||||
else:
|
||||
executable = sys.executable
|
||||
platform.libc_ver(executable)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue