From 2390c98f945046f8b7eccc007bfdcf780e48c9f3 Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Sat, 21 Nov 2026 13:48:58 +0900 Subject: [PATCH 1/3] build: add pypackaging.bzl 0.3.0 as a dependency We have been maintaining our own Starlark implementations of PEP 440 versions and PEP 508 requirements and environment markers. `pypackaging.bzl` is a Starlark port of `packaging` that is tested against the upstream test-suite, so add it as a dependency in order to start using it instead. `WORKSPACE` users get the new dependency from `py_repositories`. Our own `WORKSPACE` file now calls it before the internal setup, which loads the repository rules that are going to use the new dependency. --- BUILD.bazel | 3 ++- MODULE.bazel | 1 + WORKSPACE | 9 ++++++--- downloader_config.cfg | 2 ++ gazelle/downloader_config.cfg | 2 ++ python/private/py_repositories.bzl | 6 ++++++ sphinxdocs/downloader_config.cfg | 2 ++ 7 files changed, 21 insertions(+), 4 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 9e5c70b732..ae9c87d1bf 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -27,7 +27,8 @@ load("@package_metadata//rules:package_metadata.bzl", "package_metadata") # gazelle:resolve starlark @bazel_tools//tools/build_defs/repo:http.bzl //python/private:bazel_tools # gazelle:resolve starlark @bazel_tools//tools/build_defs/repo:utils.bzl //python/private:bazel_tools -# Prevent Gazelle from incorrectly stripping the .bzl suffix from the toml.bzl repo name +# Prevent Gazelle from incorrectly stripping the .bzl suffix from the repo names +# gazelle:resolve starlark @pypackaging.bzl//:pypackaging.bzl @pypackaging.bzl//:pypackaging # gazelle:resolve starlark @toml.bzl//:toml.bzl @toml.bzl//:toml # Override Gazelle's incorrect default resolution for platforms host constraints Starlark library diff --git a/MODULE.bazel b/MODULE.bazel index 98ae8114b5..45e18a03f4 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -8,6 +8,7 @@ bazel_dep(name = "bazel_features", version = "1.55.0") bazel_dep(name = "bazel_skylib", version = "1.8.2") bazel_dep(name = "package_metadata", version = "0.0.13") bazel_dep(name = "platforms", version = "0.0.11") +bazel_dep(name = "pypackaging.bzl", version = "0.3.0") bazel_dep(name = "rules_cc", version = "0.2.17") bazel_dep(name = "toml.bzl", version = "0.4.1") diff --git a/WORKSPACE b/WORKSPACE index 631b94118d..f282982d82 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -61,14 +61,17 @@ load("@stardoc_maven//:defs.bzl", stardoc_pinned_maven_install = "pinned_maven_i stardoc_pinned_maven_install() +load("//python:repositories.bzl", "py_repositories", "python_register_multi_toolchains") + +# This needs to be called before the internal setup, because the repository +# rules that it loads use the dependencies defined here. +py_repositories() + load("//:internal_dev_setup.bzl", "rules_python_internal_setup") rules_python_internal_setup() load("@pythons_hub//:versions.bzl", "PYTHON_VERSIONS") -load("//python:repositories.bzl", "py_repositories", "python_register_multi_toolchains") - -py_repositories() python_register_multi_toolchains( name = "python", diff --git a/downloader_config.cfg b/downloader_config.cfg index 8bde140608..d445f15ff1 100644 --- a/downloader_config.cfg +++ b/downloader_config.cfg @@ -20,6 +20,7 @@ rewrite ^github\.com/bazelbuild/rules_swift/(.*) github.com/bazelbuild/rules_swi rewrite ^github\.com/bazelbuild/rules_testing/(.*) github.com/bazelbuild/rules_testing/$1 rewrite ^github\.com/bazelbuild/stardoc/(.*) github.com/bazelbuild/stardoc/$1 rewrite ^github\.com/google/googletest/(.*) github.com/google/googletest/$1 +rewrite ^github\.com/jvolkman/pypackaging\.bzl/(.*) github.com/jvolkman/pypackaging.bzl/$1 rewrite ^github\.com/jvolkman/toml\.bzl/(.*) github.com/jvolkman/toml.bzl/$1 rewrite ^github\.com/protocolbuffers/protobuf/(.*) github.com/protocolbuffers/protobuf/$1 # keep-sorted end @@ -48,6 +49,7 @@ rewrite ^github\.com/bazelbuild/rules_swift/(.*) mirror.bazel.build/github.com/b rewrite ^github\.com/bazelbuild/rules_testing/(.*) mirror.bazel.build/github.com/bazelbuild/rules_testing/$1 rewrite ^github\.com/bazelbuild/stardoc/(.*) mirror.bazel.build/github.com/bazelbuild/stardoc/$1 rewrite ^github\.com/google/googletest/(.*) mirror.bazel.build/github.com/google/googletest/$1 +rewrite ^github\.com/jvolkman/pypackaging\.bzl/(.*) mirror.bazel.build/github.com/jvolkman/pypackaging.bzl/$1 rewrite ^github\.com/jvolkman/toml\.bzl/(.*) mirror.bazel.build/github.com/jvolkman/toml.bzl/$1 rewrite ^github\.com/protocolbuffers/protobuf/(.*) mirror.bazel.build/github.com/protocolbuffers/protobuf/$1 # keep-sorted end diff --git a/gazelle/downloader_config.cfg b/gazelle/downloader_config.cfg index 8bde140608..d445f15ff1 100644 --- a/gazelle/downloader_config.cfg +++ b/gazelle/downloader_config.cfg @@ -20,6 +20,7 @@ rewrite ^github\.com/bazelbuild/rules_swift/(.*) github.com/bazelbuild/rules_swi rewrite ^github\.com/bazelbuild/rules_testing/(.*) github.com/bazelbuild/rules_testing/$1 rewrite ^github\.com/bazelbuild/stardoc/(.*) github.com/bazelbuild/stardoc/$1 rewrite ^github\.com/google/googletest/(.*) github.com/google/googletest/$1 +rewrite ^github\.com/jvolkman/pypackaging\.bzl/(.*) github.com/jvolkman/pypackaging.bzl/$1 rewrite ^github\.com/jvolkman/toml\.bzl/(.*) github.com/jvolkman/toml.bzl/$1 rewrite ^github\.com/protocolbuffers/protobuf/(.*) github.com/protocolbuffers/protobuf/$1 # keep-sorted end @@ -48,6 +49,7 @@ rewrite ^github\.com/bazelbuild/rules_swift/(.*) mirror.bazel.build/github.com/b rewrite ^github\.com/bazelbuild/rules_testing/(.*) mirror.bazel.build/github.com/bazelbuild/rules_testing/$1 rewrite ^github\.com/bazelbuild/stardoc/(.*) mirror.bazel.build/github.com/bazelbuild/stardoc/$1 rewrite ^github\.com/google/googletest/(.*) mirror.bazel.build/github.com/google/googletest/$1 +rewrite ^github\.com/jvolkman/pypackaging\.bzl/(.*) mirror.bazel.build/github.com/jvolkman/pypackaging.bzl/$1 rewrite ^github\.com/jvolkman/toml\.bzl/(.*) mirror.bazel.build/github.com/jvolkman/toml.bzl/$1 rewrite ^github\.com/protocolbuffers/protobuf/(.*) mirror.bazel.build/github.com/protocolbuffers/protobuf/$1 # keep-sorted end diff --git a/python/private/py_repositories.bzl b/python/private/py_repositories.bzl index 5353b8b8c5..f92152a3e6 100644 --- a/python/private/py_repositories.bzl +++ b/python/private/py_repositories.bzl @@ -78,6 +78,12 @@ def py_repositories(transition_settings = []): strip_prefix = "toml.bzl-0.4.0", url = "https://github.com/jvolkman/toml.bzl/releases/download/v0.4.0/toml.bzl-v0.4.0.tar.gz", ) + http_archive( + name = "pypackaging.bzl", + sha256 = "09570564367dfbff313950528376c9ba9ded9025cacb2c731545db19bc27e1e9", + strip_prefix = "pypackaging.bzl-0.3.0", + url = "https://github.com/jvolkman/pypackaging.bzl/releases/download/v0.3.0/pypackaging.bzl-v0.3.0.tar.gz", + ) http_archive( name = "package_metadata", sha256 = "755bd6c8a3751982e2555d96c913ec070954ca9d01f935563392255da4ebad72", diff --git a/sphinxdocs/downloader_config.cfg b/sphinxdocs/downloader_config.cfg index 8bde140608..d445f15ff1 100644 --- a/sphinxdocs/downloader_config.cfg +++ b/sphinxdocs/downloader_config.cfg @@ -20,6 +20,7 @@ rewrite ^github\.com/bazelbuild/rules_swift/(.*) github.com/bazelbuild/rules_swi rewrite ^github\.com/bazelbuild/rules_testing/(.*) github.com/bazelbuild/rules_testing/$1 rewrite ^github\.com/bazelbuild/stardoc/(.*) github.com/bazelbuild/stardoc/$1 rewrite ^github\.com/google/googletest/(.*) github.com/google/googletest/$1 +rewrite ^github\.com/jvolkman/pypackaging\.bzl/(.*) github.com/jvolkman/pypackaging.bzl/$1 rewrite ^github\.com/jvolkman/toml\.bzl/(.*) github.com/jvolkman/toml.bzl/$1 rewrite ^github\.com/protocolbuffers/protobuf/(.*) github.com/protocolbuffers/protobuf/$1 # keep-sorted end @@ -48,6 +49,7 @@ rewrite ^github\.com/bazelbuild/rules_swift/(.*) mirror.bazel.build/github.com/b rewrite ^github\.com/bazelbuild/rules_testing/(.*) mirror.bazel.build/github.com/bazelbuild/rules_testing/$1 rewrite ^github\.com/bazelbuild/stardoc/(.*) mirror.bazel.build/github.com/bazelbuild/stardoc/$1 rewrite ^github\.com/google/googletest/(.*) mirror.bazel.build/github.com/google/googletest/$1 +rewrite ^github\.com/jvolkman/pypackaging\.bzl/(.*) mirror.bazel.build/github.com/jvolkman/pypackaging.bzl/$1 rewrite ^github\.com/jvolkman/toml\.bzl/(.*) mirror.bazel.build/github.com/jvolkman/toml.bzl/$1 rewrite ^github\.com/protocolbuffers/protobuf/(.*) mirror.bazel.build/github.com/protocolbuffers/protobuf/$1 # keep-sorted end From 918e6c6542cce6dfea086994fce5299cac505a5f Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Sun, 22 Nov 2026 02:28:02 +0900 Subject: [PATCH 2/3] tests: update the lockfile of the bzlmod_lockfile integration test --- tests/integration/bzlmod_lockfile/MODULE.bazel.lock | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/integration/bzlmod_lockfile/MODULE.bazel.lock b/tests/integration/bzlmod_lockfile/MODULE.bazel.lock index 2f3c632adb..996ddea575 100644 --- a/tests/integration/bzlmod_lockfile/MODULE.bazel.lock +++ b/tests/integration/bzlmod_lockfile/MODULE.bazel.lock @@ -93,6 +93,8 @@ "https://bcr.bazel.build/modules/pybind11_bazel/2.11.1/MODULE.bazel": "88af1c246226d87e65be78ed49ecd1e6f5e98648558c14ce99176da041dc378e", "https://bcr.bazel.build/modules/pybind11_bazel/2.12.0/MODULE.bazel": "e6f4c20442eaa7c90d7190d8dc539d0ab422f95c65a57cc59562170c58ae3d34", "https://bcr.bazel.build/modules/pybind11_bazel/2.12.0/source.json": "6900fdc8a9e95866b8c0d4ad4aba4d4236317b5c1cd04c502df3f0d33afed680", + "https://bcr.bazel.build/modules/pypackaging.bzl/0.3.0/MODULE.bazel": "30595bbd1169866ae6adbf4c91ab5fb40420dae63311c6e76695c1ddc8d0aec5", + "https://bcr.bazel.build/modules/pypackaging.bzl/0.3.0/source.json": "e84b643d154160c405139d59d92577e8864150620532397cf9eb6ee59165c534", "https://bcr.bazel.build/modules/re2/2023-09-01/MODULE.bazel": "cb3d511531b16cfc78a225a9e2136007a48cf8a677e4264baeab57fe78a80206", "https://bcr.bazel.build/modules/re2/2024-07-02.bcr.1/MODULE.bazel": "b4963dda9b31080be1905ef085ecd7dd6cd47c05c79b9cdf83ade83ab2ab271a", "https://bcr.bazel.build/modules/re2/2024-07-02.bcr.1/source.json": "2ff292be6ef3340325ce8a045ecc326e92cbfab47c7cbab4bd85d28971b97ac4", From 910bc285896b55fa66d844a2e12fb520009ebe10 Mon Sep 17 00:00:00 2001 From: Ignas Anikevicius <240938+aignas@users.noreply.github.com> Date: Sun, 22 Nov 2026 13:08:18 +0900 Subject: [PATCH 3/3] build: use pypackaging.bzl 0.4.0 It is aligned with packaging 26.3, is faster and officially supports WORKSPACE with Bazel 7 and 8. --- MODULE.bazel | 2 +- python/private/py_repositories.bzl | 6 +++--- tests/integration/bzlmod_lockfile/MODULE.bazel.lock | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 45e18a03f4..2fea2d486c 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -8,7 +8,7 @@ bazel_dep(name = "bazel_features", version = "1.55.0") bazel_dep(name = "bazel_skylib", version = "1.8.2") bazel_dep(name = "package_metadata", version = "0.0.13") bazel_dep(name = "platforms", version = "0.0.11") -bazel_dep(name = "pypackaging.bzl", version = "0.3.0") +bazel_dep(name = "pypackaging.bzl", version = "0.4.0") bazel_dep(name = "rules_cc", version = "0.2.17") bazel_dep(name = "toml.bzl", version = "0.4.1") diff --git a/python/private/py_repositories.bzl b/python/private/py_repositories.bzl index f92152a3e6..5eeaf4415f 100644 --- a/python/private/py_repositories.bzl +++ b/python/private/py_repositories.bzl @@ -80,9 +80,9 @@ def py_repositories(transition_settings = []): ) http_archive( name = "pypackaging.bzl", - sha256 = "09570564367dfbff313950528376c9ba9ded9025cacb2c731545db19bc27e1e9", - strip_prefix = "pypackaging.bzl-0.3.0", - url = "https://github.com/jvolkman/pypackaging.bzl/releases/download/v0.3.0/pypackaging.bzl-v0.3.0.tar.gz", + sha256 = "d234430a5425e8b090c0071944036516a3516b41f9c9d005113fff0533f591b3", + strip_prefix = "pypackaging.bzl-0.4.0", + url = "https://github.com/jvolkman/pypackaging.bzl/releases/download/v0.4.0/pypackaging.bzl-v0.4.0.tar.gz", ) http_archive( name = "package_metadata", diff --git a/tests/integration/bzlmod_lockfile/MODULE.bazel.lock b/tests/integration/bzlmod_lockfile/MODULE.bazel.lock index 996ddea575..37e0f8cb6c 100644 --- a/tests/integration/bzlmod_lockfile/MODULE.bazel.lock +++ b/tests/integration/bzlmod_lockfile/MODULE.bazel.lock @@ -93,8 +93,8 @@ "https://bcr.bazel.build/modules/pybind11_bazel/2.11.1/MODULE.bazel": "88af1c246226d87e65be78ed49ecd1e6f5e98648558c14ce99176da041dc378e", "https://bcr.bazel.build/modules/pybind11_bazel/2.12.0/MODULE.bazel": "e6f4c20442eaa7c90d7190d8dc539d0ab422f95c65a57cc59562170c58ae3d34", "https://bcr.bazel.build/modules/pybind11_bazel/2.12.0/source.json": "6900fdc8a9e95866b8c0d4ad4aba4d4236317b5c1cd04c502df3f0d33afed680", - "https://bcr.bazel.build/modules/pypackaging.bzl/0.3.0/MODULE.bazel": "30595bbd1169866ae6adbf4c91ab5fb40420dae63311c6e76695c1ddc8d0aec5", - "https://bcr.bazel.build/modules/pypackaging.bzl/0.3.0/source.json": "e84b643d154160c405139d59d92577e8864150620532397cf9eb6ee59165c534", + "https://bcr.bazel.build/modules/pypackaging.bzl/0.4.0/MODULE.bazel": "5fd3c92b01d18cb6ac6fb9581b633d75e094c63b5673935b26182439a6e30a5e", + "https://bcr.bazel.build/modules/pypackaging.bzl/0.4.0/source.json": "3d3aaa5de7e63fb1ab9953a60ddf7ade2183947003d37c1d5cc861b4f3278c5d", "https://bcr.bazel.build/modules/re2/2023-09-01/MODULE.bazel": "cb3d511531b16cfc78a225a9e2136007a48cf8a677e4264baeab57fe78a80206", "https://bcr.bazel.build/modules/re2/2024-07-02.bcr.1/MODULE.bazel": "b4963dda9b31080be1905ef085ecd7dd6cd47c05c79b9cdf83ade83ab2ab271a", "https://bcr.bazel.build/modules/re2/2024-07-02.bcr.1/source.json": "2ff292be6ef3340325ce8a045ecc326e92cbfab47c7cbab4bd85d28971b97ac4",