Skip to content

Commit 9b33bf5

Browse files
authored
Improves test_underpth_nosite_file to reveal why it fails. (#1763)
* Improves test_underpth_nosite_file to reveal why it fails. * Enable building with Windows 10 SDK. * Fix WinSDK detection * Fix initialization on Windows when a ._pth file exists. * Fix tabs * Adds comment about Py_GetPath call.
1 parent 66dc33b commit 9b33bf5

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

Lib/test/test_site.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -547,12 +547,16 @@ def test_underpth_nosite_file(self):
547547
env = os.environ.copy()
548548
env['PYTHONPATH'] = 'from-env'
549549
env['PATH'] = '{};{}'.format(exe_prefix, os.getenv('PATH'))
550-
rc = subprocess.call([exe_file, '-c',
551-
'import sys; sys.exit(sys.flags.no_site and '
552-
'len(sys.path) > 200 and '
553-
'sys.path == %r)' % sys_path,
554-
], env=env)
555-
self.assertTrue(rc, "sys.path is incorrect")
550+
output = subprocess.check_output([exe_file, '-c',
551+
'import sys; print("\\n".join(sys.path) if sys.flags.no_site else "")'
552+
], env=env, encoding='ansi')
553+
actual_sys_path = output.rstrip().split('\n')
554+
self.assert_(actual_sys_path, "sys.flags.no_site was False")
555+
self.assertEqual(
556+
actual_sys_path,
557+
sys_path,
558+
"sys.path is incorrect"
559+
)
556560

557561
def test_underpth_file(self):
558562
libpath = os.path.dirname(os.path.dirname(encodings.__file__))

PCbuild/python.props

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@
6363
<PythonExe Condition="'$(PythonExe)' == ''">$(BuildPath)python$(PyDebugExt).exe</PythonExe>
6464
</PropertyGroup>
6565

66+
<PropertyGroup Condition="$(DefaultWindowsSDKVersion) == ''">
67+
<!--
68+
Attempt to select the latest installed WinSDK. If we don't find any, then we will
69+
let the MSBuild targets determine which one it wants to use (typically the earliest
70+
possible version). Since we limit WINVER to Windows 7 anyway, it doesn't really
71+
matter which WinSDK version we use.
72+
-->
73+
<DefaultWindowsSDKVersion Condition="$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0@ProductVersion) == '10.0.15063'">10.0.15063.0</DefaultWindowsSDKVersion>
74+
<DefaultWindowsSDKVersion Condition="$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SDKs\Windows\v10.0@ProductVersion) == '10.0.15063'">10.0.15063.0</DefaultWindowsSDKVersion>
75+
<DefaultWindowsSDKVersion Condition="$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0@ProductVersion) == '10.0.10586'">10.0.10586.0</DefaultWindowsSDKVersion>
76+
<DefaultWindowsSDKVersion Condition="$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SDKs\Windows\v10.0@ProductVersion) == '10.0.10586'">10.0.10586.0</DefaultWindowsSDKVersion>
77+
<DefaultWindowsSDKVersion Condition="$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0@ProductVersion) == '10.0.10240'">10.0.10240.0</DefaultWindowsSDKVersion>
78+
<DefaultWindowsSDKVersion Condition="$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SDKs\Windows\v10.0@ProductVersion) == '10.0.10240'">10.0.10240.0</DefaultWindowsSDKVersion>
79+
</PropertyGroup>
80+
6681
<PropertyGroup Condition="'$(OverrideVersion)' == ''">
6782
<!--
6883
Read version information from Include\patchlevel.h. The following properties are set:

Python/pylifecycle.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,15 @@ _Py_InitializeEx_Private(int install_sigs, int install_importlib)
412412
if (interp->sysdict == NULL)
413413
Py_FatalError("Py_Initialize: can't initialize sys dict");
414414
Py_INCREF(interp->sysdict);
415+
416+
/* GetPath may initialize state that _PySys_EndInit locks
417+
in, and so has to be called first.
418+
419+
Hopefully one day Eric Snow will fix this. */
420+
PySys_SetPath(Py_GetPath());
415421
if (_PySys_EndInit(interp->sysdict) < 0)
416422
Py_FatalError("Py_Initialize: can't initialize sys");
417423
_PyImport_FixupBuiltin(sysmod, "sys");
418-
PySys_SetPath(Py_GetPath());
419424
PyDict_SetItemString(interp->sysdict, "modules",
420425
interp->modules);
421426

0 commit comments

Comments
 (0)