Skip to content

Commit d63344e

Browse files
committed
gh-154200: Use sysconfig.get_platform() in test_importlib.test_windows
test_tagged_suffix computed its expected extension suffix with a vendored port of distutils.util.get_platform() that sniffs sys.version for 'amd64'. Python/getversion.c truncates the compiler segment of sys.version at 80 characters, so on clang-cl builds -- whose banner carries a long __clang_version__ -- the marker is cut off, the helper falls through to sys.platform ('win32'), and the test expects '.cp316t-win32.pyd' while the interpreter correctly reports '.cp316t-win_amd64.pyd'. sysconfig.get_platform() no longer parses sys.version on Windows (gh-145410); it uses the _sysconfig C accelerator, which derives the platform from compile-time architecture macros and is compiler-agnostic. Use it and drop the vendored copy, its only caller. This also removes the VSCMD_ARG_TGT_ARCH branch, which trusted the ambient Visual Studio target architecture over the interpreter actually running the test.
1 parent 40f7fbf commit d63344e

1 file changed

Lines changed: 2 additions & 20 deletions

File tree

Lib/test/test_importlib/test_windows.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import re
66
import sys
7+
import sysconfig
78
import unittest
89
from test import support
910
from test.support import import_helper
@@ -17,25 +18,6 @@
1718
EnumKey, CloseKey, DeleteKey, OpenKey
1819
)
1920

20-
def get_platform():
21-
# Port of distutils.util.get_platform().
22-
TARGET_TO_PLAT = {
23-
'x86' : 'win32',
24-
'x64' : 'win-amd64',
25-
'arm' : 'win-arm32',
26-
}
27-
if ('VSCMD_ARG_TGT_ARCH' in os.environ and
28-
os.environ['VSCMD_ARG_TGT_ARCH'] in TARGET_TO_PLAT):
29-
return TARGET_TO_PLAT[os.environ['VSCMD_ARG_TGT_ARCH']]
30-
elif 'amd64' in sys.version.lower():
31-
return 'win-amd64'
32-
elif '(arm)' in sys.version.lower():
33-
return 'win-arm32'
34-
elif '(arm64)' in sys.version.lower():
35-
return 'win-arm64'
36-
else:
37-
return sys.platform
38-
3921
def delete_registry_tree(root, subkey):
4022
try:
4123
hkey = OpenKey(root, subkey, access=KEY_ALL_ACCESS)
@@ -143,7 +125,7 @@ def test_tagged_suffix(self):
143125
suffixes = self.machinery.EXTENSION_SUFFIXES
144126
abi_flags = "t" if support.Py_GIL_DISABLED else ""
145127
ver = sys.version_info
146-
platform = re.sub('[^a-zA-Z0-9]', '_', get_platform())
128+
platform = re.sub('[^a-zA-Z0-9]', '_', sysconfig.get_platform())
147129
expected_tag = f".cp{ver.major}{ver.minor}{abi_flags}-{platform}.pyd"
148130
try:
149131
untagged_i = suffixes.index(".pyd")

0 commit comments

Comments
 (0)