From 27dee243db292ba56a7c185a975599450189d1a9 Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Sun, 8 Nov 2026 12:39:19 +0900 Subject: [PATCH 1/2] fix(toolchain): keep the strip_prefix when single_version_override has no urls When single_version_override was used without urls, e.g. to only set libpython or distutils, the strip_prefix of all platforms was reset to the tag default. The archives of the full flavor, which are used for the freethreaded builds of some versions, need a different strip_prefix, so keep the existing strip_prefix when the archives are not overridden. --- ...gle-version-override-strip-prefix.fixed.md | 3 ++ python/private/python.bzl | 14 ++++++--- tests/python/python_tests.bzl | 29 +++++++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 news/single-version-override-strip-prefix.fixed.md diff --git a/news/single-version-override-strip-prefix.fixed.md b/news/single-version-override-strip-prefix.fixed.md new file mode 100644 index 0000000000..651cc8603e --- /dev/null +++ b/news/single-version-override-strip-prefix.fixed.md @@ -0,0 +1,3 @@ +(toolchains) {obj}`python.single_version_override` without `urls` no longer +resets the `strip_prefix` of the existing archives, which broke the +freethreaded toolchains that use the `full` archives. diff --git a/python/private/python.bzl b/python/private/python.bzl index 6d8237b24e..0d392f89a0 100644 --- a/python/private/python.bzl +++ b/python/private/python.bzl @@ -612,12 +612,18 @@ def _process_single_version_overrides(*, tag, _fail = fail, default): return sha256 = dict(tag.sha256) or available_versions[tag.python_version]["sha256"] - override = { - "sha256": sha256, - "strip_prefix": { + if tag.urls: + strip_prefix = { platform: tag.strip_prefix for platform in sha256 - }, + } + else: + # The archives are not overridden, so keep their strip_prefix, which + # differs between the archive flavors. + strip_prefix = available_versions[tag.python_version]["strip_prefix"] + override = { + "sha256": sha256, + "strip_prefix": strip_prefix, "url": { platform: list(tag.urls) for platform in tag.sha256 diff --git a/tests/python/python_tests.bzl b/tests/python/python_tests.bzl index e6956fa91e..e881feb9f7 100644 --- a/tests/python/python_tests.bzl +++ b/tests/python/python_tests.bzl @@ -16,6 +16,7 @@ load("@pythons_hub//:versions.bzl", "MINOR_MAPPING") load("@rules_testing//lib:test_suite.bzl", "test_suite") +load("//python:versions.bzl", "TOOL_VERSIONS") load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") # buildifier: disable=bzl-visibility load("//python/private:python.bzl", "parse_modules") # buildifier: disable=bzl-visibility load("//python/private:repo_utils.bzl", "repo_utils") # buildifier: disable=bzl-visibility @@ -441,6 +442,34 @@ def _test_libpython_override(env): _tests.append(_test_libpython_override) +def _test_single_version_override_keeps_strip_prefix(env): + # This version has `full` archives for the freethreaded builds, which use + # a different strip_prefix. + python_version = "3.13.0" + py = parse_modules( + module_ctx = python_ext.mctx( + python_ext.module( + name = "my_module", + is_root = True, + single_version_override = [ + python_ext.single_version_override( + libpython = "exclude", + python_version = python_version, + ), + ], + toolchain = [python_ext.toolchain(python_version = "3.13")], + ), + _rules_python_module(), + ), + logger = repo_utils.logger(verbosity_level = 0, name = "python"), + ) + + env.expect.that_dict( + py.config.default["tool_versions"][python_version]["strip_prefix"], + ).contains_exactly(TOOL_VERSIONS[python_version]["strip_prefix"]) + +_tests.append(_test_single_version_override_keeps_strip_prefix) + _ARCHIVE_FLAVOR_MANIFEST = """ 1111111111111111111111111111111111111111111111111111111111111111 20260414/cpython-3.14.4+20260414-x86_64-unknown-linux-gnu-install_only.tar.gz 2222222222222222222222222222222222222222222222222222222222222222 20260414/cpython-3.14.4+20260414-x86_64-unknown-linux-gnu-install_only_stripped.tar.gz From 4ac5b128fdda12dbdea283595feba867fe8d9427 Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Sun, 8 Nov 2026 13:20:44 +0900 Subject: [PATCH 2/2] news: name the strip_prefix entry after the PR --- ...ingle-version-override-strip-prefix.fixed.md => 4435.fixed.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename news/{single-version-override-strip-prefix.fixed.md => 4435.fixed.md} (100%) diff --git a/news/single-version-override-strip-prefix.fixed.md b/news/4435.fixed.md similarity index 100% rename from news/single-version-override-strip-prefix.fixed.md rename to news/4435.fixed.md