GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-145410: Use _sysconfig.get_platform() in the platform module by vstinner · Pull Request #146148 · python/cpython

gh-145410: Use _sysconfig.get_platform() in the platform module #146148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vstinner wants to merge 4 commits into python:main from vstinner:platform_sysconfig

Uh oh!

There was an error while loading. Please reload this page.

Closed

gh-145410: Use _sysconfig.get_platform() in the platform module #146148

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit Hold shift + click to select a range
a43ceb0
gh-146145: Use _sysconfig.get_platform() in the platform module
vstinner Mar 18, 2026
a97eafd
Fix _sysconfig_architecture for win-amd64
vstinner Mar 19, 2026
35ebd34
Add more tests on architecture()
vstinner Mar 19, 2026
ab70761
Add even more tests on architecture()
vstinner Mar 19, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Next Next commit
gh-146145: Use _sysconfig.get_platform() in the platform module
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
vstinner committed Mar 18, 2026
commit a43ceb090202d1553a0f5827e062d6dfd1955e33

There are no files selected for viewing

43 changes: 37 additions & 6 deletions 43 Lib/platform.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,27 @@ def _syscmd_file(target, default=''):
'dos': ('', 'MSDOS'),
})


_sysconfig_architecture = frozendict({
# platform: (arch, bits, linkage)
'win32': ('x86', '32bit', 'WindowsPE'),
'win-amd64': ('AMD64', '32bit', 'WindowsPE'),
'win-arm32': ('ARM', '32bit', 'WindowsPE'),
Comment thread

@diegorusso diegorusso Mar 19, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Do we really care about Windows on Arm 32bit? This is specifically Windows RT 8.1 which ended support in 2023.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@diegorusso diegorusso Mar 19, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

From https://learn.microsoft.com/en-us/windows/arm/arm32-to-arm64

Windows devices running on an Arm processor (...) no longer support AArch32 (Arm32). This change impacts Universal Windows Platform apps that presently target AArch32 (Arm32). Support for 32-bit Arm versions of applications is removed in a future release of Windows 11.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@zooba zooba Mar 20, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Until all support is entirely ripped out, it's still possible for someone to compile it. So we don't need it, but if someone out there needs it, we may as well leave it in until we're actively trying to prevent them doing their job (which, as a general rule, we don't do).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

diegorusso reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
'win-arm64': ('ARM64', '64bit', 'WindowsPE'),
})

def _sysconfig_platform():
try:
import _sysconfig
except ImportError:
return ('', '', '')

platform = _sysconfig.get_platform()
if platform in _sysconfig_architecture:
return _sysconfig_architecture[platform]
return ('', '', '')


def architecture(executable=sys.executable, bits='', linkage=''):

""" Queries the given executable (defaults to the Python interpreter
Expand Down Expand Up @@ -745,10 +766,15 @@ def architecture(executable=sys.executable, bits='', linkage=''):
else:
fileout = ''

if not fileout and \
executable == sys.executable:
if not fileout and executable == sys.executable:
Comment thread

@zooba zooba Mar 20, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This is the necessary condition for using _sysconfig.get_platform() - no change required, just pointing out why it's okay to assume that sys.executable is us.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
# "file" command did not return anything; we'll try to provide
# some sensible defaults then...
if os.name == "nt":
# Use _sysconfig.get_platform() if available
_, b, l = _sysconfig_platform()
if b:
return (b, l)

if sys.platform in _default_architecture:
b, l = _default_architecture[sys.platform]
if b:
Expand Down Expand Up @@ -790,10 +816,10 @@ def architecture(executable=sys.executable, bits='', linkage=''):


def _get_machine_win32():
# Try to use the PROCESSOR_* environment variables
# available on Win XP and later; see
# http://support.microsoft.com/kb/888731 and
# http://www.geocities.com/rick_lively/MANUALS/ENV/MSWIN/PROCESSI.HTM
# Use _sysconfig.get_platform() if available
arch, bits, linkage = _sysconfig_platform()
if arch:
return arch
Comment thread
Comment on lines +819 to +822

@zooba zooba Mar 20, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

We can't do this, because the current CPU can be different from the Python runtime. We have to query the OS specifically, we can't rely on compile-time.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

# WOW64 processes mask the native architecture
try:
Expand All @@ -811,6 +837,11 @@ def _get_machine_win32():
else:
if arch:
return arch

# Try to use the PROCESSOR_* environment variables
# available on Win XP and later; see
# http://support.microsoft.com/kb/888731 and
# http://www.geocities.com/rick_lively/MANUALS/ENV/MSWIN/PROCESSI.HTM
return (
os.environ.get('PROCESSOR_ARCHITEW6432', '') or
os.environ.get('PROCESSOR_ARCHITECTURE', '')
Expand Down
18 changes: 17 additions & 1 deletion 18 Lib/test/test_platform.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -379,19 +379,35 @@ def test_uname_win32_ARCHITEW6432(self):
# using it, per
# http://blogs.msdn.com/david.wang/archive/2006/03/26/HOWTO-Detect-Process-Bitness.aspx

for sysconfig_platform, arch in (
('win32', 'x86'),
('win-arm32', 'ARM'),
('win-amd64', 'AMD64'),
('win-arm64', 'ARM64'),
):
with mock.patch('_sysconfig.get_platform', return_value=sysconfig_platform):
try:
platform._uname_cache = None
system, node, release, version, machine, processor = platform.uname()
self.assertEqual(machine, arch)
finally:
platform._uname_cache = None

# We also need to suppress WMI checks, as those are reliable and
# overrule the environment variables
def raises_oserror(*a):
raise OSError()

with support.swap_attr(platform, '_wmi_query', raises_oserror):
with (mock.patch('_sysconfig.get_platform', return_value=None),
support.swap_attr(platform, '_wmi_query', raises_oserror)):
with os_helper.EnvironmentVarGuard() as environ:
try:
del environ['PROCESSOR_ARCHITEW6432']
environ['PROCESSOR_ARCHITECTURE'] = 'foo'
platform._uname_cache = None
system, node, release, version, machine, processor = platform.uname()
self.assertEqual(machine, 'foo')

environ['PROCESSOR_ARCHITEW6432'] = 'bar'
platform._uname_cache = None
system, node, release, version, machine, processor = platform.uname()
Expand Down
2 changes: 2 additions & 0 deletions 2 Misc/NEWS.d/next/Library/2026-03-19-00-32-12.gh-issue-145410.gu1Ops.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:mod:`platform`: On Windows, use the ``_sysconfig`` module to get the
architecture and the machine. Patch by Victor Stinner.
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.