Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
python/features.bzl export-subst
tools/publish/*.txt linguist-generated=true
tests/uv/lock/testdata/requirements.txt text eol=lf
python/private/runtimes_manifest_workspace.bzl text eol=lf
python/private/runtimes_manifest.txt text eol=lf
python/private/runtimes_manifest.bzl text eol=lf

*.bat text eol=crlf
8 changes: 1 addition & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,7 @@ repos:
name: Sort runtimes manifest
language: system
entry: ./python/private/tools/sort_manifest.py
files: ^python/private/runtimes_manifest\.txt$
- id: sync-runtimes-manifest
name: Sync runtimes manifest workspace
language: system
entry: ./python/private/tools/sync_runtimes_manifest_workspace.py
files: ^python/private/runtimes_manifest\.txt$
pass_filenames: false
files: ^python/private/runtimes_manifest\.bzl$
- id: sync-downloader-configs
name: Sync downloader configs
language: system
Expand Down
4 changes: 4 additions & 0 deletions news/4294.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(toolchains) Evaluating the {obj}`python` module extension and `@pythons_hub`
repository no longer materializes the `@rules_python` repository when using
`--experimental_remote_repo_contents_cache`
([#4294](https://github.com/bazel-contrib/rules_python/issues/4294)).
2 changes: 1 addition & 1 deletion python/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ bzl_library(
deps = [
"//python/private:pbs_manifest",
"//python/private:platform_info",
"//python/private:runtimes_manifest_workspace",
"//python/private:runtimes_manifest",
],
)

Expand Down
20 changes: 12 additions & 8 deletions python/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ licenses(["notice"])

exports_files([
"runtime_env_toolchain_interpreter.sh",
"runtimes_manifest.txt",
"runtimes_manifest_workspace.bzl",
"runtimes_manifest.bzl",
])

distribution_filegroup(
Expand Down Expand Up @@ -224,10 +223,13 @@ sentinel(
visibility = ["//visibility:public"],
)

py_binary(
name = "sync_runtimes_manifest_workspace",
srcs = ["tools/sync_runtimes_manifest_workspace.py"],
visibility = ["//:__subpackages__"],
py_library(
name = "sort_manifest_lib",
srcs = ["tools/sort_manifest.py"],
imports = ["../.."],
visibility = [
"//tests/toolchains:__pkg__",
],
)

# Tool used by py_test's validation action to statically check that the main
Expand Down Expand Up @@ -749,6 +751,7 @@ bzl_library(
":python_register_toolchains",
":pythons_hub",
":repo_utils",
":runtimes_manifest",
":toolchains_repo",
":version",
"//python:versions",
Expand Down Expand Up @@ -796,6 +799,7 @@ bzl_library(
srcs = ["pythons_hub.bzl"],
deps = [
":pbs_manifest",
":runtimes_manifest",
":text_util",
":toolchains_repo",
"//python:versions",
Expand Down Expand Up @@ -1012,8 +1016,8 @@ bzl_library(
)

bzl_library(
name = "runtimes_manifest_workspace",
srcs = ["runtimes_manifest_workspace.bzl"],
name = "runtimes_manifest",
srcs = ["runtimes_manifest.bzl"],
)

bzl_library(
Expand Down
33 changes: 28 additions & 5 deletions python/private/python.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ load(":pyproject_utils.bzl", "read_pyproject", "version_from_requires_python")
load(":python_register_toolchains.bzl", "python_register_toolchains")
load(":pythons_hub.bzl", "hub_repo")
load(":repo_utils.bzl", "repo_utils")
load(":runtimes_manifest.bzl", "MANIFEST_TEXT")
load(
":toolchains_repo.bzl",
"host_compatible_python_repo",
Expand All @@ -39,13 +40,20 @@ load(
)
load(":version.bzl", "version")

def parse_modules(*, module_ctx, logger = None, _fail = fail):
def parse_modules(
*,
module_ctx,
logger = None,
_fail = fail,
_default_runtime_manifest = MANIFEST_TEXT):
"""Parse the modules and return a struct for registrations.

Args:
module_ctx: {type}`module_ctx` module context.
logger: {type}`repo_utils.logger` A logger to use.
_fail: {type}`function` the failure function, mainly for testing.
_default_runtime_manifest: {type}`str` the built-in runtimes manifest,
only overridden for testing.

Returns:
A struct with the following attributes:
Expand Down Expand Up @@ -84,7 +92,12 @@ def parse_modules(*, module_ctx, logger = None, _fail = fail):
# Map of string Major.Minor or Major.Minor.Patch to the toolchain_info struct
global_toolchain_versions = {}

config = _get_toolchain_config(mctx = module_ctx, modules = module_ctx.modules, _fail = _fail)
config = _get_toolchain_config(
mctx = module_ctx,
modules = module_ctx.modules,
default_runtime_manifest = _default_runtime_manifest,
_fail = _fail,
)

default_python_version = _compute_default_python_version(module_ctx)

Expand Down Expand Up @@ -762,11 +775,12 @@ def _populate_from_pbs_manifest(
mctx,
add_runtime_manifest_urls = [],
add_runtime_manifest_files = [],
add_runtime_manifest_contents = [],
runtime_manifest_sha = "",
base_urls = [],
available_versions,
_fail):
manifest_contents = []
manifest_contents = list(add_runtime_manifest_contents)

if add_runtime_manifest_urls:
manifest_path = mctx.path("runtime_manifest")
Expand Down Expand Up @@ -835,12 +849,19 @@ def _populate_from_pbs_manifest(
v_dict.setdefault("url", {})[platform_key] = urls
v_dict.setdefault("strip_prefix", {})[platform_key] = strip_prefix

def _get_toolchain_config(*, mctx, modules, _fail = fail):
def _get_toolchain_config(
*,
mctx,
modules,
default_runtime_manifest,
_fail = fail):
"""Computes the configs for toolchains.

Args:
mctx: The module context.
modules: The modules from module_ctx
default_runtime_manifest: The contents of the built-in runtimes
manifest.
_fail: Function to call for failing; only used for testing.

Returns:
Expand All @@ -864,7 +885,9 @@ def _get_toolchain_config(*, mctx, modules, _fail = fail):

_populate_from_pbs_manifest(
mctx = mctx,
add_runtime_manifest_files = [Label("//python/private:runtimes_manifest.txt")],
# Loaded rather than read by Label, so the remote repo contents cache
# does not have to materialize this repo.
add_runtime_manifest_contents = [default_runtime_manifest],
base_urls = DEFAULT_RELEASE_BASE_URLS,
available_versions = available_versions,
_fail = _fail,
Expand Down
6 changes: 4 additions & 2 deletions python/private/pythons_hub.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

load("//python:versions.bzl", "PLATFORMS")
load(":pbs_manifest.bzl", "parse_runtime_manifest")
load(":runtimes_manifest.bzl", "MANIFEST_TEXT")
load(":text_util.bzl", "render")
load(":toolchains_repo.bzl", "toolchain_suites_content")

Expand Down Expand Up @@ -121,8 +122,9 @@ def _hub_repo_impl(rctx):

python_versions = rctx.attr.python_versions
if not python_versions and not rctx.attr.toolchain_python_versions:
content = rctx.read(rctx.path(Label("//python/private:runtimes_manifest.txt")))
entries = parse_runtime_manifest(content)
# Loaded rather than read by Label, so the remote repo contents cache
# does not have to materialize this repo.
entries = parse_runtime_manifest(MANIFEST_TEXT)
python_versions_str = render.list(sorted({getattr(e, "python_version", ""): None for e in entries if getattr(e, "python_version", "")}))

else:
Expand Down
15 changes: 13 additions & 2 deletions python/private/runtimes_manifest.txt → python/private/runtimes_manifest.bzl
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
"""Manifest of built-in Python runtimes.

It's a .bzl file so that both WORKSPACE mode and Bzlmod can load the manifest
directly without needing to read a file by Label (which would otherwise force
Bazel's remote repository contents cache to materialize the entire repository).
"""

MANIFEST_TEXT = """
# Manifest of runtimes to make available
# Originally generated circa 2026-06 from the runtimes in TOOL_VERSIONS from the original python/versions.bzl
# To sort this file, execute: ./python/private/tools/sort_manifest.py python/private/runtimes_manifest.txt
# Originally generated circa 2026-06 from the runtimes in TOOL_VERSIONS from
# the original python/versions.bzl
# To sort this file, execute:
# ./python/private/tools/sort_manifest.py python/private/runtimes_manifest.bzl

1409acd9a506e2d1d3b65c1488db4e40d8f19d09a7df099667c87a506f71c0ef 20220227/cpython-3.10.2+20220227-aarch64-apple-darwin-install_only.tar.gz
8f351a8cc348bb45c0f95b8634c8345ec6e749e483384188ad865b7428342703 20220227/cpython-3.10.2+20220227-aarch64-unknown-linux-gnu-install_only.tar.gz
Expand Down Expand Up @@ -1038,3 +1048,4 @@ ceb5637723387877f65b869c3d2cc36975a689824df0d075f0f39d26afb0d2b6 20261003/cpyth
986fda009bd9f37397f47a52d9bb37b761e7bc3d7dc0403a5702c050ee9cd091 20261003/cpython-3.15.0rc3+20261003-x86_64-unknown-linux-musl-freethreaded-install_only_stripped.tar.gz
4a69a480e523e9ed4d5deb941a0c0ccfe1001f3269f6b3091975f059c14de99d 20261003/cpython-3.15.0rc3+20261003-x86_64-unknown-linux-musl-install_only.tar.gz
2be25b45a6f84cc46f6f0cb144c4292dd0e5bbdb3f07442a0f270b51ecc7da0f 20261003/cpython-3.15.0rc3+20261003-x86_64-unknown-linux-musl-install_only_stripped.tar.gz
"""
Loading
Loading