Skip to content

gh-145410: Fix sysconfig.get_platform() for truncated sys.version on Windows#146146

Closed
Jah-yee wants to merge 1 commit intopython:mainfrom
Jah-yee:fix-sysconfig-truncated-sysversion-1773876066
Closed

gh-145410: Fix sysconfig.get_platform() for truncated sys.version on Windows#146146
Jah-yee wants to merge 1 commit intopython:mainfrom
Jah-yee:fix-sysconfig-truncated-sysversion-1773876066

Conversation

@Jah-yee
Copy link

@Jah-yee Jah-yee commented Mar 18, 2026

Bug Fix

On Windows, sysconfig.get_platform() checks for the string 'amd64' in sys.version to detect 64-bit builds. However, sys.version can be truncated (e.g., ~100 characters on clang builds), causing 'amd64' to be missing and returning 'win32' incorrectly.

This causes problems when installing native packages via pip because cp314-cp314-amd64 is not in the list of supported tags.

The Fix

This PR adds sys.maxsize > 2**32 as a fallback check, which is reliable even when sys.version is truncated. It also reorders the arm64 check before arm32 for proper precedence.

Before:

if os.name == 'nt':
    if 'amd64' in sys.version.lower():
        return 'win-amd64'
    if '(arm)' in sys.version.lower():
        return 'win-arm32'
    if '(arm64)' in sys.version.lower():
        return 'win-arm64'
    return sys.platform

After:

if os.name == 'nt':
    if 'amd64' in sys.version.lower():
        return 'win-amd64'
    if sys.maxsize > 2**32:
        # 64-bit Windows where sys.version may be truncated
        return 'win-amd64'
    if '(arm64)' in sys.version.lower():
        return 'win-arm64'
    if '(arm)' in sys.version.lower():
        return 'win-arm32'
    return sys.platform

Fixes: #145410


Submitted by automated agent

On Windows, sysconfig.get_platform() checks for 'amd64' in sys.version to
detect 64-bit builds. However, sys.version can be truncated (e.g., ~100 chars
on clang builds), causing 'amd64' to be missing and returning 'win32' incorrectly.

This fix adds sys.maxsize > 2**32 as a fallback check, which is reliable even
when sys.version is truncated. Also reorders arm64 check before arm32 for
proper precedence.

Fixes: python#145410
@Jah-yee Jah-yee requested a review from FFY00 as a code owner March 18, 2026 23:21
@python-cla-bot
Copy link

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

CLA not signed

@bedevere-app
Copy link

bedevere-app bot commented Mar 18, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@StanFromIreland StanFromIreland changed the title Fix sysconfig.get_platform() for truncated sys.version on Windows gh-145410: Fix sysconfig.get_platform() for truncated sys.version on Windows Mar 19, 2026
@StanFromIreland
Copy link
Member

This was resolved by b9d4318.

Also I see this was "Submitted by automated agent."

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.

sysconfig.get_platform() could return wrong value because sys.version is truncated

2 participants