FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-145410: Use _sysconfig.get_platform() in the platform module by vstinner · Pull Request #146148 · python/cpython · GitHub

Repository navigation

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

Closed
vstinner wants to merge 4 commits into
python:mainfrom
vstinner:platform_sysconfig
Closed

vstinner wants to merge 4 commits into
python:mainfrom
vstinner:platform_sysconfig

Conversation

vstinner commented Mar 18, 2026 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

vstinner changed the title gh-146145: Use _sysconfig.get_platform() in the platform module gh-145410: Use _sysconfig.get_platform() in the platform module Mar 18, 2026

Copy link
Copy Markdown
Member Author

The change avoids the WMI query (SELECT Architecture FROM Win32_Processor) in platform.machine() for these 4 sysconfig platforms: win32, win-amd64, win-arm32 and win-arm64.

cc @zooba

Copy link
Copy Markdown
Member Author

See also issues gh-102536 and gh-98962.

Copy link
Copy Markdown
Member

This looks fine, but can we be sure that the output does not change across supported Windows platforms ?

Copy link
Copy Markdown
Member Author

According to #98962 (comment) comment, platform.architecture() is always ARM64, whereas sysconfig.get_platform() can be win-arm64, win-amd64 or win32 when Python is built for different architectures and run on ARM64 Windows. So it seems like platform.architecture() is not directly related to sysconfig.get_platform(), they can be different and my change is wrong.

Copy link
Copy Markdown
Member Author

cc @diegorusso

diegorusso left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm OK with the changes, just a minor comment on win-arm32 (that in my opinion we shouldn't need)

Comment thread Lib/platform.py
# platform: (arch, bits, linkage)
'win32': ('x86', '32bit', 'WindowsPE'),
'win-amd64': ('AMD64', '64bit', 'WindowsPE'),
'win-arm32': ('ARM', '32bit', 'WindowsPE'),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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).

diegorusso left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Actually while we are here, we should update the documentation as well (if it is found to be inconsistent)

Copy link
Copy Markdown
Member

According to #98962 (comment) comment, platform.architecture() is always ARM64, whereas sysconfig.get_platform() can be win-arm64, win-amd64 or win32 when Python is built for different architectures and run on ARM64 Windows. So it seems like platform.architecture() is not directly related to sysconfig.get_platform(), they can be different and my change is wrong.

The platform module is meant for inspecting the platform Python runs on, sysconfig normally refers to the platform and settings it was compiled with.

As for return values, "win-arm64" is not an architecture. The "win-" part refers to the OS.

diegorusso left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I've just realised that I approved the PR but I didn't mean to :)
I'm not sure If I can un-approve it, hence requesting a change.

My comments still stand.

bedevere-app Bot commented Mar 19, 2026

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

Comment thread Lib/platform.py
Comment on lines +819 to +822
# Use _sysconfig.get_platform() if available
arch, bits, linkage = _sysconfig_platform()
if arch:
return arch

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Comment thread Lib/platform.py

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Member Author

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.

Yeah, I understood that when reading #98962 after I wrote my PR. I prefer to close my PR, since it would return the wrong platform in some cases.

vstinner closed this Mar 20, 2026
vstinner deleted the platform_sysconfig branch March 20, 2026 12:17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

4 participants


Back | FazBrowse Home | New Git URL