Skip to content

gh-154200: Use sysconfig.get_platform() in test_importlib.test_windows#154210

Open
SynaptSea wants to merge 2 commits into
python:mainfrom
SynaptSea:fix-test-windows-platform
Open

gh-154200: Use sysconfig.get_platform() in test_importlib.test_windows#154210
SynaptSea wants to merge 2 commits into
python:mainfrom
SynaptSea:fix-test-windows-platform

Conversation

@SynaptSea

@SynaptSea SynaptSea commented Jul 20, 2026

Copy link
Copy Markdown

Fixes #154200

test_tagged_suffix computes its expected extension suffix with a vendored
"Port of distutils.util.get_platform()" that sniffs sys.version.lower() for 'amd64'.

Python/getversion.c truncates the compiler segment of sys.version at 80 characters
("%.80s"). On clang-cl builds the banner is
"[Clang " __clang_version__ "] 64 bit (AMD64) with MSC v.<n> CRT]", and official LLVM
Windows binaries have an 86-character __clang_version__, so the (AMD64) marker is always
cut off. The helper falls through to return sys.platform -> 'win32', and the test expects
.cp316t-win32.pyd while the interpreter correctly reports .cp316t-win_amd64.pyd:

AssertionError: '.cp316t-win32.pyd' not found in ['.cp316t-win_amd64.pyd', '.pyd']

sysconfig.get_platform() no longer has this problem: since gh-145410 it does not parse
sys.version on Windows but delegates to the _sysconfig C accelerator, which derives the
platform from compile-time architecture macros and is compiler-agnostic. So this uses it and
deletes the vendored copy, which that call site was the only consumer of.

This is not circular: SYSCONFIG_PLATFORM in Modules/_sysconfig.c and PYD_PLATFORM_TAG in
PC/pyconfig.h are independent definitions in separate files, so the assertion still
cross-checks two separate derivations.

It also drops the VSCMD_ARG_TGT_ARCH branch, which trusted the ambient Visual Studio
developer-prompt target architecture over the interpreter actually executing the test.
That was backwards — EXTENSION_SUFFIXES is compiled into the running binary — and it is
why the failure only reproduced outside a VS developer prompt.

Testing

On a local clang-cl free-threaded build, python -m unittest test.test_importlib.test_windows:

  • before: Ran 11 tests ... FAILED (failures=2) (the Frozen_ and Source_ variants)
  • after: Ran 11 tests ... OK

Also OK with VSCMD_ARG_TGT_ARCH=x64, and with VSCMD_ARG_TGT_ARCH=x86 deliberately
mismatched against this amd64 interpreter — the old code would have computed 'win32' and
failed there. Full python -m test test_importlib: run=1229 skipped=23, SUCCESS.

Note the re.sub() is still required: sysconfig.get_platform() returns win-amd64 with a
hyphen while PYD_PLATFORM_TAG uses win_amd64. os and re both remain in use elsewhere
in the module, so no imports become unused.

NEWS

This is a test-only change, which the devguide lists as not requiring a Misc/NEWS.d entry,
so I have not added a blurb — could a maintainer apply skip news? Happy to add one instead
if you would prefer, on the grounds that it unblocks a whole build configuration.

…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 (pythongh-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.
Copilot AI review requested due to automatic review settings July 20, 2026 01:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a Windows-only test failure in test_importlib.test_windows by replacing a local, sys.version-parsing platform detector with sysconfig.get_platform(), which is compiler-agnostic on Windows and avoids truncation-related mis-detection on clang-cl builds.

Changes:

  • Remove the vendored get_platform() helper that relied on VSCMD_ARG_TGT_ARCH and sys.version parsing.
  • Compute the expected .pyd platform tag using sysconfig.get_platform() and keep normalization via re.sub(..., '_', ...) for win-amd64win_amd64.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@chris-eibl
chris-eibl self-requested a review July 20, 2026 10:04
@chris-eibl chris-eibl added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jul 20, 2026
@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @chris-eibl for commit d63344e 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F154210%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jul 20, 2026
@chris-eibl

Copy link
Copy Markdown
Member

Since version 22, clang-cl returns a much longer __clang_version__. I think it would make sense to switch to

#if defined(__clang__)
#define COMPILER "[Clang " __clang_major__ "." __clang_minor__ "." __clang_patchlevel__ "]"

like suggested in #145410 (comment).

This would also fix #154199.

Nevertheless, this change here lgtm, too.

Fwiw, during EP2026 sprints @zware setup a clang-cl buildbot.

Cc @encukou .

@chris-eibl

Copy link
Copy Markdown
Member

Fwiw, during EP2026 sprints @zware setup a clang-cl buildbot.

See python/buildmaster-config#764

@python-cla-bot

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

CLA not signed

@chris-eibl

Copy link
Copy Markdown
Member

I do not know why the CLA step got stuck. I've clicked "update branch" in the hope it works now ...

@chris-eibl

Copy link
Copy Markdown
Member

Yupp, that did it :)

@SynaptSea can you please sign the CLA?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test_importlib.test_windows: vendored get_platform() misdetects clang-cl builds as win32, failing test_tagged_suffix

5 participants