From 572391756293cd52a5a7ed78f10527435f46c002 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Fri, 26 Jun 2026 16:51:57 +0000 Subject: [PATCH 01/36] Migrate rules_python to use bazel-skylib's Gazelle integration for managing bzl_library targets to automate dependency tracking and ensure Starlark API consistency. This is achieved by integrating the Gazelle plugin, applying custom patches to resolve complex name clashes and external repository overrides, and manually migrating the sphinxdocs submodule. --- BUILD.bazel | 62 +- MODULE.bazel | 8 + docs/BUILD.bazel | 102 +- examples/pip_parse_vendored/BUILD.bazel | 9 +- examples/wheel/private/BUILD.bazel | 7 + gazelle/BUILD.bazel | 24 + gazelle/manifest/BUILD.bazel | 16 +- gazelle/manifest/generate/BUILD.bazel | 2 +- gazelle/modules_mapping/BUILD.bazel | 7 + gazelle/python/BUILD.bazel | 38 +- gazelle/python/private/BUILD.bazel | 8 + gazelle/pythonconfig/BUILD.bazel | 6 +- news/gazelle-bzl-library.changed.md | 4 + patches/BUILD.bazel | 1 + patches/bazel_skylib_gazelle_plugin.patch | 85 ++ python/BUILD.bazel | 463 ++++--- python/api/BUILD.bazel | 39 +- python/cc/BUILD.bazel | 20 +- python/config_settings/BUILD.bazel | 19 + python/config_settings/private/BUILD.bazel | 8 + python/entry_points/BUILD.bazel | 16 +- python/extensions/BUILD.bazel | 31 +- python/features.bzl | 26 + python/local_toolchains/BUILD.bazel | 17 +- python/pip_install/BUILD.bazel | 40 +- python/private/BUILD.bazel | 1107 +++++++++-------- python/private/api/BUILD.bazel | 17 +- python/private/api/api.bzl | 2 +- python/private/common/BUILD.bazel | 25 + python/private/internal_config_repo.bzl | 14 +- python/private/pypi/BUILD.bazel | 529 ++++---- python/private/pythons_hub.bzl | 20 +- python/private/whl_filegroup/BUILD.bazel | 12 +- python/private/zipapp/BUILD.bazel | 37 +- python/uv/BUILD.bazel | 24 +- python/uv/private/BUILD.bazel | 74 +- python/zipapp/BUILD.bazel | 12 +- sphinxdocs/docs/BUILD.bazel | 10 +- sphinxdocs/sphinxdocs/BUILD.bazel | 42 +- sphinxdocs/sphinxdocs/private/BUILD.bazel | 36 +- .../sphinxdocs/private/sphinx_stardoc.bzl | 4 +- sphinxdocs/tests/sphinx_stardoc/BUILD.bazel | 30 +- tests/BUILD.bazel | 37 +- tests/base_rules/BUILD.bazel | 9 + tests/entry_points/BUILD.bazel | 9 + .../integration/local_toolchains/BUILD.bazel | 19 + .../py_cc_toolchain_registered/BUILD.bazel | 8 + tests/integration/uv_lock/BUILD.bazel | 7 + tests/load_from_macro/BUILD.bazel | 8 + tests/pypi/extension/BUILD.bazel | 8 + tests/pypi/integration/BUILD.bazel | 7 + tests/pypi/whl_library/testdata/BUILD.bazel | 7 + tests/python_bzlmod_ext/BUILD.bazel | 12 + tests/support/BUILD.bazel | 66 + tests/support/cc_toolchains/BUILD.bazel | 11 + tests/support/mocks/BUILD.bazel | 14 +- tests/support/platforms/BUILD.bazel | 7 + tests/support/whl_from_dir/BUILD.bazel | 8 + tests/toolchains/BUILD.bazel | 19 + tools/build_defs/python/private/BUILD.bazel | 8 +- tools/private/BUILD.bazel | 8 + tools/private/update_deps/BUILD.bazel | 4 +- 62 files changed, 2042 insertions(+), 1287 deletions(-) create mode 100644 news/gazelle-bzl-library.changed.md create mode 100644 patches/BUILD.bazel create mode 100644 patches/bazel_skylib_gazelle_plugin.patch create mode 100644 python/private/common/BUILD.bazel diff --git a/BUILD.bazel b/BUILD.bazel index 7da18ebaa4..b886945dd5 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -12,8 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. +load("@bazel_gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary") load("@bazel_skylib//:bzl_library.bzl", "bzl_library") +# gazelle:resolve starlark @rules_cc//cc/common:cc_info.bzl @rules_cc//cc/common:common +# gazelle:resolve starlark @rules_cc//cc/common:cc_common.bzl @rules_cc//cc/common:common +# gazelle:resolve starlark @com_google_protobuf//bazel:py_proto_library.bzl @com_google_protobuf//bazel:py_proto_library_bzl +# 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 + package(default_visibility = ["//visibility:public"]) licenses(["notice"]) @@ -52,12 +59,6 @@ filegroup( ], ) -bzl_library( - name = "version_bzl", - srcs = ["version.bzl"], - visibility = ["//:__subpackages__"], -) - # Reexport of all bzl files used to allow downstream rules to generate docs # without shipping with a dependency on Skylib filegroup( @@ -73,3 +74,52 @@ filegroup( ], visibility = ["//visibility:public"], ) + +gazelle_binary( + name = "gazelle_bin", + languages = DEFAULT_LANGUAGES + [ + "@bazel_skylib_gazelle_plugin//bzl", + ], +) + +gazelle( + name = "gazelle", + gazelle = ":gazelle_bin", +) + +bzl_library( + name = "internal_dev_deps", + srcs = ["internal_dev_deps.bzl"], + deps = [ + "//python/private:internal_config_repo", + "@bazel_tools//tools/build_defs/repo:http.bzl", + "@bazel_tools//tools/build_defs/repo:local.bzl", + "@bazel_tools//tools/build_defs/repo:utils.bzl", + ], +) + +bzl_library( + name = "internal_dev_setup", + srcs = ["internal_dev_setup.bzl"], + deps = [ + ":version", + "//python:versions", + "//python/private:pythons_hub", + "//python/private:runtime_env_repo", + "//python/private/pypi:deps", + "//python/private/pypi:whl_library", + "//tests/support/whl_from_dir:whl_from_dir_repo", + "@bazel_features//:deps", + "@bazel_skylib//:workspace", + "@cgrindel_bazel_starlib//:deps", + "@com_google_protobuf//:protobuf_deps", + "@rules_bazel_integration_test//bazel_integration_test:deps", + "@rules_bazel_integration_test//bazel_integration_test:repo_defs", + "@rules_shell//shell:repositories", + ], +) + +bzl_library( + name = "version", + srcs = ["version.bzl"], +) diff --git a/MODULE.bazel b/MODULE.bazel index ab1c41bc09..a43ed22d0c 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -95,6 +95,8 @@ bazel_dep(name = "another_module", version = "0", dev_dependency = True) # Extra gazelle plugin deps so that WORKSPACE.bzlmod can continue including it for e2e tests. # We use `WORKSPACE.bzlmod` because it is impossible to have dev-only local overrides. bazel_dep(name = "rules_go", version = "0.60.0", dev_dependency = True, repo_name = "io_bazel_rules_go") +bazel_dep(name = "gazelle", version = "0.40.0", dev_dependency = True, repo_name = "bazel_gazelle") +bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.8.2", dev_dependency = True) internal_dev_deps = use_extension( "//python/private:internal_dev_deps.bzl", @@ -343,3 +345,9 @@ uv_dev.configure( # name = "experimental_python_import_all_repositories", # starlark_flag = "//python/config_settings:experimental_python_import_all_repositories", # ) + +single_version_override( + module_name = "bazel_skylib_gazelle_plugin", + patch_strip = 1, + patches = ["//patches:bazel_skylib_gazelle_plugin.patch"], +) diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel index 67f21b253b..19e796ca6e 100644 --- a/docs/BUILD.bazel +++ b/docs/BUILD.bazel @@ -84,58 +84,58 @@ build_test( sphinx_stardocs( name = "bzl_api_docs", srcs = [ - "//python:defs_bzl", - "//python:features_bzl", - "//python:packaging_bzl", - "//python:pip_bzl", - "//python:proto_bzl", - "//python:py_binary_bzl", - "//python:py_cc_link_params_info_bzl", - "//python:py_exec_tools_info_bzl", - "//python:py_exec_tools_toolchain_bzl", - "//python:py_executable_info_bzl", - "//python:py_library_bzl", - "//python:py_runtime_bzl", - "//python:py_runtime_info_bzl", - "//python:py_test_bzl", - "//python:repositories_bzl", - "//python/api:api_bzl", - "//python/api:attr_builders_bzl", - "//python/api:executables_bzl", - "//python/api:libraries_bzl", - "//python/api:rule_builders_bzl", - "//python/cc:py_cc_toolchain_bzl", - "//python/cc:py_cc_toolchain_info_bzl", - "//python/entry_points:py_console_script_binary_bzl", - "//python/extensions:config_bzl", - "//python/extensions:python_bzl", - "//python/local_toolchains:repos_bzl", - "//python/private:attr_builders_bzl", - "//python/private:builders_bzl", - "//python/private:builders_util_bzl", - "//python/private:py_binary_rule_bzl", - "//python/private:py_cc_toolchain_rule_bzl", - "//python/private:py_info_bzl", - "//python/private:py_library_rule_bzl", - "//python/private:py_runtime_rule_bzl", - "//python/private:py_test_rule_bzl", - "//python/private:rule_builders_bzl", - "//python/private/api:py_common_api_bzl", - "//python/private/pypi:config_settings_bzl", - "//python/private/pypi:env_marker_info_bzl", - "//python/private/pypi:pkg_aliases_bzl", - "//python/private/pypi:whl_config_setting_bzl", - "//python/private/pypi:whl_library_bzl", - "//python/private/zipapp:py_zipapp_rule_bzl", - "//python/uv:lock_bzl", - "//python/uv:uv_bzl", - "//python/uv:uv_toolchain_bzl", - "//python/uv:uv_toolchain_info_bzl", - "//python/zipapp:py_zipapp_binary_bzl", - "//python/zipapp:py_zipapp_test_bzl", + "//python:defs", + "//python:features", + "//python:packaging", + "//python:pip", + "//python:proto", + "//python:py_binary", + "//python:py_cc_link_params_info", + "//python:py_exec_tools_info", + "//python:py_exec_tools_toolchain", + "//python:py_executable_info", + "//python:py_library", + "//python:py_runtime", + "//python:py_runtime_info", + "//python:py_test", + "//python:repositories", + "//python/api", + "//python/api:attr_builders", + "//python/api:executables", + "//python/api:libraries", + "//python/api:rule_builders", + "//python/cc:py_cc_toolchain", + "//python/cc:py_cc_toolchain_info", + "//python/entry_points:py_console_script_binary", + "//python/extensions:config", + "//python/extensions:python", + "//python/local_toolchains:repos", + "//python/private:attr_builders", + "//python/private:builders", + "//python/private:builders_util", + "//python/private:py_binary_rule", + "//python/private:py_cc_toolchain_rule", + "//python/private:py_info", + "//python/private:py_library_rule", + "//python/private:py_runtime_rule", + "//python/private:py_test_rule", + "//python/private:rule_builders", + "//python/private/api:py_common_api", + "//python/private/pypi:config_settings", + "//python/private/pypi:env_marker_info", + "//python/private/pypi:pkg_aliases", + "//python/private/pypi:whl_config_setting", + "//python/private/pypi:whl_library", + "//python/private/zipapp:py_zipapp_rule", + "//python/uv", + "//python/uv:lock", + "//python/uv:uv_toolchain", + "//python/uv:uv_toolchain_info", + "//python/zipapp:py_zipapp_binary", + "//python/zipapp:py_zipapp_test", ] + ([ # This depends on @pythons_hub, which is only created under bzlmod, - "//python/extensions:pip_bzl", + "//python/extensions:pip", ] if BZLMOD_ENABLED else []), prefix = "api/rules_python/", tags = ["docs"], @@ -144,7 +144,7 @@ sphinx_stardocs( sphinx_stardoc( name = "py_runtime_pair", - src = "//python/private:py_runtime_pair_rule_bzl", + src = "//python/private:py_runtime_pair_rule", prefix = "api/rules_python/", tags = ["docs"], target_compatible_with = _TARGET_COMPATIBLE_WITH, diff --git a/examples/pip_parse_vendored/BUILD.bazel b/examples/pip_parse_vendored/BUILD.bazel index 74b9286359..7e39983b93 100644 --- a/examples/pip_parse_vendored/BUILD.bazel +++ b/examples/pip_parse_vendored/BUILD.bazel @@ -1,3 +1,4 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@bazel_skylib//rules:build_test.bzl", "build_test") load("@bazel_skylib//rules:diff_test.bzl", "diff_test") load("@bazel_skylib//rules:write_file.bzl", "write_file") @@ -51,7 +52,7 @@ write_file( sh_binary( name = "vendor_requirements", srcs = ["update.sh"], - data = [":requirement_bzl"], + data = [":requirement"], ) # Similarly ensures that the requirements.bzl file is updated @@ -75,3 +76,9 @@ build_test( name = "test_requirement_lists", targets = all_requirements + all_whl_requirements + all_data_requirements, ) + +bzl_library( + name = "requirements.clean", + srcs = ["requirements.clean.bzl"], + visibility = ["//visibility:public"], +) diff --git a/examples/wheel/private/BUILD.bazel b/examples/wheel/private/BUILD.bazel index 326fc3538c..d8401addf8 100644 --- a/examples/wheel/private/BUILD.bazel +++ b/examples/wheel/private/BUILD.bazel @@ -1,3 +1,4 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@rules_python//python:py_binary.bzl", "py_binary") py_binary( @@ -5,3 +6,9 @@ py_binary( srcs = ["directory_writer.py"], visibility = ["//:__subpackages__"], ) + +bzl_library( + name = "wheel_utils", + srcs = ["wheel_utils.bzl"], + visibility = ["//examples/wheel:__subpackages__"], +) diff --git a/gazelle/BUILD.bazel b/gazelle/BUILD.bazel index 0938be3dfc..f7ae54eca4 100644 --- a/gazelle/BUILD.bazel +++ b/gazelle/BUILD.bazel @@ -1,4 +1,5 @@ load("@bazel_gazelle//:def.bzl", "gazelle") +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") # Gazelle configuration options. # See https://github.com/bazelbuild/bazel-gazelle#running-gazelle-with-bazel @@ -36,3 +37,26 @@ filegroup( ], visibility = ["@rules_python//:__pkg__"], ) + +bzl_library( + name = "deps", + srcs = ["deps.bzl"], + visibility = ["//visibility:public"], + deps = [ + "@bazel_gazelle//:deps", + "@bazel_tools//tools/build_defs/repo:http.bzl", + ], +) + +bzl_library( + name = "internal_dev_deps", + srcs = ["internal_dev_deps.bzl"], + visibility = ["//visibility:public"], + deps = ["@bazel_tools//tools/build_defs/repo:http.bzl"], +) + +bzl_library( + name = "def", + srcs = ["def.bzl"], + visibility = ["//visibility:public"], +) diff --git a/gazelle/manifest/BUILD.bazel b/gazelle/manifest/BUILD.bazel index ea81d85fbe..f9c64d73d6 100644 --- a/gazelle/manifest/BUILD.bazel +++ b/gazelle/manifest/BUILD.bazel @@ -1,3 +1,4 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") exports_files([ @@ -11,8 +12,8 @@ go_library( importpath = "github.com/bazel-contrib/rules_python/gazelle/manifest", visibility = ["//visibility:public"], deps = [ - "@com_github_emirpasic_gods//sets/treeset", - "@in_gopkg_yaml_v2//:yaml_v2", + "@com_github_emirpasic_gods//sets/treeset:go_default_library", + "@in_gopkg_yaml_v2//:go_default_library", ], ) @@ -32,3 +33,14 @@ filegroup( ], visibility = ["//:__pkg__"], ) + +bzl_library( + name = "defs", + srcs = ["defs.bzl"], + visibility = ["//visibility:public"], + deps = [ + "@bazel_skylib//rules:diff_test", + "@io_bazel_rules_go//go:def", + "@rules_python//python:defs", + ], +) diff --git a/gazelle/manifest/generate/BUILD.bazel b/gazelle/manifest/generate/BUILD.bazel index 77d2467cef..906d4bf06b 100644 --- a/gazelle/manifest/generate/BUILD.bazel +++ b/gazelle/manifest/generate/BUILD.bazel @@ -6,7 +6,7 @@ go_library( srcs = ["generate.go"], importpath = "github.com/bazel-contrib/rules_python/gazelle/manifest/generate", visibility = ["//visibility:public"], - deps = ["//manifest"], + deps = ["//gazelle/manifest"], ) sources_hash( diff --git a/gazelle/modules_mapping/BUILD.bazel b/gazelle/modules_mapping/BUILD.bazel index 3423f34e51..0e740f2636 100644 --- a/gazelle/modules_mapping/BUILD.bazel +++ b/gazelle/modules_mapping/BUILD.bazel @@ -1,3 +1,4 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@bazel_skylib//rules:copy_file.bzl", "copy_file") load("@rules_python//python:defs.bzl", "py_binary", "py_test") @@ -56,3 +57,9 @@ filegroup( srcs = glob(["**"]), visibility = ["//:__pkg__"], ) + +bzl_library( + name = "def", + srcs = ["def.bzl"], + visibility = ["//visibility:public"], +) diff --git a/gazelle/python/BUILD.bazel b/gazelle/python/BUILD.bazel index b988e493c7..a98eddb83c 100644 --- a/gazelle/python/BUILD.bazel +++ b/gazelle/python/BUILD.bazel @@ -1,4 +1,5 @@ load("@bazel_gazelle//:def.bzl", "gazelle_binary") +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@bazel_skylib//rules:copy_file.bzl", "copy_file") load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") load(":gazelle_test.bzl", "gazelle_test") @@ -29,20 +30,20 @@ go_library( importpath = "github.com/bazel-contrib/rules_python/gazelle/python", visibility = ["//visibility:public"], deps = [ - "//pythonconfig", - "@bazel_gazelle//config:go_default_library", - "@bazel_gazelle//label:go_default_library", - "@bazel_gazelle//language:go_default_library", - "@bazel_gazelle//repo:go_default_library", - "@bazel_gazelle//resolve:go_default_library", - "@bazel_gazelle//rule:go_default_library", + "//gazelle/pythonconfig", + "@bazel_gazelle//config", + "@bazel_gazelle//label", + "@bazel_gazelle//language", + "@bazel_gazelle//repo", + "@bazel_gazelle//resolve", + "@bazel_gazelle//rule", "@com_github_bazelbuild_buildtools//build", "@com_github_bmatcuk_doublestar_v4//:doublestar", - "@com_github_emirpasic_gods//lists/singlylinkedlist", - "@com_github_emirpasic_gods//sets/treeset", - "@com_github_emirpasic_gods//utils", - "@com_github_smacker_go_tree_sitter//:go-tree-sitter", - "@com_github_smacker_go_tree_sitter//python", + "@com_github_emirpasic_gods//lists/singlylinkedlist:go_default_library", + "@com_github_emirpasic_gods//sets/treeset:go_default_library", + "@com_github_emirpasic_gods//utils:go_default_library", + "@com_github_smacker_go_tree_sitter//:go_default_library", + "@com_github_smacker_go_tree_sitter//python:go_default_library", "@org_golang_x_sync//errgroup", ], ) @@ -122,3 +123,16 @@ go_test( "@com_github_stretchr_testify//assert", ], ) + +bzl_library( + name = "gazelle_test", + srcs = ["gazelle_test.bzl"], + visibility = ["//visibility:public"], + deps = ["@io_bazel_rules_go//go:def"], +) + +bzl_library( + name = "extensions", + srcs = ["extensions.bzl"], + visibility = ["//visibility:public"], +) diff --git a/gazelle/python/private/BUILD.bazel b/gazelle/python/private/BUILD.bazel index e69de29bb2..61644f6272 100644 --- a/gazelle/python/private/BUILD.bazel +++ b/gazelle/python/private/BUILD.bazel @@ -0,0 +1,8 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + +bzl_library( + name = "extensions", + srcs = ["extensions.bzl"], + visibility = ["//gazelle/python:__subpackages__"], + deps = ["@bazel_skylib//lib:modules"], +) diff --git a/gazelle/pythonconfig/BUILD.bazel b/gazelle/pythonconfig/BUILD.bazel index 711bf2eb42..567252d606 100644 --- a/gazelle/pythonconfig/BUILD.bazel +++ b/gazelle/pythonconfig/BUILD.bazel @@ -9,9 +9,9 @@ go_library( importpath = "github.com/bazel-contrib/rules_python/gazelle/pythonconfig", visibility = ["//visibility:public"], deps = [ - "//manifest", - "@bazel_gazelle//label:go_default_library", - "@com_github_emirpasic_gods//lists/singlylinkedlist", + "//gazelle/manifest", + "@bazel_gazelle//label", + "@com_github_emirpasic_gods//lists/singlylinkedlist:go_default_library", ], ) diff --git a/news/gazelle-bzl-library.changed.md b/news/gazelle-bzl-library.changed.md new file mode 100644 index 0000000000..08b64ec124 --- /dev/null +++ b/news/gazelle-bzl-library.changed.md @@ -0,0 +1,4 @@ +(bzl_library) Migrated `bzl_library` targets to be managed by Gazelle using the +`bazel-skylib` Gazelle plugin. Public targets have been renamed to match their +file names (without the `_bzl` suffix), and deprecated aliases have been +created for backwards compatibility. diff --git a/patches/BUILD.bazel b/patches/BUILD.bazel new file mode 100644 index 0000000000..9ffe771b28 --- /dev/null +++ b/patches/BUILD.bazel @@ -0,0 +1 @@ +# Package marker for patches. diff --git a/patches/bazel_skylib_gazelle_plugin.patch b/patches/bazel_skylib_gazelle_plugin.patch new file mode 100644 index 0000000000..f51a636c40 --- /dev/null +++ b/patches/bazel_skylib_gazelle_plugin.patch @@ -0,0 +1,85 @@ +--- a/bzl/gazelle.go ++++ b/bzl/gazelle.go +@@ -160,13 +160,26 @@ + // the index only contains absolute labels, not relative + impLabel = impLabel.Abs(from.Repo, from.Pkg) + +- if impLabel.Repo == "bazel_tools" { +- // The @bazel_tools repo is tricky because it is a part of the "shipped +- // with bazel" core library for interacting with the outside world. +- // This means that it can not depend on skylib. Fortunately there is a +- // fairly simple workaround for this, which is that you can add those +- // bzl files as `deps` entries. +- deps = append(deps, imp) ++ log.Printf("JETSKI_DEBUG: imp=%q, impLabel.Abs()=%s", imp, impLabel.String()) ++ res := resolve.ImportSpec{ ++ Lang: languageName, ++ Imp: impLabel.String(), ++ } ++ depLabel, ok := resolve.FindRuleWithOverride(c, res, languageName) ++ log.Printf("JETSKI_DEBUG: FindRuleWithOverride(%q) -> label=%s, ok=%t", res.Imp, depLabel.String(), ok) ++ if ok { ++ depLabel = depLabel.Rel(from.Repo, from.Pkg) ++ deps = append(deps, depLabel.String()) ++ continue ++ } ++ ++ matches := ix.FindRulesByImportWithConfig(c, res, languageName) ++ if len(matches) > 0 { ++ for _, m := range matches { ++ depLabel := m.Label ++ depLabel = depLabel.Rel(from.Repo, from.Pkg) ++ deps = append(deps, depLabel.String()) ++ } + continue + } + +@@ -177,23 +190,11 @@ + continue + } + +- res := resolve.ImportSpec{ +- Lang: languageName, +- Imp: impLabel.String(), +- } +- matches := ix.FindRulesByImportWithConfig(c, res, languageName) +- if len(matches) == 0 { +- log.Printf("%s: %q (%s) was not found in dependency index. Skipping. This may result in an incomplete deps section and require manual BUILD file intervention.\n", from.String(), imp, impLabel.String()) +- } +- +- for _, m := range matches { +- depLabel := m.Label +- depLabel = depLabel.Rel(from.Repo, from.Pkg) +- deps = append(deps, depLabel.String()) +- } ++ log.Printf("%s: %q (%s) was not found in dependency index. Skipping. This may result in an incomplete deps section and require manual BUILD file intervention.\n", from.String(), imp, impLabel.String()) + } + + sort.Strings(deps) ++ log.Printf("JETSKI_DEBUG: Rule %s (from %s) final deps: %v", r.Name(), from.String(), deps) + if len(deps) > 0 { + r.SetAttr("deps", deps) + } +@@ -223,7 +224,7 @@ + var rules []*rule.Rule + var imports []interface{} + for _, f := range append(args.RegularFiles, args.GenFiles...) { +- if !isBzlSourceFile(f) { ++ if !isBzlSourceFile(f, args.Rel) { + continue + } + name := strings.TrimSuffix(f, fileType) +@@ -278,8 +279,11 @@ + return loads, nil + } + +-func isBzlSourceFile(f string) bool { +- return strings.HasSuffix(f, fileType) && !ignoreSuffix.Matches(f) ++func isBzlSourceFile(f string, rel string) bool { ++ if rel == "tests" || strings.HasPrefix(rel, "tests/") { ++ return strings.HasSuffix(f, fileType) && !ignoreSuffix.Matches(f) ++ } ++ return strings.HasSuffix(f, fileType) + } + + // generateEmpty generates the list of rules that don't need to exist in the diff --git a/python/BUILD.bazel b/python/BUILD.bazel index e940e9e94b..013f527aa5 100644 --- a/python/BUILD.bazel +++ b/python/BUILD.bazel @@ -24,6 +24,9 @@ In an ideal renaming, we'd move the packaging rules to a different package so that @rules_python//python is only concerned with the core rules. """ +# gazelle:resolve starlark @rules_python//python:current_py_toolchain.bzl //python:current_py_toolchain_bzl +# gazelle:resolve starlark //python:current_py_toolchain.bzl //python:current_py_toolchain_bzl + load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load(":current_py_toolchain.bzl", "current_py_toolchain") @@ -54,184 +57,6 @@ filegroup( # ========= bzl_library targets end ========= -bzl_library( - name = "current_py_toolchain_bzl", - srcs = ["current_py_toolchain.bzl"], - deps = ["//python/private:toolchain_types_bzl"], -) - -bzl_library( - name = "defs_bzl", - srcs = [ - "defs.bzl", - ], - visibility = ["//visibility:public"], - deps = [ - ":current_py_toolchain_bzl", - ":py_binary_bzl", - ":py_import_bzl", - ":py_info_bzl", - ":py_library_bzl", - ":py_runtime_bzl", - ":py_runtime_info_bzl", - ":py_runtime_pair_bzl", - ":py_test_bzl", - ], -) - -bzl_library( - name = "features_bzl", - srcs = ["features.bzl"], -) - -bzl_library( - name = "packaging_bzl", - srcs = ["packaging.bzl"], - deps = [ - "//python/entry_points:py_console_script_binary_bzl", - "//python/private:bzlmod_enabled_bzl", - "//python/private:py_package_bzl", - "//python/private:py_wheel_bzl", - "//python/private:util_bzl", - "@bazel_skylib//rules:native_binary", - ], -) - -bzl_library( - name = "pip_bzl", - srcs = ["pip.bzl"], - deps = [ - "//python/private:normalize_name_bzl", - "//python/private/pypi:multi_pip_parse_bzl", - "//python/private/pypi:package_annotation_bzl", - "//python/private/pypi:pip_compile_bzl", - "//python/private/pypi:pip_repository_bzl", - "//python/private/pypi:whl_library_alias_bzl", - "//python/private/whl_filegroup:whl_filegroup_bzl", - ], -) - -bzl_library( - name = "proto_bzl", - srcs = [ - "proto.bzl", - ], - visibility = ["//visibility:public"], - deps = [ - "@com_google_protobuf//bazel:py_proto_library_bzl", - ], -) - -bzl_library( - name = "py_binary_bzl", - srcs = ["py_binary.bzl"], - deps = [ - "//python/private:py_binary_macro_bzl", - ], -) - -bzl_library( - name = "py_cc_link_params_info_bzl", - srcs = ["py_cc_link_params_info.bzl"], - deps = [ - "//python/private:py_cc_link_params_info_bzl", - ], -) - -bzl_library( - name = "py_exec_tools_info_bzl", - srcs = ["py_exec_tools_info.bzl"], - deps = ["//python/private:py_exec_tools_info_bzl"], -) - -bzl_library( - name = "py_exec_tools_toolchain_bzl", - srcs = ["py_exec_tools_toolchain.bzl"], - deps = ["//python/private:py_exec_tools_toolchain_bzl"], -) - -bzl_library( - name = "py_executable_info_bzl", - srcs = ["py_executable_info.bzl"], - deps = ["//python/private:py_executable_info_bzl"], -) - -bzl_library( - name = "py_import_bzl", - srcs = ["py_import.bzl"], - deps = [":py_info_bzl"], -) - -bzl_library( - name = "py_info_bzl", - srcs = ["py_info.bzl"], - deps = [ - "//python/private:py_info_bzl", - ], -) - -bzl_library( - name = "py_library_bzl", - srcs = ["py_library.bzl"], - deps = [ - "//python/private:py_library_macro_bzl", - ], -) - -bzl_library( - name = "py_runtime_bzl", - srcs = ["py_runtime.bzl"], - deps = [ - "//python/private:py_runtime_macro_bzl", - ], -) - -bzl_library( - name = "py_runtime_pair_bzl", - srcs = ["py_runtime_pair.bzl"], - deps = [ - "//python/private:py_runtime_pair_macro_bzl", - ], -) - -bzl_library( - name = "py_runtime_info_bzl", - srcs = ["py_runtime_info.bzl"], - deps = [ - "//python/private:py_runtime_info_bzl", - ], -) - -bzl_library( - name = "py_test_bzl", - srcs = ["py_test.bzl"], - deps = [ - "//python/private:py_test_macro_bzl", - ], -) - -bzl_library( - name = "repositories_bzl", - srcs = ["repositories.bzl"], - deps = [ - "//python/private:is_standalone_interpreter_bzl", - "//python/private:py_repositories_bzl", - "//python/private:python_register_multi_toolchains_bzl", - "//python/private:python_register_toolchains_bzl", - "//python/private:python_repository_bzl", - ], -) - -bzl_library( - name = "versions_bzl", - srcs = ["versions.bzl"], - visibility = ["//:__subpackages__"], - deps = [ - "//python/private:platform_info_bzl", - "//python/private:runtimes_manifest_workspace_bzl", - ], -) - # NOTE: Remember to add bzl_library targets to //tests:bzl_libraries # ========= bzl_library targets end ========= @@ -351,3 +176,285 @@ exports_files([ current_py_toolchain( name = "current_py_toolchain", ) + +# keep +bzl_library( + name = "current_py_toolchain_bzl", + srcs = ["current_py_toolchain.bzl"], + visibility = ["//visibility:public"], +) + +bzl_library( + name = "packaging", + srcs = ["packaging.bzl"], + deps = [ + ":py_binary", + "//python/private:bzlmod_enabled", + "//python/private:py_package", + "//python/private:py_wheel", + "//python/private:util", + "@bazel_skylib//rules:native_binary", + ], +) + +bzl_library( + name = "pip", + srcs = ["pip.bzl"], + deps = [ + "//python/private:normalize_name", + "//python/private/pypi:multi_pip_parse", + "//python/private/pypi:package_annotation", + "//python/private/pypi:pip_compile", + "//python/private/pypi:pip_repository", + "//python/private/pypi:whl_library_alias", + "//python/private/whl_filegroup", + ], +) + +bzl_library( + name = "proto", + srcs = ["proto.bzl"], + deps = ["@com_google_protobuf//bazel:py_proto_library_bzl"], +) + +bzl_library( + name = "py_binary", + srcs = ["py_binary.bzl"], + deps = ["//python/private:py_binary_macro"], +) + +bzl_library( + name = "py_cc_link_params_info", + srcs = ["py_cc_link_params_info.bzl"], + deps = ["//python/private:py_cc_link_params_info"], +) + +bzl_library( + name = "py_exec_tools_info", + srcs = ["py_exec_tools_info.bzl"], + deps = ["//python/private:py_exec_tools_info"], +) + +bzl_library( + name = "py_exec_tools_toolchain", + srcs = ["py_exec_tools_toolchain.bzl"], + deps = ["//python/private:py_exec_tools_toolchain"], +) + +bzl_library( + name = "py_executable_info", + srcs = ["py_executable_info.bzl"], + deps = ["//python/private:py_executable_info"], +) + +bzl_library( + name = "py_import", + srcs = ["py_import.bzl"], + deps = [":py_info"], +) + +bzl_library( + name = "py_info", + srcs = ["py_info.bzl"], + deps = ["//python/private:py_info"], +) + +bzl_library( + name = "py_library", + srcs = ["py_library.bzl"], + deps = ["//python/private:py_library_macro"], +) + +bzl_library( + name = "py_runtime", + srcs = ["py_runtime.bzl"], + deps = ["//python/private:py_runtime_macro"], +) + +bzl_library( + name = "py_runtime_info", + srcs = ["py_runtime_info.bzl"], + deps = ["//python/private:py_runtime_info"], +) + +bzl_library( + name = "py_runtime_pair", + srcs = ["py_runtime_pair.bzl"], + deps = ["//python/private:py_runtime_pair_macro"], +) + +bzl_library( + name = "py_test", + srcs = ["py_test.bzl"], + deps = ["//python/private:py_test_macro"], +) + +bzl_library( + name = "repositories", + srcs = ["repositories.bzl"], + deps = [ + "//python/private:is_standalone_interpreter", + "//python/private:py_repositories", + "//python/private:python_register_multi_toolchains", + "//python/private:python_register_toolchains", + "//python/private:python_repository", + ], +) + +bzl_library( + name = "versions", + srcs = ["versions.bzl"], + deps = [ + "//python/private:pbs_manifest", + "//python/private:platform_info", + "//python/private:runtimes_manifest_workspace", + ], +) + +# ========= Deprecated aliases for backwards compatibility ========= + +alias( + name = "defs_bzl", + actual = ":defs", + deprecation = "Use //python:defs instead", +) + +alias( + name = "packaging_bzl", + actual = ":packaging", + deprecation = "Use //python:packaging instead", +) + +alias( + name = "pip_bzl", + actual = ":pip", + deprecation = "Use //python:pip instead", +) + +alias( + name = "proto_bzl", + actual = ":proto", + deprecation = "Use //python:proto instead", +) + +alias( + name = "py_binary_bzl", + actual = ":py_binary", + deprecation = "Use //python:py_binary instead", +) + +alias( + name = "py_cc_link_params_info_bzl", + actual = ":py_cc_link_params_info", + deprecation = "Use //python:py_cc_link_params_info instead", +) + +alias( + name = "py_exec_tools_info_bzl", + actual = ":py_exec_tools_info", + deprecation = "Use //python:py_exec_tools_info instead", +) + +alias( + name = "py_exec_tools_toolchain_bzl", + actual = ":py_exec_tools_toolchain", + deprecation = "Use //python:py_exec_tools_toolchain instead", +) + +alias( + name = "py_executable_info_bzl", + actual = ":py_executable_info", + deprecation = "Use //python:py_executable_info instead", +) + +alias( + name = "py_import_bzl", + actual = ":py_import", + deprecation = "Use //python:py_import instead", +) + +alias( + name = "py_info_bzl", + actual = ":py_info", + deprecation = "Use //python:py_info instead", +) + +alias( + name = "py_library_bzl", + actual = ":py_library", + deprecation = "Use //python:py_library instead", +) + +alias( + name = "py_runtime_bzl", + actual = ":py_runtime", + deprecation = "Use //python:py_runtime instead", +) + +alias( + name = "py_runtime_info_bzl", + actual = ":py_runtime_info", + deprecation = "Use //python:py_runtime_info instead", +) + +alias( + name = "py_runtime_pair_bzl", + actual = ":py_runtime_pair", + deprecation = "Use //python:py_runtime_pair instead", +) + +alias( + name = "py_test_bzl", + actual = ":py_test", + deprecation = "Use //python:py_test instead", +) + +alias( + name = "repositories_bzl", + actual = ":repositories", + deprecation = "Use //python:repositories instead", +) + +alias( + name = "versions_bzl", + actual = ":versions", + deprecation = "Use //python:versions instead", +) + +alias( + name = "features_bzl", + actual = ":features", + deprecation = "Use //python:features instead", +) + +alias( + name = "python_bzl", + actual = ":python", + deprecation = "Use //python:python instead", +) + +bzl_library( + name = "defs", + srcs = ["defs.bzl"], + deps = [ + ":py_binary", + ":py_import", + ":py_info", + ":py_library", + ":py_runtime", + ":py_runtime_info", + ":py_runtime_pair", + ":py_test", + "//python:current_py_toolchain_bzl", + ], +) + +bzl_library( + name = "features", + srcs = ["features.bzl"], +) + +bzl_library( + name = "python", + srcs = ["python.bzl"], +) diff --git a/python/api/BUILD.bazel b/python/api/BUILD.bazel index 11fee103cb..93c70f4c8b 100644 --- a/python/api/BUILD.bazel +++ b/python/api/BUILD.bazel @@ -18,46 +18,41 @@ package( default_visibility = ["//:__subpackages__"], ) +filegroup( + name = "distribution", + srcs = glob(["**"]), +) + bzl_library( - name = "api_bzl", + name = "api", srcs = ["api.bzl"], - visibility = ["//visibility:public"], - deps = ["//python/private/api:api_bzl"], + deps = ["//python/private/api"], ) bzl_library( - name = "attr_builders_bzl", + name = "attr_builders", srcs = ["attr_builders.bzl"], - deps = ["//python/private:attr_builders_bzl"], + deps = ["//python/private:attr_builders"], ) bzl_library( - name = "executables_bzl", + name = "executables", srcs = ["executables.bzl"], - visibility = ["//visibility:public"], deps = [ - "//python/private:py_binary_rule_bzl", - "//python/private:py_executable_bzl", - "//python/private:py_test_rule_bzl", + "//python/private:py_binary_rule", + "//python/private:py_executable", + "//python/private:py_test_rule", ], ) bzl_library( - name = "libraries_bzl", + name = "libraries", srcs = ["libraries.bzl"], - visibility = ["//visibility:public"], - deps = [ - "//python/private:py_library_bzl", - ], + deps = ["//python/private:py_library"], ) bzl_library( - name = "rule_builders_bzl", + name = "rule_builders", srcs = ["rule_builders.bzl"], - deps = ["//python/private:rule_builders_bzl"], -) - -filegroup( - name = "distribution", - srcs = glob(["**"]), + deps = ["//python/private:rule_builders"], ) diff --git a/python/cc/BUILD.bazel b/python/cc/BUILD.bazel index f7686c41f6..2b3af42bcb 100644 --- a/python/cc/BUILD.bazel +++ b/python/cc/BUILD.bazel @@ -47,21 +47,19 @@ toolchain_type( visibility = ["//visibility:public"], ) +filegroup( + name = "distribution", + srcs = glob(["**"]), +) + bzl_library( - name = "py_cc_toolchain_bzl", + name = "py_cc_toolchain", srcs = ["py_cc_toolchain.bzl"], - visibility = ["//visibility:public"], - deps = ["//python/private:py_cc_toolchain_macro_bzl"], + deps = ["//python/private:py_cc_toolchain_macro"], ) bzl_library( - name = "py_cc_toolchain_info_bzl", + name = "py_cc_toolchain_info", srcs = ["py_cc_toolchain_info.bzl"], - visibility = ["//visibility:public"], - deps = ["//python/private:py_cc_toolchain_info_bzl"], -) - -filegroup( - name = "distribution", - srcs = glob(["**"]), + deps = ["//python/private:py_cc_toolchain_info"], ) diff --git a/python/config_settings/BUILD.bazel b/python/config_settings/BUILD.bazel index 5b1317872f..0dc54366af 100644 --- a/python/config_settings/BUILD.bazel +++ b/python/config_settings/BUILD.bazel @@ -1,3 +1,4 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag") load("@pythons_hub//:versions.bzl", "DEFAULT_PYTHON_VERSION", "MINOR_MAPPING", "PYTHON_VERSIONS") load("@rules_python_internal//:rules_python_config.bzl", "config") @@ -210,3 +211,21 @@ string_flag( scope = "universal", visibility = ["//visibility:public"], ) + +bzl_library( + name = "config_settings", + srcs = ["config_settings.bzl"], + visibility = ["//visibility:public"], + deps = ["//python/private:config_settings"], +) + +bzl_library( + name = "transition", + srcs = ["transition.bzl"], + visibility = ["//visibility:public"], + deps = [ + "//python:py_binary", + "//python/private:deprecation", + "//python/private:text_util", + ], +) diff --git a/python/config_settings/private/BUILD.bazel b/python/config_settings/private/BUILD.bazel index cb42e4999a..6b69ee8879 100644 --- a/python/config_settings/private/BUILD.bazel +++ b/python/config_settings/private/BUILD.bazel @@ -1,5 +1,13 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + filegroup( name = "distribution", srcs = glob(["**"]), visibility = ["//python/config_settings:__pkg__"], ) + +bzl_library( + name = "py_args", + srcs = ["py_args.bzl"], + visibility = ["//python/config_settings:__subpackages__"], +) diff --git a/python/entry_points/BUILD.bazel b/python/entry_points/BUILD.bazel index 46dbd9298b..182d8fa85c 100644 --- a/python/entry_points/BUILD.bazel +++ b/python/entry_points/BUILD.bazel @@ -21,17 +21,15 @@ exports_files( visibility = ["//docs:__subpackages__"], ) -bzl_library( - name = "py_console_script_binary_bzl", - srcs = [":py_console_script_binary.bzl"], - visibility = ["//visibility:public"], - deps = [ - "//python/private:py_console_script_binary_bzl", - ], -) - filegroup( name = "distribution", srcs = glob(["**"]), visibility = ["//python:__subpackages__"], ) + +bzl_library( + name = "py_console_script_binary", + srcs = ["py_console_script_binary.bzl"], + visibility = ["//visibility:public"], + deps = ["//python/private:py_console_script_binary"], +) diff --git a/python/extensions/BUILD.bazel b/python/extensions/BUILD.bazel index 50d2b3bbdf..c64ff7cc64 100644 --- a/python/extensions/BUILD.bazel +++ b/python/extensions/BUILD.bazel @@ -25,28 +25,23 @@ filegroup( ) bzl_library( - name = "pip_bzl", - srcs = ["pip.bzl"], - visibility = ["//:__subpackages__"], - deps = ["//python/private/pypi:pip_bzl"], + name = "config", + srcs = ["config.bzl"], + deps = [ + "//python/private:internal_config_repo", + "//python/private/pypi:deps", + "@bazel_features//:features", + ], ) bzl_library( - name = "python_bzl", - srcs = ["python.bzl"], - visibility = ["//:__subpackages__"], - deps = [ - "//python/private:python_bzl", - ], + name = "pip", + srcs = ["pip.bzl"], + deps = ["//python/private/pypi:pip"], ) bzl_library( - name = "config_bzl", - srcs = ["config.bzl"], - visibility = ["//:__subpackages__"], - deps = [ - "//python/private:internal_config_repo_bzl", - "//python/private/pypi:deps_bzl", - "@bazel_features//:features", - ], + name = "python", + srcs = ["python.bzl"], + deps = ["//python/private:python"], ) diff --git a/python/features.bzl b/python/features.bzl index a2cb95f1ee..85ce371ffb 100644 --- a/python/features.bzl +++ b/python/features.bzl @@ -87,7 +87,33 @@ _TARGETS = { "//command_line_option:build_runfile_links": True, "//command_line_option:enable_runfiles": True, "//command_line_option:extra_toolchains": True, + "//python/api:api": True, + "//python/api:executables": True, + "//python/api:libraries": True, "//python/cc:current_py_cc_headers_abi3": True, + "//python/cc:py_cc_toolchain": True, + "//python/cc:py_cc_toolchain_info": True, + "//python/entry_points:py_console_script_binary": True, + "//python/local_toolchains:repos": True, + "//python:defs": True, + "//python:features": True, + "//python:packaging": True, + "//python:pip": True, + "//python:proto": True, + "//python:py_binary": True, + "//python:py_cc_link_params_info": True, + "//python:py_exec_tools_info": True, + "//python:py_exec_tools_toolchain": True, + "//python:py_executable_info": True, + "//python:py_import": True, + "//python:py_info": True, + "//python:py_library": True, + "//python:py_runtime": True, + "//python:py_runtime_info": True, + "//python:py_runtime_pair": True, + "//python:py_test": True, + "//python:repositories": True, + "//python:versions": True, } features = struct( diff --git a/python/local_toolchains/BUILD.bazel b/python/local_toolchains/BUILD.bazel index 211f3e21a7..9ca71264fd 100644 --- a/python/local_toolchains/BUILD.bazel +++ b/python/local_toolchains/BUILD.bazel @@ -2,17 +2,16 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") package(default_visibility = ["//:__subpackages__"]) +filegroup( + name = "distribution", + srcs = glob(["**"]), +) + bzl_library( - name = "repos_bzl", + name = "repos", srcs = ["repos.bzl"], - visibility = ["//visibility:public"], deps = [ - "//python/private:local_runtime_repo_bzl", - "//python/private:local_runtime_toolchains_repo_bzl", + "@rules_python//python/private:local_runtime_repo", + "@rules_python//python/private:local_runtime_toolchains_repo", ], ) - -filegroup( - name = "distribution", - srcs = glob(["**"]), -) diff --git a/python/pip_install/BUILD.bazel b/python/pip_install/BUILD.bazel index 665375cc5b..b3c1ab1c03 100644 --- a/python/pip_install/BUILD.bazel +++ b/python/pip_install/BUILD.bazel @@ -18,23 +18,6 @@ package( default_visibility = ["//:__subpackages__"], ) -bzl_library( - name = "pip_repository_bzl", - srcs = ["pip_repository.bzl"], - deps = [ - "//python/private/pypi:package_annotation_bzl", - "//python/private/pypi:pip_repository_bzl", - "//python/private/pypi:whl_config_repo_bzl", - "//python/private/pypi:whl_library_bzl", - ], -) - -bzl_library( - name = "requirements_bzl", - srcs = ["requirements.bzl"], - deps = ["//python/private/pypi:pip_compile_bzl"], -) - filegroup( name = "distribution", srcs = glob(["**"]), @@ -51,3 +34,26 @@ exports_files( glob(["*.bzl"]), visibility = ["//docs:__pkg__"], ) + +bzl_library( + name = "pip_repository", + srcs = ["pip_repository.bzl"], + deps = [ + "//python/private/pypi:package_annotation", + "//python/private/pypi:pip_repository", + "//python/private/pypi:whl_config_repo", + "//python/private/pypi:whl_library", + ], +) + +bzl_library( + name = "requirements", + srcs = ["requirements.bzl"], + deps = ["//python/private/pypi:pip_compile"], +) + +bzl_library( + name = "requirements_parser", + srcs = ["requirements_parser.bzl"], + deps = ["//python/private/pypi:parse_requirements_txt"], +) diff --git a/python/private/BUILD.bazel b/python/private/BUILD.bazel index e4b38c2d1d..c74ff388e8 100644 --- a/python/private/BUILD.bazel +++ b/python/private/BUILD.bazel @@ -22,6 +22,12 @@ load(":sentinel.bzl", "sentinel") load(":stamp.bzl", "stamp_build_setting") load(":uncachable_version_file.bzl", "define_uncachable_version_file") +# gazelle:exclude sentinel.bzl +# gazelle:resolve starlark @rules_python//python/private:sentinel.bzl //python/private:sentinel_bzl +# gazelle:resolve starlark //python/private:sentinel.bzl //python/private:sentinel_bzl +# gazelle:resolve starlark @rules_python//python/private:stamp.bzl //python/private:stamp_bzl +# gazelle:resolve starlark //python/private:stamp.bzl //python/private:stamp_bzl + package( default_visibility = [ "//:__subpackages__", @@ -50,7 +56,7 @@ filegroup( ) filegroup( - name = "coverage_deps", + name = "coverage_deps_filegroup", srcs = ["coverage_deps.bzl"], visibility = ["//tools/private/update_deps:__pkg__"], ) @@ -62,508 +68,610 @@ filegroup( visibility = ["//python:__pkg__"], ) +alias( + name = "build_data_writer", + actual = select({ + "@platforms//os:windows": ":build_data_writer.ps1", + "//conditions:default": ":build_data_writer.sh", + }), +) + +# keep bzl_library( - name = "attr_builders_bzl", - srcs = ["attr_builders.bzl"], - deps = [ - ":builders_util_bzl", - "@bazel_skylib//lib:types", - ], + name = "sentinel_bzl", + srcs = ["sentinel.bzl"], ) +# keep bzl_library( - name = "attributes_bzl", - srcs = ["attributes.bzl"], - deps = [ - ":attr_builders_bzl", - ":common_bzl", - ":common_labels_bzl", - ":enum_bzl", - ":flags_bzl", - ":py_info_bzl", - ":py_internal_bzl", - ":reexports_bzl", - ":rule_builders_bzl", - ":rules_cc_srcs_bzl", - "@bazel_skylib//lib:dicts", - "@bazel_skylib//rules:common_settings", - ], + name = "stamp_bzl", + srcs = ["stamp.bzl"], +) + +define_uncachable_version_file( + name = "uncachable_version_file", ) +# @bazel_tools can't define bzl_library itself, so we just put a wrapper around it. +# keep bzl_library( - name = "auth_bzl", - srcs = ["auth.bzl"], - deps = [":bazel_tools_bzl"], + name = "bazel_tools", + srcs = [ + # This set of sources is overly broad, but it's the only public + # target available across Bazel versions that has all the necessary + # sources. + "@bazel_tools//tools:bzl_srcs", + ], ) +# keep bzl_library( - name = "runtime_env_toolchain_bzl", - srcs = ["runtime_env_toolchain.bzl"], + name = "rules_cc_srcs", + srcs = [ + # rules_cc 0.0.13 and earlier load cc_proto_libary (and thus protobuf@), + # but their bzl srcs targets don't transitively refer to protobuf. + "@com_google_protobuf//:bzl_srcs", + # NOTE: As of rules_cc 0.10, cc:bzl_srcs no longer contains + # everything and sub-targets must be used instead + "@rules_cc//cc:bzl_srcs", + "@rules_cc//cc/common", + "@rules_cc//cc/toolchains:toolchain_rules", + ], deps = [ - ":config_settings_bzl", - ":py_exec_tools_toolchain_bzl", - ":toolchain_types_bzl", - "//python:py_runtime_bzl", - "//python:py_runtime_pair_bzl", + ":bazel_tools", + "@rules_cc//cc/common", + ], +) + +# Needed to define bzl_library targets for docgen. (We don't define the +# bzl_library target here because it'd give our users a transitive dependency +# on Skylib.) +exports_files( + [ + "coverage.patch", + "repack_whl.py", + "py_package.bzl", + "py_wheel.bzl", + "version.bzl", + "reexports.bzl", + "stamp.bzl", + "util.bzl", ], + visibility = ["//:__subpackages__"], ) +exports_files( + ["python_bootstrap_template.txt"], + # Not actually public. Only public because it's an implicit dependency of + # py_runtime. + visibility = ["//visibility:public"], +) + +filegroup( + name = "stage1_bootstrap_template", + srcs = ["stage1_bootstrap_template.sh"], + # Not actually public. Only public because it's an implicit dependency of + # py_runtime. + visibility = ["//visibility:public"], +) + +filegroup( + name = "stage2_bootstrap_template", + srcs = ["stage2_bootstrap_template.py"], + # Not actually public. Only public because it's an implicit dependency of + # py_runtime. + visibility = ["//visibility:public"], +) + +filegroup( + name = "site_init_template", + srcs = ["site_init_template.py"], + # Not actually public. Only public because it's an implicit dependency of + # py_runtime. + visibility = ["//visibility:public"], +) + +# NOTE: Windows builds don't use this bootstrap. Instead, a native Windows +# program locates some Python exe and runs `python.exe foo.zip` which +# runs the __main__.py in the zip file. alias( - name = "build_data_writer", + name = "bootstrap_template", actual = select({ - "@platforms//os:windows": ":build_data_writer.ps1", - "//conditions:default": ":build_data_writer.sh", + ":is_script_bootstrap_enabled": "stage1_bootstrap_template.sh", + "//conditions:default": "python_bootstrap_template.txt", }), + # Not actually public. Only public because it's an implicit dependency of + # py_runtime. + visibility = ["//visibility:public"], ) -bzl_library( - name = "builders_bzl", - srcs = ["builders.bzl"], - deps = [ - "@bazel_skylib//lib:types", +# Used to determine the use of `--stamp` in Starlark rules +stamp_build_setting(name = "stamp") + +config_setting( + name = "is_script_bootstrap_enabled", + flag_values = { + "//python/config_settings:bootstrap_impl": "script", + }, +) + +config_setting( + name = "is_bazel_config_mode_target", + flag_values = { + "//python/private:bazel_config_mode": "target", + }, +) + +alias( + name = "debugger_if_target_config", + actual = select({ + ":is_bazel_config_mode_target": "//python/config_settings:debugger", + "//conditions:default": "//python/private:empty", + }), +) + +bazel_config_mode(name = "bazel_config_mode") + +# This should only be set by analysis tests to expose additional metadata to +# aid testing, so a setting instead of a flag. +bool_flag( + name = "visible_for_testing", + build_setting_default = False, + # This is only because it is an implicit dependency by the toolchains. + visibility = ["//visibility:public"], +) + +# Used for py_console_script_gen rule +py_binary( + name = "py_console_script_gen_py", + srcs = ["py_console_script_gen.py"], + main = "py_console_script_gen.py", + visibility = [ + "//visibility:public", + ], +) + +py_binary( + name = "py_wheel_dist", + srcs = ["py_wheel_dist.py"], + visibility = ["//visibility:public"], +) + +py_library( + name = "py_console_script_gen_lib", + srcs = ["py_console_script_gen.py"], + imports = ["../.."], + visibility = [ + "//tests/entry_points:__pkg__", ], ) +# The current toolchain's interpreter as an excutable, usable with +# executable=True attributes. +current_interpreter_executable( + name = "current_interpreter_executable", + # Not actually public. Only public because it's an implicit dependency of + # py_exec_tools_toolchain. + visibility = ["//visibility:public"], +) + +py_library( + name = "empty", +) + +sentinel( + name = "sentinel", +) + +py_binary( + name = "sync_runtimes_manifest_workspace", + srcs = ["tools/sync_runtimes_manifest_workspace.py"], + visibility = ["//:__subpackages__"], +) + bzl_library( - name = "builders_util_bzl", - srcs = ["builders_util.bzl"], + name = "attr_builders", + srcs = ["attr_builders.bzl"], deps = [ - ":bzlmod_enabled_bzl", + ":builders_util", "@bazel_skylib//lib:types", ], ) bzl_library( - name = "bzlmod_enabled_bzl", - srcs = ["bzlmod_enabled.bzl"], + name = "attributes", + srcs = ["attributes.bzl"], + deps = [ + ":attr_builders", + ":common_labels", + ":enum", + ":flags", + ":py_info", + ":reexports", + ":rule_builders", + "@bazel_skylib//lib:dicts", + "@bazel_skylib//rules:common_settings", + "@rules_cc//cc/common", + ], ) bzl_library( - name = "cc_helper_bzl", - srcs = ["cc_helper.bzl"], - deps = [":py_internal_bzl"], + name = "builders", + srcs = ["builders.bzl"], + deps = ["@bazel_skylib//lib:types"], ) bzl_library( - name = "common_bzl", - srcs = ["common.bzl"], + name = "builders_util", + srcs = ["builders_util.bzl"], deps = [ - ":cc_helper_bzl", - ":py_cc_link_params_info_bzl", - ":py_info_bzl", - ":py_internal_bzl", - ":reexports_bzl", - ":rules_cc_srcs_bzl", - "@bazel_skylib//lib:paths", + ":bzlmod_enabled", + "@bazel_skylib//lib:types", ], ) bzl_library( - name = "common_labels_bzl", - srcs = ["common_labels.bzl"], + name = "cc_helper", + srcs = ["cc_helper.bzl"], + deps = [":py_internal"], ) bzl_library( - name = "config_settings_bzl", - srcs = ["config_settings.bzl"], + name = "common", + srcs = ["common.bzl"], deps = [ - ":version_bzl", - "@bazel_skylib//lib:selects", - "@bazel_skylib//rules:common_settings", + ":builders", + ":cc_helper", + ":py_cc_link_params_info", + ":py_info", + ":py_internal", + ":py_interpreter_program", + ":reexports", + ":toolchain_types", + "@bazel_skylib//lib:paths", + "@rules_cc//cc/common", + "@rules_python_internal//:rules_python_config", ], ) bzl_library( - name = "coverage_deps_bzl", - srcs = ["coverage_deps.bzl"], + name = "config_settings", + srcs = ["config_settings.bzl"], deps = [ - ":bazel_tools_bzl", - ":repo_utils_bzl", - ":version_label_bzl", + ":text_util", + ":version", + "@bazel_skylib//lib:selects", + "@bazel_skylib//rules:common_settings", ], ) bzl_library( - name = "deprecation_bzl", - srcs = ["deprecation.bzl"], + name = "current_py_cc_headers", + srcs = ["current_py_cc_headers.bzl"], deps = [ - "@rules_python_internal//:rules_python_config_bzl", + ":toolchain_types", + "@rules_cc//cc/common", ], ) bzl_library( - name = "enum_bzl", - srcs = ["enum.bzl"], + name = "current_py_cc_libs", + srcs = ["current_py_cc_libs.bzl"], + deps = ["@rules_cc//cc/common"], ) bzl_library( - name = "envsubst_bzl", - srcs = ["envsubst.bzl"], + name = "deprecation", + srcs = ["deprecation.bzl"], + deps = ["@rules_python_internal//:rules_python_config"], ) bzl_library( - name = "flags_bzl", + name = "flags", srcs = ["flags.bzl"], deps = [ - ":enum_bzl", + ":enum", "@bazel_skylib//rules:common_settings", ], ) bzl_library( - name = "full_version_bzl", - srcs = ["full_version.bzl"], -) - -bzl_library( - name = "internal_config_repo_bzl", - srcs = ["internal_config_repo.bzl"], + name = "hermetic_runtime_repo_setup", + srcs = ["hermetic_runtime_repo_setup.bzl"], deps = [ - ":pbs_manifest_bzl", - ":repo_utils_bzl", - ":text_util_bzl", + ":py_exec_tools_toolchain", + ":version", + "//python:py_runtime", + "//python:py_runtime_pair", + "//python/cc:py_cc_toolchain", + "@rules_cc//cc:cc_import", + "@rules_cc//cc:cc_library", ], ) bzl_library( - name = "is_standalone_interpreter_bzl", - srcs = ["is_standalone_interpreter.bzl"], + name = "internal_config_repo", + srcs = ["internal_config_repo.bzl"], deps = [ - ":repo_utils_bzl", + ":repo_utils", + ":text_util", ], ) bzl_library( - name = "local_runtime_repo_bzl", - srcs = ["local_runtime_repo.bzl"], + name = "internal_dev_deps", + srcs = ["internal_dev_deps.bzl"], deps = [ - ":enum_bzl", - ":repo_utils.bzl", + ":runtime_env_repo", + "//python/private/pypi:whl_library", + "//tests/support/whl_from_dir:whl_from_dir_repo", + "@bazel_ci_rules//:rbe_repo", ], ) bzl_library( - name = "local_runtime_toolchains_repo_bzl", - srcs = ["local_runtime_toolchains_repo.bzl"], + name = "interpreter", + srcs = ["interpreter.bzl"], deps = [ - ":repo_utils.bzl", - ":text_util_bzl", + ":common", + ":toolchain_types", + "//python:py_runtime_info", + "//python/private:sentinel_bzl", + "@bazel_skylib//lib:paths", ], ) bzl_library( - name = "normalize_name_bzl", - srcs = ["normalize_name.bzl"], + name = "is_standalone_interpreter", + srcs = ["is_standalone_interpreter.bzl"], + deps = [":repo_utils"], ) bzl_library( - name = "pbs_manifest_bzl", - srcs = ["pbs_manifest.bzl"], + name = "local_runtime_repo", + srcs = ["local_runtime_repo.bzl"], + deps = [ + ":enum", + ":repo_utils", + ], ) bzl_library( - name = "precompile_bzl", - srcs = ["precompile.bzl"], + name = "local_runtime_repo_setup", + srcs = ["local_runtime_repo_setup.bzl"], deps = [ - ":attributes_bzl", - ":py_internal_bzl", - ":py_interpreter_program_bzl", - ":toolchain_types_bzl", - "@bazel_skylib//lib:paths", + "@bazel_skylib//lib:selects", + "@rules_cc//cc:cc_import", + "@rules_cc//cc:cc_library", + "@rules_python//python:py_runtime", + "@rules_python//python:py_runtime_pair", + "@rules_python//python/cc:py_cc_toolchain", + "@rules_python//python/private:py_exec_tools_toolchain", ], ) bzl_library( - name = "platform_info_bzl", - srcs = ["platform_info.bzl"], + name = "local_runtime_toolchains_repo", + srcs = ["local_runtime_toolchains_repo.bzl"], + deps = [ + ":repo_utils", + ":text_util", + ], ) bzl_library( - name = "python_bzl", - srcs = ["python.bzl"], + name = "precompile", + srcs = ["precompile.bzl"], deps = [ - ":full_version_bzl", - ":pbs_manifest_bzl", - ":platform_info_bzl", - ":python_register_toolchains_bzl", - ":pythons_hub_bzl", - ":repo_utils_bzl", - ":toolchains_repo_bzl", - ":version_bzl", - "@bazel_features//:features", + ":attributes", + ":flags", + ":py_interpreter_program", + ":toolchain_types", + "@bazel_skylib//rules:common_settings", ], ) bzl_library( - name = "python_register_toolchains_bzl", - srcs = ["python_register_toolchains.bzl"], + name = "py_binary_macro", + srcs = ["py_binary_macro.bzl"], deps = [ - ":auth_bzl", - ":bazel_tools_bzl", - ":coverage_deps_bzl", - ":full_version_bzl", - ":python_repository_bzl", - ":repo_utils_bzl", - ":toolchains_repo_bzl", - "//python:versions_bzl", - "//python/private/pypi:deps_bzl", + ":py_binary_rule", + ":py_executable", ], ) bzl_library( - name = "python_repository_bzl", - srcs = ["python_repository.bzl"], + name = "py_binary_rule", + srcs = ["py_binary_rule.bzl"], deps = [ - ":auth_bzl", - ":repo_utils_bzl", - ":text_util_bzl", - "//python:versions_bzl", + ":attributes", + ":py_executable", ], ) bzl_library( - name = "python_register_multi_toolchains_bzl", - srcs = ["python_register_multi_toolchains.bzl"], - deps = [ - ":python_register_toolchains_bzl", - ":toolchains_repo_bzl", - "//python:versions_bzl", - ], -) - -bzl_library( - name = "pythons_hub_bzl", - srcs = ["pythons_hub.bzl"], - deps = [ - ":pbs_manifest_bzl", - ":py_toolchain_suite_bzl", - ":text_util_bzl", - "//python:versions_bzl", - ], -) - -bzl_library( - name = "py_binary_macro_bzl", - srcs = ["py_binary_macro.bzl"], - deps = [ - ":py_binary_rule_bzl", - ":py_executable_bzl", - ], -) - -bzl_library( - name = "py_binary_rule_bzl", - srcs = ["py_binary_rule.bzl"], - deps = [ - ":attributes_bzl", - ":py_executable_bzl", - ":rule_builders_bzl", - "@bazel_skylib//lib:dicts", - ], -) - -bzl_library( - name = "py_cc_link_params_info_bzl", + name = "py_cc_link_params_info", srcs = ["py_cc_link_params_info.bzl"], - deps = [ - ":rules_cc_srcs_bzl", - ":util_bzl", - ], + deps = ["@rules_cc//cc/common"], ) bzl_library( - name = "py_cc_toolchain_macro_bzl", + name = "py_cc_toolchain_macro", srcs = ["py_cc_toolchain_macro.bzl"], deps = [ - ":py_cc_toolchain_rule_bzl", + ":py_cc_toolchain_rule", + ":util", ], ) bzl_library( - name = "py_cc_toolchain_rule_bzl", + name = "py_cc_toolchain_rule", srcs = ["py_cc_toolchain_rule.bzl"], deps = [ - ":common_labels_bzl", - ":py_cc_toolchain_info_bzl", - ":rules_cc_srcs_bzl", - ":sentinel_bzl", - ":util_bzl", + ":common_labels", + ":py_cc_toolchain_info", + "//python/private:sentinel_bzl", "@bazel_skylib//rules:common_settings", + "@rules_cc//cc/common", ], ) bzl_library( - name = "py_cc_toolchain_info_bzl", - srcs = ["py_cc_toolchain_info.bzl"], -) - -bzl_library( - name = "py_console_script_binary_bzl", - srcs = [ - "py_console_script_binary.bzl", - "py_console_script_gen.bzl", - ], - visibility = ["//python/entry_points:__pkg__"], + name = "py_console_script_binary", + srcs = ["py_console_script_binary.bzl"], deps = [ - "//python:py_binary_bzl", + ":py_console_script_gen", + "//python:py_binary", ], ) bzl_library( - name = "py_exec_tools_info_bzl", - srcs = ["py_exec_tools_info.bzl"], -) - -bzl_library( - name = "py_exec_tools_toolchain_bzl", + name = "py_exec_tools_toolchain", srcs = ["py_exec_tools_toolchain.bzl"], deps = [ - ":common_bzl", - ":common_labels_bzl", - ":py_exec_tools_info_bzl", - ":sentinel_bzl", - ":toolchain_types_bzl", + ":common_labels", + ":py_exec_tools_info", + ":toolchain_types", + "//python/private:sentinel_bzl", "@bazel_skylib//lib:paths", "@bazel_skylib//rules:common_settings", ], ) bzl_library( - name = "py_executable_bzl", + name = "py_executable", srcs = ["py_executable.bzl"], deps = [ - ":attributes_bzl", - ":cc_helper_bzl", - ":common_bzl", - ":common_labels_bzl", - ":flags_bzl", - ":precompile_bzl", - ":py_cc_link_params_info_bzl", - ":py_executable_info_bzl", - ":py_info_bzl", - ":py_internal_bzl", - ":py_runtime_info_bzl", - ":rules_cc_srcs_bzl", - ":toolchain_types_bzl", - ":transition_labels_bzl", - ":venv_runfiles_bzl", + ":attr_builders", + ":attributes", + ":builders", + ":cc_helper", + ":common", + ":common_labels", + ":flags", + ":precompile", + ":py_cc_link_params_info", + ":py_executable_info", + ":py_info", + ":py_internal", + ":py_runtime_info", + ":reexports", + ":rule_builders", + ":toolchain_types", + ":transition_labels", + ":venv_runfiles", "@bazel_skylib//lib:dicts", "@bazel_skylib//lib:paths", "@bazel_skylib//lib:structs", "@bazel_skylib//rules:common_settings", + "@rules_cc//cc/common", + "@rules_python_internal//:rules_python_config", ], ) bzl_library( - name = "py_executable_info_bzl", - srcs = ["py_executable_info.bzl"], -) - -bzl_library( - name = "py_info_bzl", + name = "py_info", srcs = ["py_info.bzl"], deps = [ - ":builders_bzl", - ":reexports_bzl", + ":builders", + ":reexports", ], ) bzl_library( - name = "py_internal_bzl", + name = "py_internal", srcs = ["py_internal.bzl"], - deps = ["//tools/build_defs/python/private:py_internal_renamed_bzl"], + deps = ["//tools/build_defs/python/private:py_internal_renamed"], ) bzl_library( - name = "py_interpreter_program_bzl", + name = "py_interpreter_program", srcs = ["py_interpreter_program.bzl"], deps = [ - ":sentinel_bzl", + "//python/private:sentinel_bzl", "@bazel_skylib//rules:common_settings", ], ) bzl_library( - name = "py_library_bzl", + name = "py_library", srcs = ["py_library.bzl"], deps = [ - ":attributes_bzl", - ":common_bzl", - ":common_labels_bzl", - ":flags_bzl", - ":normalize_name_bzl", - ":precompile_bzl", - ":py_cc_link_params_info_bzl", - ":py_internal_bzl", - ":rule_builders_bzl", - ":toolchain_types_bzl", - ":venv_runfiles_bzl", - ":version_bzl", + ":attr_builders", + ":attributes", + ":builders", + ":common", + ":common_labels", + ":flags", + ":normalize_name", + ":precompile", + ":py_cc_link_params_info", + ":py_info", + ":reexports", + ":rule_builders", + ":toolchain_types", + ":venv_runfiles", + ":version", "@bazel_skylib//lib:dicts", + "@bazel_skylib//lib:paths", "@bazel_skylib//rules:common_settings", ], ) bzl_library( - name = "py_library_macro_bzl", + name = "py_library_macro", srcs = ["py_library_macro.bzl"], - deps = [":py_library_rule_bzl"], + deps = [":py_library_rule"], ) bzl_library( - name = "py_library_rule_bzl", + name = "py_library_rule", srcs = ["py_library_rule.bzl"], - deps = [ - ":common_labels_bzl", - ":py_library_bzl", - ], + deps = [":py_library"], ) bzl_library( - name = "py_package_bzl", + name = "py_package", srcs = ["py_package.bzl"], - visibility = ["//:__subpackages__"], deps = [ - ":builders_bzl", - ":py_info_bzl", + ":builders", + ":py_info", ], ) bzl_library( - name = "py_runtime_info_bzl", - srcs = ["py_runtime_info.bzl"], + name = "py_runtime_macro", + srcs = ["py_runtime_macro.bzl"], + deps = [":py_runtime_rule"], ) bzl_library( - name = "py_repositories_bzl", - srcs = ["py_repositories.bzl"], - deps = [ - ":bazel_tools_bzl", - ":internal_config_repo_bzl", - ":pythons_hub_bzl", - "//python:versions_bzl", - "//python/private/pypi:deps_bzl", - ], + name = "py_runtime_pair_macro", + srcs = ["py_runtime_pair_macro.bzl"], + deps = [":py_runtime_pair_rule"], ) bzl_library( - name = "py_runtime_macro_bzl", - srcs = ["py_runtime_macro.bzl"], - deps = [":py_runtime_rule_bzl"], + name = "py_runtime_pair_rule", + srcs = ["py_runtime_pair_rule.bzl"], + deps = [ + ":common_labels", + ":reexports", + "//python:py_runtime_info", + "@bazel_skylib//rules:common_settings", + ], ) bzl_library( - name = "py_runtime_rule_bzl", + name = "py_runtime_rule", srcs = ["py_runtime_rule.bzl"], deps = [ - ":attributes_bzl", - ":common_labels_bzl", - ":flags_bzl", - ":py_internal_bzl", - ":py_runtime_info_bzl", - ":reexports_bzl", - ":rule_builders_bzl", - ":version_bzl", + ":common_labels", + ":flags", + ":py_internal", + ":py_runtime_info", + ":reexports", + ":version", "@bazel_skylib//lib:dicts", "@bazel_skylib//lib:paths", "@bazel_skylib//rules:common_settings", @@ -571,345 +679,326 @@ bzl_library( ) bzl_library( - name = "py_runtime_pair_macro_bzl", - srcs = ["py_runtime_pair_macro.bzl"], - visibility = ["//:__subpackages__"], - deps = [":py_runtime_pair_rule_bzl"], + name = "py_test_macro", + srcs = ["py_test_macro.bzl"], + deps = [ + ":py_executable", + ":py_test_rule", + ], ) bzl_library( - name = "py_runtime_pair_rule_bzl", - srcs = ["py_runtime_pair_rule.bzl"], + name = "py_test_rule", + srcs = ["py_test_rule.bzl"], deps = [ - ":common_labels_bzl", - "//python:py_runtime_bzl", - "//python:py_runtime_info_bzl", - "@bazel_skylib//rules:common_settings", + ":attributes", + ":common", + ":py_executable", ], ) bzl_library( - name = "py_test_macro_bzl", - srcs = ["py_test_macro.bzl"], + name = "py_toolchain_suite", + srcs = ["py_toolchain_suite.bzl"], deps = [ - ":py_executable_bzl", - ":py_test_rule_bzl", + ":text_util", + ":toolchain_types", + "@bazel_skylib//lib:selects", + "@platforms//host:constraints", ], ) bzl_library( - name = "py_test_rule_bzl", - srcs = ["py_test_rule.bzl"], + name = "python", + srcs = ["python.bzl"], deps = [ - ":attributes_bzl", - ":common_bzl", - ":py_executable_bzl", - ":rule_builders_bzl", - "@bazel_skylib//lib:dicts", + ":auth", + ":full_version", + ":pbs_manifest", + ":platform_info", + ":python_register_toolchains", + ":pythons_hub", + ":repo_utils", + ":toolchains_repo", + ":version", + "//python:versions", + "@bazel_features//:features", ], ) bzl_library( - name = "py_toolchain_suite_bzl", - srcs = ["py_toolchain_suite.bzl"], + name = "python_register_multi_toolchains", + srcs = ["python_register_multi_toolchains.bzl"], deps = [ - ":config_settings_bzl", - ":text_util_bzl", - ":toolchain_types_bzl", - "@bazel_skylib//lib:selects", + ":python_register_toolchains", + ":toolchains_repo", + "//python:versions", ], ) bzl_library( - name = "py_wheel_bzl", - srcs = ["py_wheel.bzl"], - visibility = ["//:__subpackages__"], + name = "python_register_toolchains", + srcs = ["python_register_toolchains.bzl"], deps = [ - ":py_package_bzl", - ":stamp_bzl", - ":transition_labels_bzl", - ":version_bzl", + ":coverage_deps", + ":full_version", + ":python_repository", + ":repo_utils", + ":toolchains_repo", + "//python:versions", ], ) bzl_library( - name = "reexports_bzl", - srcs = ["reexports.bzl"], - visibility = [ - "//:__subpackages__", - ], + name = "python_repository", + srcs = ["python_repository.bzl"], deps = [ - ":bazel_tools_bzl", - "@rules_python_internal//:rules_python_config_bzl", + ":auth", + ":repo_utils", + ":text_util", + "//python:versions", ], ) bzl_library( - name = "repo_utils_bzl", - srcs = ["repo_utils.bzl"], + name = "pythons_hub", + srcs = ["pythons_hub.bzl"], + deps = [ + ":pbs_manifest", + ":text_util", + ":toolchains_repo", + "//python:versions", + ], ) bzl_library( - name = "rule_builders_bzl", - srcs = ["rule_builders.bzl"], - deps = [ - ":builders_bzl", - ":builders_util_bzl", - "@bazel_skylib//lib:types", - ], + name = "reexports", + srcs = ["reexports.bzl"], + deps = ["@rules_python_internal//:rules_python_config"], ) bzl_library( - name = "runtimes_manifest_workspace_bzl", - srcs = ["runtimes_manifest_workspace.bzl"], + name = "repl", + srcs = ["repl.bzl"], + deps = ["//python:py_binary"], ) bzl_library( - name = "sentinel_bzl", - srcs = ["sentinel.bzl"], + name = "rule_builders", + srcs = ["rule_builders.bzl"], + deps = [ + ":builders_util", + "@bazel_skylib//lib:types", + ], ) bzl_library( - name = "stamp_bzl", - srcs = ["stamp.bzl"], - visibility = ["//:__subpackages__"], + name = "runtime_env_repo", + srcs = ["runtime_env_repo.bzl"], + deps = [":repo_utils"], ) bzl_library( - name = "text_util_bzl", - srcs = ["text_util.bzl"], + name = "runtime_env_toolchain", + srcs = ["runtime_env_toolchain.bzl"], + deps = [ + ":config_settings", + ":py_exec_tools_toolchain", + ":toolchain_types", + "//python:py_runtime", + "//python:py_runtime_pair", + "//python/cc:py_cc_toolchain", + "@rules_cc//cc:cc_library", + ], ) bzl_library( - name = "toolchains_repo_bzl", - srcs = ["toolchains_repo.bzl"], + name = "toolchain_aliases", + srcs = ["toolchain_aliases.bzl"], deps = [ - ":repo_utils_bzl", - ":text_util_bzl", - "//python:versions_bzl", + "//python:versions", + "@bazel_skylib//lib:selects", ], ) bzl_library( - name = "toolchain_types_bzl", - srcs = ["toolchain_types.bzl"], + name = "toolchains_repo", + srcs = ["toolchains_repo.bzl"], + deps = [ + ":repo_utils", + ":text_util", + "//python:versions", + ], ) bzl_library( - name = "transition_labels_bzl", + name = "transition_labels", srcs = ["transition_labels.bzl"], deps = [ - ":common_labels_bzl", + ":common_labels", "@bazel_skylib//lib:collections", - "@rules_python_internal//:extra_transition_settings_bzl", + "@rules_python_internal//:extra_transition_settings", ], ) bzl_library( - name = "util_bzl", + name = "util", srcs = ["util.bzl"], deps = [ - ":py_internal_bzl", + ":py_internal", "@bazel_skylib//lib:types", ], ) -define_uncachable_version_file( - name = "uncachable_version_file", +bzl_library( + name = "venv_runfiles", + srcs = ["venv_runfiles.bzl"], + deps = [ + ":common", + ":py_info", + ":util", + "@bazel_skylib//lib:paths", + ], ) bzl_library( - name = "version_bzl", - srcs = ["version.bzl"], + name = "py_wheel", + srcs = ["py_wheel.bzl"], + deps = [ + ":attributes", + ":py_info", + ":py_package", + ":rule_builders", + ":transition_labels", + ":version", + "//python/private:stamp_bzl", + ], ) bzl_library( - name = "version_label_bzl", - srcs = ["version_label.bzl"], + name = "auth", + srcs = ["auth.bzl"], + deps = ["//python/private:bazel_tools"], ) -# @bazel_tools can't define bzl_library itself, so we just put a wrapper around it. bzl_library( - name = "bazel_tools_bzl", - srcs = [ - # This set of sources is overly broad, but it's the only public - # target available across Bazel versions that has all the necessary - # sources. - "@bazel_tools//tools:bzl_srcs", - ], + name = "bzlmod_enabled", + srcs = ["bzlmod_enabled.bzl"], ) bzl_library( - name = "rules_cc_srcs_bzl", - srcs = [ - # rules_cc 0.0.13 and earlier load cc_proto_libary (and thus protobuf@), - # but their bzl srcs targets don't transitively refer to protobuf. - "@com_google_protobuf//:bzl_srcs", - # NOTE: As of rules_cc 0.10, cc:bzl_srcs no longer contains - # everything and sub-targets must be used instead - "@rules_cc//cc:bzl_srcs", - "@rules_cc//cc/common", - "@rules_cc//cc/toolchains:toolchain_rules", - ], - deps = [ - ":bazel_tools_bzl", - "@rules_cc//cc/common", - ], + name = "common_labels", + srcs = ["common_labels.bzl"], ) bzl_library( - name = "venv_runfiles_bzl", - srcs = ["venv_runfiles.bzl"], + name = "coverage_deps", + srcs = ["coverage_deps.bzl"], deps = [ - ":common_bzl", - ":py_info_bzl", - ":py_internal_bzl", - "@bazel_skylib//lib:paths", + ":repo_utils", + ":version_label", + "//python/private:bazel_tools", ], ) -# Needed to define bzl_library targets for docgen. (We don't define the -# bzl_library target here because it'd give our users a transitive dependency -# on Skylib.) -exports_files( - [ - "coverage.patch", - "repack_whl.py", - "py_package.bzl", - "py_wheel.bzl", - "version.bzl", - "reexports.bzl", - "stamp.bzl", - "util.bzl", - ], - visibility = ["//:__subpackages__"], +bzl_library( + name = "enum", + srcs = ["enum.bzl"], ) -exports_files( - ["python_bootstrap_template.txt"], - # Not actually public. Only public because it's an implicit dependency of - # py_runtime. - visibility = ["//visibility:public"], +bzl_library( + name = "envsubst", + srcs = ["envsubst.bzl"], ) -filegroup( - name = "stage1_bootstrap_template", - srcs = ["stage1_bootstrap_template.sh"], - # Not actually public. Only public because it's an implicit dependency of - # py_runtime. - visibility = ["//visibility:public"], +bzl_library( + name = "full_version", + srcs = ["full_version.bzl"], ) -filegroup( - name = "stage2_bootstrap_template", - srcs = ["stage2_bootstrap_template.py"], - # Not actually public. Only public because it's an implicit dependency of - # py_runtime. - visibility = ["//visibility:public"], +bzl_library( + name = "normalize_name", + srcs = ["normalize_name.bzl"], ) -filegroup( - name = "site_init_template", - srcs = ["site_init_template.py"], - # Not actually public. Only public because it's an implicit dependency of - # py_runtime. - visibility = ["//visibility:public"], +bzl_library( + name = "pbs_manifest", + srcs = ["pbs_manifest.bzl"], ) -# NOTE: Windows builds don't use this bootstrap. Instead, a native Windows -# program locates some Python exe and runs `python.exe foo.zip` which -# runs the __main__.py in the zip file. -alias( - name = "bootstrap_template", - actual = select({ - ":is_script_bootstrap_enabled": "stage1_bootstrap_template.sh", - "//conditions:default": "python_bootstrap_template.txt", - }), - # Not actually public. Only public because it's an implicit dependency of - # py_runtime. - visibility = ["//visibility:public"], +bzl_library( + name = "platform_info", + srcs = ["platform_info.bzl"], ) -# Used to determine the use of `--stamp` in Starlark rules -stamp_build_setting(name = "stamp") +bzl_library( + name = "py_cc_toolchain_info", + srcs = ["py_cc_toolchain_info.bzl"], +) -config_setting( - name = "is_script_bootstrap_enabled", - flag_values = { - "//python/config_settings:bootstrap_impl": "script", - }, +bzl_library( + name = "py_console_script_gen", + srcs = ["py_console_script_gen.bzl"], ) -config_setting( - name = "is_bazel_config_mode_target", - flag_values = { - "//python/private:bazel_config_mode": "target", - }, +bzl_library( + name = "py_exec_tools_info", + srcs = ["py_exec_tools_info.bzl"], ) -alias( - name = "debugger_if_target_config", - actual = select({ - ":is_bazel_config_mode_target": "//python/config_settings:debugger", - "//conditions:default": "//python/private:empty", - }), +bzl_library( + name = "py_executable_info", + srcs = ["py_executable_info.bzl"], ) -bazel_config_mode(name = "bazel_config_mode") +bzl_library( + name = "py_repositories", + srcs = ["py_repositories.bzl"], + deps = [ + ":internal_config_repo", + ":pythons_hub", + "//python:versions", + "//python/private:bazel_tools", + "//python/private/pypi:deps", + ], +) -# This should only be set by analysis tests to expose additional metadata to -# aid testing, so a setting instead of a flag. -bool_flag( - name = "visible_for_testing", - build_setting_default = False, - # This is only because it is an implicit dependency by the toolchains. - visibility = ["//visibility:public"], +bzl_library( + name = "py_runtime_info", + srcs = ["py_runtime_info.bzl"], ) -# Used for py_console_script_gen rule -py_binary( - name = "py_console_script_gen_py", - srcs = ["py_console_script_gen.py"], - main = "py_console_script_gen.py", - visibility = [ - "//visibility:public", - ], +bzl_library( + name = "repo_utils", + srcs = ["repo_utils.bzl"], ) -py_binary( - name = "py_wheel_dist", - srcs = ["py_wheel_dist.py"], - visibility = ["//visibility:public"], +bzl_library( + name = "runtimes_manifest_workspace", + srcs = ["runtimes_manifest_workspace.bzl"], ) -py_library( - name = "py_console_script_gen_lib", - srcs = ["py_console_script_gen.py"], - imports = ["../.."], - visibility = [ - "//tests/entry_points:__pkg__", - ], +bzl_library( + name = "text_util", + srcs = ["text_util.bzl"], ) -# The current toolchain's interpreter as an excutable, usable with -# executable=True attributes. -current_interpreter_executable( - name = "current_interpreter_executable", - # Not actually public. Only public because it's an implicit dependency of - # py_exec_tools_toolchain. - visibility = ["//visibility:public"], +bzl_library( + name = "toolchain_types", + srcs = ["toolchain_types.bzl"], ) -py_library( - name = "empty", +bzl_library( + name = "version", + srcs = ["version.bzl"], ) -sentinel( - name = "sentinel", +bzl_library( + name = "version_label", + srcs = ["version_label.bzl"], ) -py_binary( - name = "sync_runtimes_manifest_workspace", - srcs = ["tools/sync_runtimes_manifest_workspace.py"], - visibility = ["//:__subpackages__"], +bzl_library( + name = "visibility", + srcs = ["visibility.bzl"], ) diff --git a/python/private/api/BUILD.bazel b/python/private/api/BUILD.bazel index 0826b85d9b..b3cc7360a7 100644 --- a/python/private/api/BUILD.bazel +++ b/python/private/api/BUILD.bazel @@ -25,24 +25,21 @@ filegroup( ) py_common_api( - name = "py_common_api", + name = "py_common_api_impl", # NOTE: Not actually public. Implicit dependency of public rules. visibility = ["//visibility:public"], ) bzl_library( - name = "api_bzl", - srcs = ["api.bzl"], + name = "py_common_api", + srcs = ["py_common_api.bzl"], deps = [ - "//python/private:py_info_bzl", + ":api", + "//python/private:py_info", ], ) bzl_library( - name = "py_common_api_bzl", - srcs = ["py_common_api.bzl"], - deps = [ - ":api_bzl", - "//python/private:py_info_bzl", - ], + name = "api", + srcs = ["api.bzl"], ) diff --git a/python/private/api/api.bzl b/python/private/api/api.bzl index 44f9ab4e77..2a1f79fdf5 100644 --- a/python/private/api/api.bzl +++ b/python/private/api/api.bzl @@ -13,7 +13,7 @@ # limitations under the License. """Implementation of py_api.""" -_PY_COMMON_API_LABEL = Label("//python/private/api:py_common_api") +_PY_COMMON_API_LABEL = Label("//python/private/api:py_common_api_impl") ApiImplInfo = provider( doc = "Provider to hold an API implementation", diff --git a/python/private/common/BUILD.bazel b/python/private/common/BUILD.bazel new file mode 100644 index 0000000000..c72025ca89 --- /dev/null +++ b/python/private/common/BUILD.bazel @@ -0,0 +1,25 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + +bzl_library( + name = "py_binary_rule_bazel", + srcs = ["py_binary_rule_bazel.bzl"], + visibility = ["//python:__subpackages__"], +) + +bzl_library( + name = "py_library_rule_bazel", + srcs = ["py_library_rule_bazel.bzl"], + visibility = ["//python:__subpackages__"], +) + +bzl_library( + name = "py_runtime_rule", + srcs = ["py_runtime_rule.bzl"], + visibility = ["//python:__subpackages__"], +) + +bzl_library( + name = "py_test_rule_bazel", + srcs = ["py_test_rule_bazel.bzl"], + visibility = ["//python:__subpackages__"], +) diff --git a/python/private/internal_config_repo.bzl b/python/private/internal_config_repo.bzl index 72970cf100..78d0b35e12 100644 --- a/python/private/internal_config_repo.bzl +++ b/python/private/internal_config_repo.bzl @@ -49,14 +49,24 @@ package( ) bzl_library( - name = "extra_transition_settings_bzl", + name = "extra_transition_settings", srcs = ["extra_transition_settings.bzl"], ) +alias( + name = "extra_transition_settings_bzl", + actual = ":extra_transition_settings", +) + bzl_library( - name = "rules_python_config_bzl", + name = "rules_python_config", srcs = ["rules_python_config.bzl"], ) + +alias( + name = "rules_python_config_bzl", + actual = ":rules_python_config", +) """ _EXTRA_TRANSITIONS_TEMPLATE = """ diff --git a/python/private/pypi/BUILD.bazel b/python/private/pypi/BUILD.bazel index 7569eccac4..2dfdd8f02d 100644 --- a/python/private/pypi/BUILD.bazel +++ b/python/private/pypi/BUILD.bazel @@ -77,475 +77,488 @@ filegroup( # Keep sorted by library name and keep the files named by the main symbol they export -bzl_library( - name = "argparse_bzl", - srcs = ["argparse.bzl"], -) - -bzl_library( - name = "attrs_bzl", - srcs = ["attrs.bzl"], +py_library( + name = "repack_whl", + srcs = ["repack_whl.py"], + deps = ["//tools:wheelmaker"], ) bzl_library( - name = "config_settings_bzl", + name = "config_settings", srcs = ["config_settings.bzl"], - deps = [ - ":flags_bzl", - "//python/private:common_labels_bzl", - "//python/private:flags_bzl", - "@bazel_skylib//lib:selects", - ], + deps = ["@bazel_skylib//lib:selects"], ) +# keep bzl_library( - name = "deps_bzl", + name = "deps", srcs = ["deps.bzl"], deps = [ - "//python/private:bazel_tools_bzl", + "//python/private:bazel_tools", ], ) bzl_library( - name = "env_marker_info_bzl", - srcs = ["env_marker_info.bzl"], -) - -bzl_library( - name = "env_marker_setting_bzl", + name = "env_marker_setting", srcs = ["env_marker_setting.bzl"], deps = [ - ":env_marker_info_bzl", - ":pep508_env_bzl", - ":pep508_evaluate_bzl", - "//python/private:common_labels_bzl", - "//python/private:toolchain_types_bzl", + ":env_marker_info", + ":pep508_env", + ":pep508_evaluate", + "//python/private:common_labels", + "//python/private:toolchain_types", "@bazel_skylib//rules:common_settings", ], ) bzl_library( - name = "evaluate_markers_bzl", + name = "evaluate_markers", srcs = ["evaluate_markers.bzl"], deps = [ - ":deps_bzl", - ":pep508_evaluate_bzl", - ":pep508_requirement_bzl", + ":pep508_evaluate", + ":pep508_requirement", ], ) bzl_library( - name = "extension_bzl", + name = "extension", srcs = ["extension.bzl"], deps = [ - ":hub_builder_bzl", - ":hub_repository_bzl", - ":parse_whl_name_bzl", - ":pep508_env_bzl", - ":pip_repository_attrs_bzl", - ":platform_bzl", - ":pypi_cache_bzl", - ":simpleapi_download_bzl", - ":whl_library_bzl", - "//python/private:auth_bzl", - "//python/private:normalize_name_bzl", - "//python/private:repo_utils_bzl", - "@bazel_features//:features", - "@pythons_hub//:interpreters_bzl", - "@pythons_hub//:versions_bzl", - "@rules_python_internal//:rules_python_config_bzl", - ], -) - -bzl_library( - name = "flags_bzl", - srcs = ["flags.bzl"], - deps = [ - ":env_marker_info.bzl", - ":pep508_env_bzl", - "@bazel_skylib//rules:common_settings", + ":hub_builder", + ":hub_repository", + ":parse_whl_name", + ":pep508_env", + ":pip_repository_attrs", + ":platform", + ":pypi_cache", + ":simpleapi_download", + ":whl_library", + "//python/private:auth", + "//python/private:normalize_name", + "//python/private:repo_utils", + "@pythons_hub//:interpreters", + "@pythons_hub//:versions", + "@rules_python_internal//:rules_python_config", ], ) bzl_library( - name = "generate_whl_library_build_bazel_bzl", - srcs = ["generate_whl_library_build_bazel.bzl"], + name = "flags", + srcs = ["flags.bzl"], deps = [ - "//python/private:text_util_bzl", + ":env_marker_info", + ":pep508_env", + "//python/private:common_labels", + "@bazel_skylib//rules:common_settings", ], ) bzl_library( - name = "generate_group_library_build_bazel_bzl", + name = "generate_group_library_build_bazel", srcs = ["generate_group_library_build_bazel.bzl"], deps = [ - ":labels_bzl", - "//python/private:normalize_name_bzl", + ":labels", + "//python/private:normalize_name", + "//python/private:text_util", ], ) bzl_library( - name = "hub_builder_bzl", + name = "generate_whl_library_build_bazel", + srcs = ["generate_whl_library_build_bazel.bzl"], + deps = ["//python/private:text_util"], +) + +bzl_library( + name = "hub_builder", srcs = ["hub_builder.bzl"], - visibility = ["//:__subpackages__"], deps = [ - ":attrs_bzl", - ":parse_requirements_bzl", - ":pep508_env_bzl", - ":pep508_evaluate_bzl", - ":python_tag_bzl", - ":requirements_files_by_platform_bzl", - ":whl_config_setting_bzl", - ":whl_repo_name_bzl", - "//python/private:full_version_bzl", - "//python/private:normalize_name_bzl", - "//python/private:text_util_bzl", - "//python/private:version_bzl", - "//python/private:version_label_bzl", + ":attrs", + ":parse_requirements", + ":pep508_env", + ":pep508_evaluate", + ":python_tag", + ":requirements_files_by_platform", + ":whl_config_setting", + ":whl_repo_name", + "//python/private:full_version", + "//python/private:normalize_name", + "//python/private:repo_utils", + "//python/private:text_util", + "//python/private:version", + "//python/private:version_label", ], ) bzl_library( - name = "hub_repository_bzl", + name = "hub_repository", srcs = ["hub_repository.bzl"], - visibility = ["//:__subpackages__"], deps = [ - ":render_pkg_aliases_bzl", - "//python/private:text_util_bzl", + ":render_pkg_aliases", + ":whl_config_setting", + "//python/private:text_util", ], ) bzl_library( - name = "index_sources_bzl", - srcs = ["index_sources.bzl"], -) - -bzl_library( - name = "labels_bzl", - srcs = ["labels.bzl"], -) - -bzl_library( - name = "multi_pip_parse_bzl", + name = "multi_pip_parse", srcs = ["multi_pip_parse.bzl"], deps = [ - ":pip_repository_bzl", - "//python/private:text_util_bzl", + ":pip_repository", + "//python/private:text_util", ], ) bzl_library( - name = "package_annotation_bzl", - srcs = ["package_annotation.bzl"], + name = "namespace_pkgs", + srcs = ["namespace_pkgs.bzl"], + deps = ["@bazel_skylib//rules:copy_file"], ) bzl_library( - name = "parse_requirements_bzl", + name = "parse_requirements", srcs = ["parse_requirements.bzl"], deps = [ - ":argparse_bzl", - ":index_sources_bzl", - ":parse_requirements_txt_bzl", - ":pep508_evaluate_bzl", - ":pep508_requirement_bzl", - ":pypi_repo_utils_bzl", - ":requirements_files_by_platform_bzl", - ":select_whl_bzl", - "//python/private:normalize_name_bzl", - "//python/private:repo_utils_bzl", + ":argparse", + ":index_sources", + ":parse_requirements_txt", + ":pep508_evaluate", + ":pep508_requirement", + ":select_whl", + "//python/private:normalize_name", + "//python/private:repo_utils", ], ) bzl_library( - name = "parse_requirements_txt_bzl", - srcs = ["parse_requirements_txt.bzl"], -) - -bzl_library( - name = "parse_simpleapi_html_bzl", + name = "parse_simpleapi_html", srcs = ["parse_simpleapi_html.bzl"], deps = [ - ":version_from_filename_bzl", - "//python/private:normalize_name_bzl", + ":version_from_filename", + "//python/private:normalize_name", ], ) bzl_library( - name = "parse_whl_name_bzl", - srcs = ["parse_whl_name.bzl"], -) - -bzl_library( - name = "patch_whl_bzl", + name = "patch_whl", srcs = ["patch_whl.bzl"], deps = [ - ":parse_whl_name_bzl", - "//python/private:repo_utils_bzl", - "@rules_python_internal//:rules_python_config_bzl", + ":parse_whl_name", + ":pypi_repo_utils", + "//python/private:repo_utils", + "@rules_python_internal//:rules_python_config", ], ) bzl_library( - name = "pep508_deps_bzl", + name = "pep508_deps", srcs = ["pep508_deps.bzl"], deps = [ - ":pep508_env_bzl", - ":pep508_evaluate_bzl", - ":pep508_requirement_bzl", - "//python/private:normalize_name_bzl", + ":pep508_env", + ":pep508_evaluate", + ":pep508_requirement", + "//python/private:normalize_name", ], ) bzl_library( - name = "pep508_env_bzl", + name = "pep508_env", srcs = ["pep508_env.bzl"], deps = [ - "//python/private:normalize_name_bzl", - "//python/private:version_bzl", + "//python/private:normalize_name", + "//python/private:version", ], ) bzl_library( - name = "pep508_evaluate_bzl", + name = "pep508_evaluate", srcs = ["pep508_evaluate.bzl"], deps = [ - "//python/private:enum_bzl", - "//python/private:version_bzl", + "//python/private:enum", + "//python/private:version", ], ) bzl_library( - name = "pep508_requirement_bzl", + name = "pep508_requirement", srcs = ["pep508_requirement.bzl"], - deps = [ - "//python/private:normalize_name_bzl", - ], + deps = ["//python/private:normalize_name"], ) bzl_library( - name = "pip_bzl", + name = "pip", srcs = ["pip.bzl"], - deps = [ - ":extension_bzl", - ], + deps = [":extension"], ) bzl_library( - name = "pip_compile_bzl", + name = "pip_compile", srcs = ["pip_compile.bzl"], deps = [ - ":deps_bzl", - "//python:py_binary_bzl", - "//python:py_test_bzl", + "//python:py_binary", + "//python:py_test", ], ) bzl_library( - name = "pip_repository_bzl", + name = "pip_repository", srcs = ["pip_repository.bzl"], deps = [ - ":attrs_bzl", - ":parse_requirements_bzl", - ":pep508_env_bzl", - ":pip_repository_attrs_bzl", - ":pypi_repo_utils_bzl", - ":render_pkg_aliases_bzl", - ":whl_config_setting_bzl", - "//python/private:normalize_name_bzl", - "//python/private:repo_utils_bzl", - "//python/private:text_util_bzl", + ":parse_requirements", + ":pep508_env", + ":pip_repository_attrs", + ":pypi_repo_utils", + ":render_pkg_aliases", + ":requirements_files_by_platform", + "//python/private:normalize_name", + "//python/private:repo_utils", + "//python/private:text_util", "@bazel_skylib//lib:sets", ], ) bzl_library( - name = "pip_repository_attrs_bzl", + name = "pip_repository_attrs", srcs = ["pip_repository_attrs.bzl"], + deps = [":attrs"], ) bzl_library( - name = "pkg_aliases_bzl", + name = "pkg_aliases", srcs = ["pkg_aliases.bzl"], deps = [ - ":labels_bzl", - "//python/private:common_labels_bzl", - "//python/private:text_util_bzl", + ":labels", + "//python/private:common_labels", + "//python/private:text_util", "@bazel_skylib//lib:selects", ], ) bzl_library( - name = "platform_bzl", - srcs = ["platform.bzl"], -) - -bzl_library( - name = "pypi_cache_bzl", + name = "pypi_cache", srcs = ["pypi_cache.bzl"], - deps = [ - ":version_from_filename_bzl", - ], + deps = [":version_from_filename"], ) bzl_library( - name = "pypi_repo_utils_bzl", + name = "pypi_repo_utils", srcs = ["pypi_repo_utils.bzl"], deps = [ - "//python/private:repo_utils_bzl", + "//python/private:repo_utils", + "//python/private:util", "@bazel_skylib//lib:types", ], ) bzl_library( - name = "python_tag_bzl", + name = "python_tag", srcs = ["python_tag.bzl"], - deps = [ - "//python/private:version_bzl", - ], + deps = ["//python/private:version"], ) bzl_library( - name = "render_pkg_aliases_bzl", + name = "render_pkg_aliases", srcs = ["render_pkg_aliases.bzl"], deps = [ - ":generate_group_library_build_bazel_bzl", - ":whl_config_setting_bzl", - "//python/private:normalize_name_bzl", - "//python/private:text_util_bzl", + ":generate_group_library_build_bazel", + "//python/private:normalize_name", + "//python/private:text_util", ], ) -py_library( - name = "repack_whl", - srcs = ["repack_whl.py"], - deps = ["//tools:wheelmaker"], -) - bzl_library( - name = "requirements_files_by_platform_bzl", + name = "requirements_files_by_platform", srcs = ["requirements_files_by_platform.bzl"], deps = [ - ":argparse_bzl", - ":whl_target_platforms_bzl", + ":argparse", + ":whl_target_platforms", ], ) bzl_library( - name = "select_whl_bzl", + name = "select_whl", srcs = ["select_whl.bzl"], deps = [ - ":parse_whl_name_bzl", - ":python_tag_bzl", - "//python/private:version_bzl", + ":parse_whl_name", + ":python_tag", + "//python/private:version", ], ) bzl_library( - name = "simpleapi_download_bzl", + name = "simpleapi_download", srcs = ["simpleapi_download.bzl"], deps = [ - ":parse_simpleapi_html_bzl", - ":urllib_bzl", - "//python/private:auth_bzl", - "//python/private:normalize_name_bzl", + ":parse_simpleapi_html", + ":urllib", + "//python/private:auth", + "//python/private:envsubst", + "//python/private:normalize_name", ], ) bzl_library( - name = "urllib_bzl", - srcs = ["urllib.bzl"], + name = "venv_entry_point", + srcs = ["venv_entry_point.bzl"], + deps = [ + "//python/private:attributes", + "//python/private:common", + "//python/private:rule_builders", + ], ) bzl_library( - name = "version_from_filename_bzl", - srcs = ["version_from_filename.bzl"], + name = "venv_rewrite_shebang", + srcs = ["venv_rewrite_shebang.bzl"], + deps = [ + "//python/private:attributes", + "//python/private:common", + "//python/private:py_info", + "//python/private:rule_builders", + ], ) bzl_library( - name = "whl_config_repo_bzl", + name = "whl_config_repo", srcs = ["whl_config_repo.bzl"], deps = [ - ":generate_group_library_build_bazel_bzl", - "//python/private:text_util_bzl", + ":generate_group_library_build_bazel", + "//python/private:text_util", ], ) bzl_library( - name = "whl_config_setting_bzl", - srcs = ["whl_config_setting.bzl"], + name = "whl_extract", + srcs = ["whl_extract.bzl"], + deps = [ + ":whl_metadata", + "//python/private:repo_utils", + "@rules_python_internal//:rules_python_config", + ], ) bzl_library( - name = "whl_extract_bzl", - srcs = ["whl_extract.bzl"], + name = "whl_library", + srcs = ["whl_library.bzl"], deps = [ - ":whl_metadata_bzl", - "//python/private:repo_utils_bzl", - "@rules_python_internal//:rules_python_config_bzl", + ":attrs", + ":deps", + ":generate_whl_library_build_bazel", + ":patch_whl", + ":pep508_requirement", + ":pypi_repo_utils", + ":urllib", + ":whl_extract", + ":whl_metadata", + "//python/private:auth", + "//python/private:envsubst", + "//python/private:is_standalone_interpreter", + "//python/private:normalize_name", + "//python/private:repo_utils", ], ) bzl_library( - name = "whl_library_alias_bzl", + name = "whl_library_alias", srcs = ["whl_library_alias.bzl"], deps = [ - ":render_pkg_aliases_bzl", - "//python/private:full_version_bzl", + ":render_pkg_aliases", + "//python/private:full_version", ], ) bzl_library( - name = "whl_library_bzl", - srcs = ["whl_library.bzl"], + name = "whl_library_targets", + srcs = ["whl_library_targets.bzl"], deps = [ - ":attrs_bzl", - ":deps_bzl", - ":generate_whl_library_build_bazel_bzl", - ":parse_whl_name_bzl", - ":patch_whl_bzl", - ":pep508_requirement_bzl", - ":pypi_repo_utils_bzl", - ":urllib_bzl", - ":whl_extract_bzl", - ":whl_metadata_bzl", - ":whl_target_platforms_bzl", - "//python/private:auth_bzl", - "//python/private:envsubst_bzl", - "//python/private:is_standalone_interpreter_bzl", - "//python/private:normalize_name_bzl", - "//python/private:repo_utils_bzl", - "//python/private:util_bzl", - "@rules_python_internal//:rules_python_config_bzl", - ], -) - -bzl_library( - name = "whl_metadata_bzl", - srcs = ["whl_metadata.bzl"], + ":env_marker_setting", + ":labels", + ":namespace_pkgs", + ":pep508_deps", + ":venv_entry_point", + ":venv_rewrite_shebang", + "//python:py_binary", + "//python:py_library", + "//python/private:normalize_name", + "@bazel_skylib//rules:copy_file", + ], ) bzl_library( - name = "whl_repo_name_bzl", + name = "whl_repo_name", srcs = ["whl_repo_name.bzl"], deps = [ - ":parse_whl_name_bzl", - "//python/private:normalize_name_bzl", + ":parse_whl_name", + "//python/private:normalize_name", ], ) bzl_library( - name = "whl_target_platforms_bzl", - srcs = ["whl_target_platforms.bzl"], + name = "argparse", + srcs = ["argparse.bzl"], ) bzl_library( - name = "venv_entry_point_bzl", - srcs = ["venv_entry_point.bzl"], - visibility = ["//visibility:public"], + name = "attrs", + srcs = ["attrs.bzl"], ) bzl_library( - name = "venv_rewrite_shebang_bzl", - srcs = ["venv_rewrite_shebang.bzl"], - visibility = ["//visibility:public"], + name = "env_marker_info", + srcs = ["env_marker_info.bzl"], +) + +bzl_library( + name = "index_sources", + srcs = ["index_sources.bzl"], +) + +bzl_library( + name = "labels", + srcs = ["labels.bzl"], +) + +bzl_library( + name = "package_annotation", + srcs = ["package_annotation.bzl"], +) + +bzl_library( + name = "parse_requirements_txt", + srcs = ["parse_requirements_txt.bzl"], +) + +bzl_library( + name = "parse_whl_name", + srcs = ["parse_whl_name.bzl"], +) + +bzl_library( + name = "platform", + srcs = ["platform.bzl"], +) + +bzl_library( + name = "urllib", + srcs = ["urllib.bzl"], +) + +bzl_library( + name = "version_from_filename", + srcs = ["version_from_filename.bzl"], +) + +bzl_library( + name = "whl_config_setting", + srcs = ["whl_config_setting.bzl"], +) + +bzl_library( + name = "whl_metadata", + srcs = ["whl_metadata.bzl"], +) + +bzl_library( + name = "whl_target_platforms", + srcs = ["whl_target_platforms.bzl"], ) diff --git a/python/private/pythons_hub.bzl b/python/private/pythons_hub.bzl index 173c811da6..d6f6bcec92 100644 --- a/python/private/pythons_hub.bzl +++ b/python/private/pythons_hub.bzl @@ -31,17 +31,33 @@ load("@@{rules_python}//python/private:py_toolchain_suite.bzl", "py_toolchain_su load("@bazel_skylib//:bzl_library.bzl", "bzl_library") bzl_library( - name = "interpreters_bzl", + name = "interpreters", srcs = ["interpreters.bzl"], visibility = ["@rules_python//:__subpackages__"], ) +# deprecated: use :interpreters instead +alias( + name = "interpreters_bzl", + actual = ":interpreters", + deprecation = "Use :interpreters instead. The _bzl suffix targets are deprecated and will be removed in a future release.", + visibility = ["@rules_python//:__subpackages__"], +) + bzl_library( - name = "versions_bzl", + name = "versions", srcs = ["versions.bzl"], visibility = ["@rules_python//:__subpackages__"], ) +# deprecated: use :versions instead +alias( + name = "versions_bzl", + actual = ":versions", + deprecation = "Use :versions instead. The _bzl suffix targets are deprecated and will be removed in a future release.", + visibility = ["@rules_python//:__subpackages__"], +) + {toolchains} """ diff --git a/python/private/whl_filegroup/BUILD.bazel b/python/private/whl_filegroup/BUILD.bazel index b4246ca080..4d0a096311 100644 --- a/python/private/whl_filegroup/BUILD.bazel +++ b/python/private/whl_filegroup/BUILD.bazel @@ -7,14 +7,14 @@ filegroup( visibility = ["//python/private:__pkg__"], ) -bzl_library( - name = "whl_filegroup_bzl", - srcs = ["whl_filegroup.bzl"], - visibility = ["//:__subpackages__"], -) - py_binary( name = "extract_wheel_files", srcs = ["extract_wheel_files.py"], visibility = ["//visibility:public"], ) + +bzl_library( + name = "whl_filegroup", + srcs = ["whl_filegroup.bzl"], + visibility = ["//python:__subpackages__"], +) diff --git a/python/private/zipapp/BUILD.bazel b/python/private/zipapp/BUILD.bazel index 543fe0a185..66f0b4f667 100644 --- a/python/private/zipapp/BUILD.bazel +++ b/python/private/zipapp/BUILD.bazel @@ -11,25 +11,6 @@ filegroup( srcs = glob(["**"]), ) -bzl_library( - name = "py_zipapp_rule_bzl", - srcs = ["py_zipapp_rule.bzl"], - deps = [ - "//python/private:attributes_bzl", - "//python/private:builders_bzl", - "//python/private:common_bzl", - "//python/private:common_labels_bzl", - "//python/private:py_executable_info_bzl", - "//python/private:py_info_bzl", - "//python/private:py_internal_bzl", - "//python/private:py_interpreter_program_bzl", - "//python/private:py_runtime_info_bzl", - "//python/private:toolchain_types_bzl", - "//python/private:transition_labels_bzl", - "@bazel_skylib//lib:paths", - ], -) - filegroup( name = "zip_main_template", srcs = ["zip_main_template.py"], @@ -47,3 +28,21 @@ filegroup( srcs = ["zipapp_stage2_bootstrap_template.py"], visibility = ["//visibility:public"], ) + +bzl_library( + name = "py_zipapp_rule", + srcs = ["py_zipapp_rule.bzl"], + deps = [ + "//python/private:attributes", + "//python/private:builders", + "//python/private:common", + "//python/private:common_labels", + "//python/private:py_executable_info", + "//python/private:py_internal", + "//python/private:py_runtime_info", + "//python/private:toolchain_types", + "//python/private:transition_labels", + "@bazel_skylib//lib:paths", + "@rules_python_internal//:rules_python_config", + ], +) diff --git a/python/uv/BUILD.bazel b/python/uv/BUILD.bazel index 7ce6ce0523..93aefbfbd7 100644 --- a/python/uv/BUILD.bazel +++ b/python/uv/BUILD.bazel @@ -45,33 +45,25 @@ current_toolchain( ) bzl_library( - name = "lock_bzl", + name = "lock", srcs = ["lock.bzl"], - # EXPERIMENTAL: Visibility is restricted to allow for changes. - visibility = ["//:__subpackages__"], - deps = ["//python/uv/private:lock_bzl"], + deps = ["//python/uv/private:lock"], ) bzl_library( - name = "uv_bzl", + name = "uv", srcs = ["uv.bzl"], - # EXPERIMENTAL: Visibility is restricted to allow for changes. - visibility = ["//:__subpackages__"], - deps = ["//python/uv/private:uv_bzl"], + deps = ["//python/uv/private:uv"], ) bzl_library( - name = "uv_toolchain_bzl", + name = "uv_toolchain", srcs = ["uv_toolchain.bzl"], - # EXPERIMENTAL: Visibility is restricted to allow for changes. - visibility = ["//:__subpackages__"], - deps = ["//python/uv/private:uv_toolchain_bzl"], + deps = ["//python/uv/private:uv_toolchain"], ) bzl_library( - name = "uv_toolchain_info_bzl", + name = "uv_toolchain_info", srcs = ["uv_toolchain_info.bzl"], - # EXPERIMENTAL: Visibility is restricted to allow for changes. - visibility = ["//:__subpackages__"], - deps = ["//python/uv/private:uv_toolchain_info_bzl"], + deps = ["//python/uv/private:uv_toolchain_info"], ) diff --git a/python/uv/private/BUILD.bazel b/python/uv/private/BUILD.bazel index 3e4d6c7baa..ecfc2bcb92 100644 --- a/python/uv/private/BUILD.bazel +++ b/python/uv/private/BUILD.bazel @@ -29,80 +29,86 @@ filegroup( visibility = ["//python/uv:__pkg__"], ) +filegroup( + name = "lock_template", + srcs = select({ + "@platforms//os:windows": ["lock.bat"], + "//conditions:default": ["lock.sh"], + }), + target_compatible_with = [] if BZLMOD_ENABLED else ["@platforms//:incompatible"], + visibility = ["//visibility:public"], +) + bzl_library( - name = "current_toolchain_bzl", + name = "current_toolchain", srcs = ["current_toolchain.bzl"], visibility = ["//python/uv:__subpackages__"], + deps = [":toolchain_types"], ) bzl_library( - name = "lock_bzl", + name = "lock", srcs = ["lock.bzl"], visibility = ["//python/uv:__subpackages__"], deps = [ - ":toolchain_types_bzl", - "//python:py_binary_bzl", - "//python/private:bzlmod_enabled_bzl", - "//python/private:common_labels_bzl", - "//python/private:toolchain_types_bzl", + ":toolchain_types", + "//python:py_binary", + "//python/private:bzlmod_enabled", + "//python/private:common_labels", + "//python/private:toolchain_types", "@bazel_skylib//lib:shell", ], ) bzl_library( - name = "toolchain_types_bzl", - srcs = ["toolchain_types.bzl"], + name = "toolchains_hub", + srcs = ["toolchains_hub.bzl"], visibility = ["//python/uv:__subpackages__"], + deps = [":toolchain_types"], ) bzl_library( - name = "uv_bzl", + name = "uv", srcs = ["uv.bzl"], visibility = ["//python/uv:__subpackages__"], deps = [ - ":toolchain_types_bzl", - ":uv_repository_bzl", - ":uv_toolchains_repo_bzl", - "//python/private:auth_bzl", - "//python/private:common_labels_bzl", + ":toolchain_types", + ":uv_repository", + ":uv_toolchains_repo", + "//python/private:auth", + "//python/private:common_labels", ], ) bzl_library( - name = "uv_repository_bzl", + name = "uv_repository", srcs = ["uv_repository.bzl"], visibility = ["//python/uv:__subpackages__"], - deps = ["//python/private:auth_bzl"], + deps = ["//python/private:auth"], ) bzl_library( - name = "uv_toolchain_bzl", + name = "uv_toolchain", srcs = ["uv_toolchain.bzl"], visibility = ["//python/uv:__subpackages__"], - deps = [":uv_toolchain_info_bzl"], + deps = [":uv_toolchain_info"], ) bzl_library( - name = "uv_toolchain_info_bzl", - srcs = ["uv_toolchain_info.bzl"], + name = "uv_toolchains_repo", + srcs = ["uv_toolchains_repo.bzl"], visibility = ["//python/uv:__subpackages__"], + deps = ["//python/private:text_util"], ) bzl_library( - name = "uv_toolchains_repo_bzl", - srcs = ["uv_toolchains_repo.bzl"], + name = "toolchain_types", + srcs = ["toolchain_types.bzl"], visibility = ["//python/uv:__subpackages__"], - deps = [ - "//python/private:text_util_bzl", - ], ) -filegroup( - name = "lock_template", - srcs = select({ - "@platforms//os:windows": ["lock.bat"], - "//conditions:default": ["lock.sh"], - }), - target_compatible_with = [] if BZLMOD_ENABLED else ["@platforms//:incompatible"], - visibility = ["//visibility:public"], +bzl_library( + name = "uv_toolchain_info", + srcs = ["uv_toolchain_info.bzl"], + visibility = ["//python/uv:__subpackages__"], ) diff --git a/python/zipapp/BUILD.bazel b/python/zipapp/BUILD.bazel index 71249ae45c..5e8c51171b 100644 --- a/python/zipapp/BUILD.bazel +++ b/python/zipapp/BUILD.bazel @@ -11,19 +11,19 @@ filegroup( ) bzl_library( - name = "py_zipapp_binary_bzl", + name = "py_zipapp_binary", srcs = ["py_zipapp_binary.bzl"], deps = [ - "//python/private:util_bzl", - "//python/private/zipapp:py_zipapp_rule_bzl", + "//python/private:util", + "//python/private/zipapp:py_zipapp_rule", ], ) bzl_library( - name = "py_zipapp_test_bzl", + name = "py_zipapp_test", srcs = ["py_zipapp_test.bzl"], deps = [ - "//python/private:util_bzl", - "//python/private/zipapp:py_zipapp_rule_bzl", + "//python/private:util", + "//python/private/zipapp:py_zipapp_rule", ], ) diff --git a/sphinxdocs/docs/BUILD.bazel b/sphinxdocs/docs/BUILD.bazel index 87771f14f1..58c9e7fc18 100644 --- a/sphinxdocs/docs/BUILD.bazel +++ b/sphinxdocs/docs/BUILD.bazel @@ -48,11 +48,11 @@ sphinx_docs_library( sphinx_stardocs( name = "bzl_docs", srcs = [ - "//sphinxdocs:readthedocs_bzl", - "//sphinxdocs:sphinx_bzl", - "//sphinxdocs:sphinx_docs_library_bzl", - "//sphinxdocs:sphinx_stardoc_bzl", - "//sphinxdocs/private:sphinx_docs_library_bzl", + "//sphinxdocs:readthedocs", + "//sphinxdocs:sphinx", + "//sphinxdocs:sphinx_docs_library", + "//sphinxdocs:sphinx_stardoc", + "//sphinxdocs/private:sphinx_docs_library", ], prefix = "api/sphinxdocs/", target_compatible_with = _TARGET_COMPATIBLE_WITH, diff --git a/sphinxdocs/sphinxdocs/BUILD.bazel b/sphinxdocs/sphinxdocs/BUILD.bazel index 5a498b197e..fbdd633a32 100644 --- a/sphinxdocs/sphinxdocs/BUILD.bazel +++ b/sphinxdocs/sphinxdocs/BUILD.bazel @@ -42,29 +42,55 @@ bool_flag( ) bzl_library( - name = "sphinx_bzl", + name = "sphinx", srcs = ["sphinx.bzl"], visibility = ["//visibility:public"], - deps = ["//sphinxdocs/private:sphinx_bzl"], + deps = ["//sphinxdocs/private:sphinx"], ) bzl_library( - name = "sphinx_docs_library_bzl", + name = "sphinx_docs_library", srcs = ["sphinx_docs_library.bzl"], visibility = ["//visibility:public"], - deps = ["//sphinxdocs/private:sphinx_docs_library_macro_bzl"], + deps = ["//sphinxdocs/private:sphinx_docs_library_macro"], ) bzl_library( - name = "sphinx_stardoc_bzl", + name = "sphinx_stardoc", srcs = ["sphinx_stardoc.bzl"], visibility = ["//visibility:public"], - deps = ["//sphinxdocs/private:sphinx_stardoc_bzl"], + deps = ["//sphinxdocs/private:sphinx_stardoc"], ) bzl_library( - name = "readthedocs_bzl", + name = "readthedocs", srcs = ["readthedocs.bzl"], visibility = ["//visibility:public"], - deps = ["//sphinxdocs/private:readthedocs_bzl"], + deps = ["//sphinxdocs/private:readthedocs"], +) + +# ========= Deprecated aliases for backwards compatibility ========= + +alias( + name = "sphinx_bzl", + actual = ":sphinx", + deprecation = "Use //sphinxdocs:sphinx instead", +) + +alias( + name = "sphinx_docs_library_bzl", + actual = ":sphinx_docs_library", + deprecation = "Use //sphinxdocs:sphinx_docs_library instead", +) + +alias( + name = "sphinx_stardoc_bzl", + actual = ":sphinx_stardoc", + deprecation = "Use //sphinxdocs:sphinx_stardoc instead", +) + +alias( + name = "readthedocs_bzl", + actual = ":readthedocs", + deprecation = "Use //sphinxdocs:readthedocs instead", ) diff --git a/sphinxdocs/sphinxdocs/private/BUILD.bazel b/sphinxdocs/sphinxdocs/private/BUILD.bazel index 785d2e074d..8c9ea58e88 100644 --- a/sphinxdocs/sphinxdocs/private/BUILD.bazel +++ b/sphinxdocs/sphinxdocs/private/BUILD.bazel @@ -35,7 +35,7 @@ exports_files( ) bzl_library( - name = "util_bzl", + name = "util", srcs = ["util.bzl"], deps = [ "@bazel_skylib//lib:types", @@ -43,48 +43,48 @@ bzl_library( ) bzl_library( - name = "sphinx_docs_library_macro_bzl", + name = "sphinx_docs_library_macro", srcs = ["sphinx_docs_library_macro.bzl"], deps = [ - ":sphinx_docs_library_bzl", - "//sphinxdocs/private:util_bzl", + ":sphinx_docs_library", + ":util", ], ) bzl_library( - name = "sphinx_docs_library_bzl", + name = "sphinx_docs_library", srcs = ["sphinx_docs_library.bzl"], - deps = [":sphinx_docs_library_info_bzl"], + deps = [":sphinx_docs_library_info"], ) bzl_library( - name = "sphinx_docs_library_info_bzl", + name = "sphinx_docs_library_info", srcs = ["sphinx_docs_library_info.bzl"], ) bzl_library( - name = "sphinx_bzl", + name = "sphinx", srcs = ["sphinx.bzl"], deps = [ - ":sphinx_docs_library_info_bzl", - ":util_bzl", + ":sphinx_docs_library_info", + ":util", "@bazel_skylib//:bzl_library", "@bazel_skylib//lib:paths", "@bazel_skylib//lib:types", "@bazel_skylib//rules:build_test", "@bazel_skylib//rules:common_settings", "@io_bazel_stardoc//stardoc:stardoc_lib", - "@rules_python//python:py_binary_bzl", + "@rules_python//python:py_binary", ], ) bzl_library( - name = "sphinx_stardoc_bzl", + name = "sphinx_stardoc", srcs = ["sphinx_stardoc.bzl"], deps = [ - ":sphinx_docs_library_macro_bzl", - "//sphinxdocs:sphinx_bzl", - "//sphinxdocs/private:util_bzl", + ":sphinx_docs_library_macro", + ":util", + "//sphinxdocs:sphinx", "@bazel_skylib//:bzl_library", "@bazel_skylib//lib:paths", "@bazel_skylib//lib:types", @@ -94,11 +94,11 @@ bzl_library( ) bzl_library( - name = "readthedocs_bzl", + name = "readthedocs", srcs = ["readthedocs.bzl"], deps = [ - ":util_bzl", - "@rules_python//python:py_binary_bzl", + ":util", + "@rules_python//python:py_binary", ], ) diff --git a/sphinxdocs/sphinxdocs/private/sphinx_stardoc.bzl b/sphinxdocs/sphinxdocs/private/sphinx_stardoc.bzl index ac76219299..75a4daf4d0 100644 --- a/sphinxdocs/sphinxdocs/private/sphinx_stardoc.bzl +++ b/sphinxdocs/sphinxdocs/private/sphinx_stardoc.bzl @@ -171,7 +171,7 @@ def sphinx_stardoc( **common_kwargs ) - stardoc_name = internal_name + "_stardoc" + stardoc_name = internal_name + "__stardoc" # NOTE: The .binaryproto suffix is an optimization. It makes the stardoc() # call avoid performing a copy of the output to the desired name. @@ -186,7 +186,7 @@ def sphinx_stardoc( **common_kwargs ) - pb2md_name = internal_name + "_pb2md" + pb2md_name = internal_name + "__pb2md" _stardoc_proto_to_markdown( name = pb2md_name, src = stardoc_pb, diff --git a/sphinxdocs/tests/sphinx_stardoc/BUILD.bazel b/sphinxdocs/tests/sphinx_stardoc/BUILD.bazel index a5d402b809..36472f12f5 100644 --- a/sphinxdocs/tests/sphinx_stardoc/BUILD.bazel +++ b/sphinxdocs/tests/sphinx_stardoc/BUILD.bazel @@ -1,4 +1,3 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@bazel_skylib//rules:build_test.bzl", "build_test") load("@rules_python//python:py_test.bzl", "py_test") load("//sphinxdocs:sphinx.bzl", "sphinx_build_binary", "sphinx_docs") @@ -48,8 +47,8 @@ build_test( sphinx_stardocs( name = "simple_bzl_docs", srcs = [ - ":bzl_rule_bzl", - ":bzl_typedef_bzl", + ":bzl_rule", + ":bzl_typedef", ], target_compatible_with = _TARGET_COMPATIBLE_WITH, ) @@ -58,7 +57,7 @@ sphinx_stardoc( name = "bzl_function", src = ":bzl_function.bzl", target_compatible_with = _TARGET_COMPATIBLE_WITH, - deps = [":func_and_providers_bzl"], + deps = [":func_and_providers"], ) sphinx_stardoc( @@ -66,34 +65,15 @@ sphinx_stardoc( src = ":bzl_providers.bzl", prefix = "addprefix_", target_compatible_with = _TARGET_COMPATIBLE_WITH, - deps = [":func_and_providers_bzl"], + deps = [":func_and_providers"], ) # A bzl_library with multiple sources -bzl_library( - name = "func_and_providers_bzl", - srcs = [ - "bzl_function.bzl", - "bzl_providers.bzl", - ], -) - -bzl_library( - name = "bzl_rule_bzl", - srcs = ["bzl_rule.bzl"], - deps = [":func_and_providers_bzl"], -) - -bzl_library( - name = "bzl_typedef_bzl", - srcs = ["bzl_typedef.bzl"], -) - sphinx_build_binary( name = "sphinx-build", tags = ["manual"], # Only needed as part of sphinx doc building deps = [ - "//sphinxdocs/src/sphinx_bzl", + "//sphinxdocs/src/sphinx", "@dev_pip//myst_parser", "@dev_pip//sphinx", "@dev_pip//typing_extensions", # Needed by sphinx_stardoc diff --git a/tests/BUILD.bazel b/tests/BUILD.bazel index e7dbef65d8..e5d9a58243 100644 --- a/tests/BUILD.bazel +++ b/tests/BUILD.bazel @@ -1,3 +1,4 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@bazel_skylib//rules:build_test.bzl", "build_test") package(default_visibility = ["//visibility:public"]) @@ -8,20 +9,26 @@ build_test( name = "bzl_libraries_build_test", targets = [ # keep sorted - "//python:current_py_toolchain_bzl", - "//python:defs_bzl", - "//python:proto_bzl", - "//python:py_binary_bzl", - "//python:py_cc_link_params_info_bzl", - "//python:py_import_bzl", - "//python:py_info_bzl", - "//python:py_library_bzl", - "//python:py_runtime_bzl", - "//python:py_runtime_info_bzl", - "//python:py_runtime_pair_bzl", - "//python:py_test_bzl", - "//python/cc:py_cc_toolchain_bzl", - "//python/cc:py_cc_toolchain_info_bzl", - "//python/entry_points:py_console_script_binary_bzl", + "//python:current_py_toolchain", + "//python:defs", + "//python:proto", + "//python:py_binary", + "//python:py_cc_link_params_info", + "//python:py_import", + "//python:py_info", + "//python:py_library", + "//python:py_runtime", + "//python:py_runtime_info", + "//python:py_runtime_pair", + "//python:py_test", + "//python/cc:py_cc_toolchain", + "//python/cc:py_cc_toolchain_info", + "//python/entry_points:py_console_script_binary", ], ) + +bzl_library( + name = "default_info_subject", + srcs = ["default_info_subject.bzl"], + deps = ["@rules_testing//lib/private:runfiles_subject"], +) diff --git a/tests/base_rules/BUILD.bazel b/tests/base_rules/BUILD.bazel index aa21042e25..5d97b3eac6 100644 --- a/tests/base_rules/BUILD.bazel +++ b/tests/base_rules/BUILD.bazel @@ -1,3 +1,5 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + # Copyright 2023 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -11,3 +13,10 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +bzl_library( + name = "util", + srcs = ["util.bzl"], + visibility = ["//visibility:public"], + deps = ["@bazel_skylib//lib:structs"], +) diff --git a/tests/entry_points/BUILD.bazel b/tests/entry_points/BUILD.bazel index c877462f54..e98a610f87 100644 --- a/tests/entry_points/BUILD.bazel +++ b/tests/entry_points/BUILD.bazel @@ -1,3 +1,5 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + # Copyright 2023 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -44,3 +46,10 @@ build_test( ":twine_pkg", ], ) + +bzl_library( + name = "simple_macro", + srcs = ["simple_macro.bzl"], + visibility = ["//visibility:public"], + deps = ["//python/entry_points:py_console_script_binary"], +) diff --git a/tests/integration/local_toolchains/BUILD.bazel b/tests/integration/local_toolchains/BUILD.bazel index 20ee7bcfe6..6e846ad0f5 100644 --- a/tests/integration/local_toolchains/BUILD.bazel +++ b/tests/integration/local_toolchains/BUILD.bazel @@ -1,3 +1,5 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + # Copyright 2024 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -85,3 +87,20 @@ py_test( srcs = ["echo_test.py"], deps = [":echo_ext"], ) + +bzl_library( + name = "py_extension", + srcs = ["py_extension.bzl"], + visibility = ["//visibility:public"], + deps = [ + "@bazel_skylib//rules:copy_file", + "@rules_cc//cc:cc_binary", + "@rules_python//python:defs", + ], +) + +bzl_library( + name = "pbs_archive", + srcs = ["pbs_archive.bzl"], + visibility = ["//visibility:public"], +) diff --git a/tests/integration/py_cc_toolchain_registered/BUILD.bazel b/tests/integration/py_cc_toolchain_registered/BUILD.bazel index 9c9275c7c1..c2d50143af 100644 --- a/tests/integration/py_cc_toolchain_registered/BUILD.bazel +++ b/tests/integration/py_cc_toolchain_registered/BUILD.bazel @@ -1,3 +1,5 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + # Copyright 2024 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,3 +19,9 @@ load(":defs.bzl", "py_cc_toolchain_available_test") # Simple test to verify that the py_cc_toolchain is registered and available # by default (for bzlmod) and when users setup a hermetic toolchain (workspace) py_cc_toolchain_available_test(name = "py_cc_toolchain_available_test") + +bzl_library( + name = "defs", + srcs = ["defs.bzl"], + visibility = ["//visibility:public"], +) diff --git a/tests/integration/uv_lock/BUILD.bazel b/tests/integration/uv_lock/BUILD.bazel index da6482ba08..0ba2272cce 100644 --- a/tests/integration/uv_lock/BUILD.bazel +++ b/tests/integration/uv_lock/BUILD.bazel @@ -1,3 +1,4 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@bazel_skylib//rules:diff_test.bzl", "diff_test") load("@rules_python//python/uv:lock.bzl", "lock") load(":uv_runner.bzl", "uv_runner") @@ -24,3 +25,9 @@ diff_test( file1 = ":requirements", file2 = ":requirements.txt", ) + +bzl_library( + name = "uv_runner", + srcs = ["uv_runner.bzl"], + visibility = ["//visibility:public"], +) diff --git a/tests/load_from_macro/BUILD.bazel b/tests/load_from_macro/BUILD.bazel index ecb5de51a7..40ea405d1c 100644 --- a/tests/load_from_macro/BUILD.bazel +++ b/tests/load_from_macro/BUILD.bazel @@ -1,3 +1,5 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + # Copyright 2019 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,3 +34,9 @@ genrule( cmd = "$(PYTHON3) --version > $(location out.txt)", toolchains = ["//python:current_py_toolchain"], ) + +bzl_library( + name = "tags", + srcs = ["tags.bzl"], + visibility = ["//visibility:public"], +) diff --git a/tests/pypi/extension/BUILD.bazel b/tests/pypi/extension/BUILD.bazel index 39000e8c1b..46ce2a3613 100644 --- a/tests/pypi/extension/BUILD.bazel +++ b/tests/pypi/extension/BUILD.bazel @@ -1,3 +1,5 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + # Copyright 2024 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,3 +17,9 @@ load(":extension_tests.bzl", "extension_test_suite") extension_test_suite(name = "extension_tests") + +bzl_library( + name = "pip_parse", + srcs = ["pip_parse.bzl"], + visibility = ["//visibility:public"], +) diff --git a/tests/pypi/integration/BUILD.bazel b/tests/pypi/integration/BUILD.bazel index 316abe8271..0971cb05f7 100644 --- a/tests/pypi/integration/BUILD.bazel +++ b/tests/pypi/integration/BUILD.bazel @@ -1,3 +1,4 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@bazel_skylib//rules:build_test.bzl", "build_test") load("@rules_python_publish_deps//:requirements.bzl", "all_requirements") @@ -5,3 +6,9 @@ build_test( name = "all_requirements_build_test", targets = all_requirements, ) + +bzl_library( + name = "transitions", + srcs = ["transitions.bzl"], + visibility = ["//visibility:public"], +) diff --git a/tests/pypi/whl_library/testdata/BUILD.bazel b/tests/pypi/whl_library/testdata/BUILD.bazel index e69de29bb2..fc9d518702 100644 --- a/tests/pypi/whl_library/testdata/BUILD.bazel +++ b/tests/pypi/whl_library/testdata/BUILD.bazel @@ -0,0 +1,7 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + +bzl_library( + name = "packages", + srcs = ["packages.bzl"], + visibility = ["//visibility:public"], +) diff --git a/tests/python_bzlmod_ext/BUILD.bazel b/tests/python_bzlmod_ext/BUILD.bazel index e266c01b9c..45006674b9 100644 --- a/tests/python_bzlmod_ext/BUILD.bazel +++ b/tests/python_bzlmod_ext/BUILD.bazel @@ -1,3 +1,4 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load(":test_helpers.bzl", "register_python_bzlmod_ext_tests") register_python_bzlmod_ext_tests( @@ -5,3 +6,14 @@ register_python_bzlmod_ext_tests( parse_runtime_manifest_name = "parse_runtime_manifest_tests", runtime_manifests_name = "runtime_manifests_tests", ) + +bzl_library( + name = "test_helpers", + srcs = ["test_helpers.bzl"], + visibility = ["//visibility:public"], + deps = [ + ":parse_runtime_manifest_tests", + ":runtime_manifests_tests", + "//python/private:bzlmod_enabled", + ], +) diff --git a/tests/support/BUILD.bazel b/tests/support/BUILD.bazel index 45f43c89e2..74a67f9169 100644 --- a/tests/support/BUILD.bazel +++ b/tests/support/BUILD.bazel @@ -1,3 +1,5 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + # Copyright 2023 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,3 +36,67 @@ config_setting( ":custom_runtime": "linux-x86-install-only-stripped", }, ) + +bzl_library( + name = "cc_info_subject", + srcs = ["cc_info_subject.bzl"], + deps = ["@rules_testing//lib:truth"], +) + +bzl_library( + name = "py_cc_toolchain_info_subject", + srcs = ["py_cc_toolchain_info_subject.bzl"], + deps = ["@rules_testing//lib:truth"], +) + +bzl_library( + name = "py_executable_info_subject", + srcs = ["py_executable_info_subject.bzl"], + deps = ["@rules_testing//lib:truth"], +) + +bzl_library( + name = "py_info_subject", + srcs = ["py_info_subject.bzl"], + deps = ["@rules_testing//lib:truth"], +) + +bzl_library( + name = "py_reconfig", + srcs = ["py_reconfig.bzl"], + deps = [ + ":support", + "//python/private:attr_builders", + "//python/private:common_labels", + "//python/private:py_binary_macro", + "//python/private:py_binary_rule", + "//python/private:py_test_macro", + "//python/private:py_test_rule", + "@rules_python_internal//:rules_python_config", + ], +) + +bzl_library( + name = "py_runtime_info_subject", + srcs = ["py_runtime_info_subject.bzl"], + deps = ["@rules_testing//lib:truth"], +) + +bzl_library( + name = "support", + srcs = ["support.bzl"], + deps = [ + "//python/private:bzlmod_enabled", + "@rules_python_internal//:rules_python_config", + ], +) + +bzl_library( + name = "copy_file", + srcs = ["copy_file.bzl"], +) + +bzl_library( + name = "mocks", + srcs = ["mocks.bzl"], +) diff --git a/tests/support/cc_toolchains/BUILD.bazel b/tests/support/cc_toolchains/BUILD.bazel index 1c1a714626..73d00e8e2a 100644 --- a/tests/support/cc_toolchains/BUILD.bazel +++ b/tests/support/cc_toolchains/BUILD.bazel @@ -1,3 +1,5 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + # Copyright 2023 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -172,3 +174,12 @@ fake_cc_toolchain_config( target_cpu = "windows_x86_64", toolchain_identifier = "windows-toolchain", ) + +bzl_library( + name = "fake_cc_toolchain_config", + srcs = ["fake_cc_toolchain_config.bzl"], + deps = [ + "@rules_cc//cc/common:cc_common", + "@rules_cc//cc/toolchains:cc_toolchain_config_info", + ], +) diff --git a/tests/support/mocks/BUILD.bazel b/tests/support/mocks/BUILD.bazel index 07bdb2bffc..bb6130e2ed 100644 --- a/tests/support/mocks/BUILD.bazel +++ b/tests/support/mocks/BUILD.bazel @@ -5,15 +5,15 @@ package( default_visibility = ["//:__subpackages__"], ) -bzl_library( - name = "mocks_bzl", - srcs = ["mocks.bzl"], -) +mocks_test_suite(name = "mocks_tests") bzl_library( - name = "python_ext_bzl", + name = "python_ext", srcs = ["python_ext.bzl"], - deps = [":mocks_bzl"], + deps = [":mocks"], ) -mocks_test_suite(name = "mocks_tests") +bzl_library( + name = "mocks", + srcs = ["mocks.bzl"], +) diff --git a/tests/support/platforms/BUILD.bazel b/tests/support/platforms/BUILD.bazel index eeb7ccb597..7e2ba49911 100644 --- a/tests/support/platforms/BUILD.bazel +++ b/tests/support/platforms/BUILD.bazel @@ -1,3 +1,5 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + package( default_visibility = ["//:__subpackages__"], ) @@ -83,3 +85,8 @@ platform( "@platforms//cpu:s390x", ], ) + +bzl_library( + name = "platforms", + srcs = ["platforms.bzl"], +) diff --git a/tests/support/whl_from_dir/BUILD.bazel b/tests/support/whl_from_dir/BUILD.bazel index e69de29bb2..e4a4d423d5 100644 --- a/tests/support/whl_from_dir/BUILD.bazel +++ b/tests/support/whl_from_dir/BUILD.bazel @@ -0,0 +1,8 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + +bzl_library( + name = "whl_from_dir_repo", + srcs = ["whl_from_dir_repo.bzl"], + visibility = ["//visibility:public"], + deps = ["//python/private:repo_utils"], +) diff --git a/tests/toolchains/BUILD.bazel b/tests/toolchains/BUILD.bazel index b336a06269..65e0153381 100644 --- a/tests/toolchains/BUILD.bazel +++ b/tests/toolchains/BUILD.bazel @@ -1,3 +1,5 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + # Copyright 2022 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -54,3 +56,20 @@ diff_test( file1 = "//python/private:runtimes_manifest_workspace.bzl", file2 = ":expected_runtimes_manifest_workspace.bzl", ) + +bzl_library( + name = "defs", + srcs = ["defs.bzl"], + visibility = ["//visibility:public"], + deps = [ + "//python:versions", + "//python/private:version", + "//tests/support:py_reconfig", + ], +) + +bzl_library( + name = "expected_runtimes_manifest_workspace", + srcs = ["expected_runtimes_manifest_workspace.bzl"], + visibility = ["//visibility:public"], +) diff --git a/tools/build_defs/python/private/BUILD.bazel b/tools/build_defs/python/private/BUILD.bazel index 746545640d..e5ac9c8a87 100644 --- a/tools/build_defs/python/private/BUILD.bazel +++ b/tools/build_defs/python/private/BUILD.bazel @@ -14,6 +14,11 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") +package(default_visibility = [ + "//python/private:__pkg__", + "//tools/build_defs/python:__subpackages__", +]) + filegroup( name = "distribution", srcs = glob(["**"]), @@ -21,7 +26,6 @@ filegroup( ) bzl_library( - name = "py_internal_renamed_bzl", + name = "py_internal_renamed", srcs = ["py_internal_renamed.bzl"], - visibility = ["//python/private:__pkg__"], ) diff --git a/tools/private/BUILD.bazel b/tools/private/BUILD.bazel index adc8de3b0f..ae6951c245 100644 --- a/tools/private/BUILD.bazel +++ b/tools/private/BUILD.bazel @@ -1,3 +1,5 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + package( default_visibility = ["//:__subpackages__"], ) @@ -8,3 +10,9 @@ filegroup( "//tools/private/zipapp:distribution", ], ) + +bzl_library( + name = "publish_deps", + srcs = ["publish_deps.bzl"], + deps = ["//python/uv/private:lock"], +) diff --git a/tools/private/update_deps/BUILD.bazel b/tools/private/update_deps/BUILD.bazel index beecf82189..c3f94c9814 100644 --- a/tools/private/update_deps/BUILD.bazel +++ b/tools/private/update_deps/BUILD.bazel @@ -34,10 +34,10 @@ py_binary( name = "update_coverage_deps", srcs = ["update_coverage_deps.py"], data = [ - "//python/private:coverage_deps", + "//python/private:coverage_deps_filegroup", ], env = { - "UPDATE_FILE": "$(rlocationpath //python/private:coverage_deps)", + "UPDATE_FILE": "$(rlocationpath //python/private:coverage_deps_filegroup)", }, imports = ["../../.."], deps = [ From d390ab4c12fa83b70a978fcaa57c438fc57d266e Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Fri, 26 Jun 2026 17:47:38 +0000 Subject: [PATCH 02/36] Refactor Gazelle integration and refine target structure based on feedback. Move the gazelle_binary to tools/private to avoid production dependencies, clean up package visibilities, interleave public aliases alphabetically, and restore necessary stardoc name collision shields. --- BUILD.bazel | 11 +- news/gazelle-bzl-library.changed.md | 7 +- python/BUILD.bazel | 262 ++++++++++---------- python/private/BUILD.bazel | 44 ++-- python/private/internal_config_repo.bzl | 10 - tools/build_defs/python/private/BUILD.bazel | 7 +- tools/private/BUILD.bazel | 8 + 7 files changed, 167 insertions(+), 182 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index b886945dd5..c1664ddb18 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("@bazel_gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary") +load("@bazel_gazelle//:def.bzl", "gazelle") load("@bazel_skylib//:bzl_library.bzl", "bzl_library") # gazelle:resolve starlark @rules_cc//cc/common:cc_info.bzl @rules_cc//cc/common:common @@ -75,16 +75,9 @@ filegroup( visibility = ["//visibility:public"], ) -gazelle_binary( - name = "gazelle_bin", - languages = DEFAULT_LANGUAGES + [ - "@bazel_skylib_gazelle_plugin//bzl", - ], -) - gazelle( name = "gazelle", - gazelle = ":gazelle_bin", + gazelle = "//tools/private:gazelle_bin", ) bzl_library( diff --git a/news/gazelle-bzl-library.changed.md b/news/gazelle-bzl-library.changed.md index 08b64ec124..bf2a44ce34 100644 --- a/news/gazelle-bzl-library.changed.md +++ b/news/gazelle-bzl-library.changed.md @@ -1,4 +1,3 @@ -(bzl_library) Migrated `bzl_library` targets to be managed by Gazelle using the -`bazel-skylib` Gazelle plugin. Public targets have been renamed to match their -file names (without the `_bzl` suffix), and deprecated aliases have been -created for backwards compatibility. +(bzl_library) Standardized `bzl_library` targets to match their corresponding +Starlark file names (removing the legacy `_bzl` suffix). Deprecated aliases +have been created for all public targets to ensure backwards compatibility. diff --git a/python/BUILD.bazel b/python/BUILD.bazel index 013f527aa5..47ac5d8fa6 100644 --- a/python/BUILD.bazel +++ b/python/BUILD.bazel @@ -184,6 +184,34 @@ bzl_library( visibility = ["//visibility:public"], ) +bzl_library( + name = "defs", + srcs = ["defs.bzl"], + deps = [ + ":py_binary", + ":py_import", + ":py_info", + ":py_library", + ":py_runtime", + ":py_runtime_info", + ":py_runtime_pair", + ":py_test", + "//python:current_py_toolchain_bzl", + ], +) + +alias( + name = "defs_bzl", + actual = ":defs", + deprecation = "Use //python:defs instead", +) + +alias( + name = "features_bzl", + actual = ":features", + deprecation = "Use //python:features instead", +) + bzl_library( name = "packaging", srcs = ["packaging.bzl"], @@ -197,6 +225,12 @@ bzl_library( ], ) +alias( + name = "packaging_bzl", + actual = ":packaging", + deprecation = "Use //python:packaging instead", +) + bzl_library( name = "pip", srcs = ["pip.bzl"], @@ -211,84 +245,174 @@ bzl_library( ], ) +alias( + name = "pip_bzl", + actual = ":pip", + deprecation = "Use //python:pip instead", +) + bzl_library( name = "proto", srcs = ["proto.bzl"], deps = ["@com_google_protobuf//bazel:py_proto_library_bzl"], ) +alias( + name = "proto_bzl", + actual = ":proto", + deprecation = "Use //python:proto instead", +) + bzl_library( name = "py_binary", srcs = ["py_binary.bzl"], deps = ["//python/private:py_binary_macro"], ) +alias( + name = "py_binary_bzl", + actual = ":py_binary", + deprecation = "Use //python:py_binary instead", +) + bzl_library( name = "py_cc_link_params_info", srcs = ["py_cc_link_params_info.bzl"], deps = ["//python/private:py_cc_link_params_info"], ) +alias( + name = "py_cc_link_params_info_bzl", + actual = ":py_cc_link_params_info", + deprecation = "Use //python:py_cc_link_params_info instead", +) + bzl_library( name = "py_exec_tools_info", srcs = ["py_exec_tools_info.bzl"], deps = ["//python/private:py_exec_tools_info"], ) +alias( + name = "py_exec_tools_info_bzl", + actual = ":py_exec_tools_info", + deprecation = "Use //python:py_exec_tools_info instead", +) + bzl_library( name = "py_exec_tools_toolchain", srcs = ["py_exec_tools_toolchain.bzl"], deps = ["//python/private:py_exec_tools_toolchain"], ) +alias( + name = "py_exec_tools_toolchain_bzl", + actual = ":py_exec_tools_toolchain", + deprecation = "Use //python:py_exec_tools_toolchain instead", +) + bzl_library( name = "py_executable_info", srcs = ["py_executable_info.bzl"], deps = ["//python/private:py_executable_info"], ) +alias( + name = "py_executable_info_bzl", + actual = ":py_executable_info", + deprecation = "Use //python:py_executable_info instead", +) + bzl_library( name = "py_import", srcs = ["py_import.bzl"], deps = [":py_info"], ) +alias( + name = "py_import_bzl", + actual = ":py_import", + deprecation = "Use //python:py_import instead", +) + bzl_library( name = "py_info", srcs = ["py_info.bzl"], deps = ["//python/private:py_info"], ) +alias( + name = "py_info_bzl", + actual = ":py_info", + deprecation = "Use //python:py_info instead", +) + bzl_library( name = "py_library", srcs = ["py_library.bzl"], deps = ["//python/private:py_library_macro"], ) +alias( + name = "py_library_bzl", + actual = ":py_library", + deprecation = "Use //python:py_library instead", +) + bzl_library( name = "py_runtime", srcs = ["py_runtime.bzl"], deps = ["//python/private:py_runtime_macro"], ) +alias( + name = "py_runtime_bzl", + actual = ":py_runtime", + deprecation = "Use //python:py_runtime instead", +) + bzl_library( name = "py_runtime_info", srcs = ["py_runtime_info.bzl"], deps = ["//python/private:py_runtime_info"], ) +alias( + name = "py_runtime_info_bzl", + actual = ":py_runtime_info", + deprecation = "Use //python:py_runtime_info instead", +) + bzl_library( name = "py_runtime_pair", srcs = ["py_runtime_pair.bzl"], deps = ["//python/private:py_runtime_pair_macro"], ) +alias( + name = "py_runtime_pair_bzl", + actual = ":py_runtime_pair", + deprecation = "Use //python:py_runtime_pair instead", +) + bzl_library( name = "py_test", srcs = ["py_test.bzl"], deps = ["//python/private:py_test_macro"], ) +alias( + name = "py_test_bzl", + actual = ":py_test", + deprecation = "Use //python:py_test instead", +) + +alias( + name = "python_bzl", + actual = ":python", + deprecation = "Use //python:python instead", +) + bzl_library( name = "repositories", srcs = ["repositories.bzl"], @@ -301,6 +425,12 @@ bzl_library( ], ) +alias( + name = "repositories_bzl", + actual = ":repositories", + deprecation = "Use //python:repositories instead", +) + bzl_library( name = "versions", srcs = ["versions.bzl"], @@ -311,144 +441,12 @@ bzl_library( ], ) -# ========= Deprecated aliases for backwards compatibility ========= - -alias( - name = "defs_bzl", - actual = ":defs", - deprecation = "Use //python:defs instead", -) - -alias( - name = "packaging_bzl", - actual = ":packaging", - deprecation = "Use //python:packaging instead", -) - -alias( - name = "pip_bzl", - actual = ":pip", - deprecation = "Use //python:pip instead", -) - -alias( - name = "proto_bzl", - actual = ":proto", - deprecation = "Use //python:proto instead", -) - -alias( - name = "py_binary_bzl", - actual = ":py_binary", - deprecation = "Use //python:py_binary instead", -) - -alias( - name = "py_cc_link_params_info_bzl", - actual = ":py_cc_link_params_info", - deprecation = "Use //python:py_cc_link_params_info instead", -) - -alias( - name = "py_exec_tools_info_bzl", - actual = ":py_exec_tools_info", - deprecation = "Use //python:py_exec_tools_info instead", -) - -alias( - name = "py_exec_tools_toolchain_bzl", - actual = ":py_exec_tools_toolchain", - deprecation = "Use //python:py_exec_tools_toolchain instead", -) - -alias( - name = "py_executable_info_bzl", - actual = ":py_executable_info", - deprecation = "Use //python:py_executable_info instead", -) - -alias( - name = "py_import_bzl", - actual = ":py_import", - deprecation = "Use //python:py_import instead", -) - -alias( - name = "py_info_bzl", - actual = ":py_info", - deprecation = "Use //python:py_info instead", -) - -alias( - name = "py_library_bzl", - actual = ":py_library", - deprecation = "Use //python:py_library instead", -) - -alias( - name = "py_runtime_bzl", - actual = ":py_runtime", - deprecation = "Use //python:py_runtime instead", -) - -alias( - name = "py_runtime_info_bzl", - actual = ":py_runtime_info", - deprecation = "Use //python:py_runtime_info instead", -) - -alias( - name = "py_runtime_pair_bzl", - actual = ":py_runtime_pair", - deprecation = "Use //python:py_runtime_pair instead", -) - -alias( - name = "py_test_bzl", - actual = ":py_test", - deprecation = "Use //python:py_test instead", -) - -alias( - name = "repositories_bzl", - actual = ":repositories", - deprecation = "Use //python:repositories instead", -) - alias( name = "versions_bzl", actual = ":versions", deprecation = "Use //python:versions instead", ) -alias( - name = "features_bzl", - actual = ":features", - deprecation = "Use //python:features instead", -) - -alias( - name = "python_bzl", - actual = ":python", - deprecation = "Use //python:python instead", -) - -bzl_library( - name = "defs", - srcs = ["defs.bzl"], - deps = [ - ":py_binary", - ":py_import", - ":py_info", - ":py_library", - ":py_runtime", - ":py_runtime_info", - ":py_runtime_pair", - ":py_test", - "//python:current_py_toolchain_bzl", - ], -) - bzl_library( name = "features", srcs = ["features.bzl"], diff --git a/python/private/BUILD.bazel b/python/private/BUILD.bazel index c74ff388e8..ee12e6dc79 100644 --- a/python/private/BUILD.bazel +++ b/python/private/BUILD.bazel @@ -881,16 +881,6 @@ bzl_library( deps = ["//python/private:bazel_tools"], ) -bzl_library( - name = "bzlmod_enabled", - srcs = ["bzlmod_enabled.bzl"], -) - -bzl_library( - name = "common_labels", - srcs = ["common_labels.bzl"], -) - bzl_library( name = "coverage_deps", srcs = ["coverage_deps.bzl"], @@ -901,6 +891,28 @@ bzl_library( ], ) +bzl_library( + name = "py_repositories", + srcs = ["py_repositories.bzl"], + deps = [ + ":internal_config_repo", + ":pythons_hub", + "//python:versions", + "//python/private:bazel_tools", + "//python/private/pypi:deps", + ], +) + +bzl_library( + name = "bzlmod_enabled", + srcs = ["bzlmod_enabled.bzl"], +) + +bzl_library( + name = "common_labels", + srcs = ["common_labels.bzl"], +) + bzl_library( name = "enum", srcs = ["enum.bzl"], @@ -951,18 +963,6 @@ bzl_library( srcs = ["py_executable_info.bzl"], ) -bzl_library( - name = "py_repositories", - srcs = ["py_repositories.bzl"], - deps = [ - ":internal_config_repo", - ":pythons_hub", - "//python:versions", - "//python/private:bazel_tools", - "//python/private/pypi:deps", - ], -) - bzl_library( name = "py_runtime_info", srcs = ["py_runtime_info.bzl"], diff --git a/python/private/internal_config_repo.bzl b/python/private/internal_config_repo.bzl index 78d0b35e12..9bae0a5821 100644 --- a/python/private/internal_config_repo.bzl +++ b/python/private/internal_config_repo.bzl @@ -53,20 +53,10 @@ bzl_library( srcs = ["extra_transition_settings.bzl"], ) -alias( - name = "extra_transition_settings_bzl", - actual = ":extra_transition_settings", -) - bzl_library( name = "rules_python_config", srcs = ["rules_python_config.bzl"], ) - -alias( - name = "rules_python_config_bzl", - actual = ":rules_python_config", -) """ _EXTRA_TRANSITIONS_TEMPLATE = """ diff --git a/tools/build_defs/python/private/BUILD.bazel b/tools/build_defs/python/private/BUILD.bazel index e5ac9c8a87..bb15727346 100644 --- a/tools/build_defs/python/private/BUILD.bazel +++ b/tools/build_defs/python/private/BUILD.bazel @@ -14,18 +14,15 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") -package(default_visibility = [ - "//python/private:__pkg__", - "//tools/build_defs/python:__subpackages__", -]) - filegroup( name = "distribution", srcs = glob(["**"]), visibility = ["//python:__subpackages__"], ) +# keep bzl_library( name = "py_internal_renamed", srcs = ["py_internal_renamed.bzl"], + visibility = ["//python/private:__pkg__"], ) diff --git a/tools/private/BUILD.bazel b/tools/private/BUILD.bazel index ae6951c245..fbf8bc9f42 100644 --- a/tools/private/BUILD.bazel +++ b/tools/private/BUILD.bazel @@ -1,3 +1,4 @@ +load("@bazel_gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle_binary") load("@bazel_skylib//:bzl_library.bzl", "bzl_library") package( @@ -16,3 +17,10 @@ bzl_library( srcs = ["publish_deps.bzl"], deps = ["//python/uv/private:lock"], ) + +gazelle_binary( + name = "gazelle_bin", + languages = DEFAULT_LANGUAGES + [ + "@bazel_skylib_gazelle_plugin//bzl", + ], +) From c80e3af29969cfc2a8c6e5bfba6a33cd50aa60cb Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Fri, 26 Jun 2026 18:53:19 +0000 Subject: [PATCH 03/36] Relocate Gazelle targets entirely to a private subpackage and rename clashing Starlark files to simplify build structure. Move all Gazelle loads and targets to tools/private/gazelle, and rename private stamp and sentinel Starlark files to stamp_impl and sentinel_impl to naturally avoid target name collisions without manual overrides. --- BUILD.bazel | 6 - news/gazelle-bzl-library.changed.md | 6 +- python/private/BUILD.bazel | 154 +++++++++--------- python/private/interpreter.bzl | 2 +- python/private/py_cc_toolchain_rule.bzl | 2 +- python/private/py_exec_tools_toolchain.bzl | 2 +- python/private/py_interpreter_program.bzl | 2 +- python/private/py_wheel.bzl | 2 +- .../{sentinel.bzl => sentinel_impl.bzl} | 0 python/private/{stamp.bzl => stamp_impl.bzl} | 0 tools/private/BUILD.bazel | 8 - tools/private/gazelle/BUILD.bazel | 17 ++ 12 files changed, 98 insertions(+), 103 deletions(-) rename python/private/{sentinel.bzl => sentinel_impl.bzl} (100%) rename python/private/{stamp.bzl => stamp_impl.bzl} (100%) create mode 100644 tools/private/gazelle/BUILD.bazel diff --git a/BUILD.bazel b/BUILD.bazel index c1664ddb18..ec9e989e04 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("@bazel_gazelle//:def.bzl", "gazelle") load("@bazel_skylib//:bzl_library.bzl", "bzl_library") # gazelle:resolve starlark @rules_cc//cc/common:cc_info.bzl @rules_cc//cc/common:common @@ -75,11 +74,6 @@ filegroup( visibility = ["//visibility:public"], ) -gazelle( - name = "gazelle", - gazelle = "//tools/private:gazelle_bin", -) - bzl_library( name = "internal_dev_deps", srcs = ["internal_dev_deps.bzl"], diff --git a/news/gazelle-bzl-library.changed.md b/news/gazelle-bzl-library.changed.md index bf2a44ce34..0d602110e3 100644 --- a/news/gazelle-bzl-library.changed.md +++ b/news/gazelle-bzl-library.changed.md @@ -1,3 +1,3 @@ -(bzl_library) Standardized `bzl_library` targets to match their corresponding -Starlark file names (removing the legacy `_bzl` suffix). Deprecated aliases -have been created for all public targets to ensure backwards compatibility. +Renamed most public bzl_library targets from `{foo}_bzl` to `{foo}` to follow +gazelle naming conventions. Deprecated aliases are left for backwards +compatibility. diff --git a/python/private/BUILD.bazel b/python/private/BUILD.bazel index ee12e6dc79..e06ca9f3c4 100644 --- a/python/private/BUILD.bazel +++ b/python/private/BUILD.bazel @@ -18,16 +18,10 @@ load("//python:py_binary.bzl", "py_binary") load("//python:py_library.bzl", "py_library") load(":bazel_config_mode.bzl", "bazel_config_mode") load(":py_exec_tools_toolchain.bzl", "current_interpreter_executable") -load(":sentinel.bzl", "sentinel") -load(":stamp.bzl", "stamp_build_setting") +load(":sentinel_impl.bzl", "sentinel") +load(":stamp_impl.bzl", "stamp_build_setting") load(":uncachable_version_file.bzl", "define_uncachable_version_file") -# gazelle:exclude sentinel.bzl -# gazelle:resolve starlark @rules_python//python/private:sentinel.bzl //python/private:sentinel_bzl -# gazelle:resolve starlark //python/private:sentinel.bzl //python/private:sentinel_bzl -# gazelle:resolve starlark @rules_python//python/private:stamp.bzl //python/private:stamp_bzl -# gazelle:resolve starlark //python/private:stamp.bzl //python/private:stamp_bzl - package( default_visibility = [ "//:__subpackages__", @@ -76,18 +70,6 @@ alias( }), ) -# keep -bzl_library( - name = "sentinel_bzl", - srcs = ["sentinel.bzl"], -) - -# keep -bzl_library( - name = "stamp_bzl", - srcs = ["stamp.bzl"], -) - define_uncachable_version_file( name = "uncachable_version_file", ) @@ -134,7 +116,7 @@ exports_files( "py_wheel.bzl", "version.bzl", "reexports.bzl", - "stamp.bzl", + "stamp_impl.bzl", "util.bzl", ], visibility = ["//:__subpackages__"], @@ -409,18 +391,6 @@ bzl_library( ], ) -bzl_library( - name = "interpreter", - srcs = ["interpreter.bzl"], - deps = [ - ":common", - ":toolchain_types", - "//python:py_runtime_info", - "//python/private:sentinel_bzl", - "@bazel_skylib//lib:paths", - ], -) - bzl_library( name = "is_standalone_interpreter", srcs = ["is_standalone_interpreter.bzl"], @@ -504,18 +474,6 @@ bzl_library( ], ) -bzl_library( - name = "py_cc_toolchain_rule", - srcs = ["py_cc_toolchain_rule.bzl"], - deps = [ - ":common_labels", - ":py_cc_toolchain_info", - "//python/private:sentinel_bzl", - "@bazel_skylib//rules:common_settings", - "@rules_cc//cc/common", - ], -) - bzl_library( name = "py_console_script_binary", srcs = ["py_console_script_binary.bzl"], @@ -525,19 +483,6 @@ bzl_library( ], ) -bzl_library( - name = "py_exec_tools_toolchain", - srcs = ["py_exec_tools_toolchain.bzl"], - deps = [ - ":common_labels", - ":py_exec_tools_info", - ":toolchain_types", - "//python/private:sentinel_bzl", - "@bazel_skylib//lib:paths", - "@bazel_skylib//rules:common_settings", - ], -) - bzl_library( name = "py_executable", srcs = ["py_executable.bzl"], @@ -584,15 +529,6 @@ bzl_library( deps = ["//tools/build_defs/python/private:py_internal_renamed"], ) -bzl_library( - name = "py_interpreter_program", - srcs = ["py_interpreter_program.bzl"], - deps = [ - "//python/private:sentinel_bzl", - "@bazel_skylib//rules:common_settings", - ], -) - bzl_library( name = "py_library", srcs = ["py_library.bzl"], @@ -861,20 +797,6 @@ bzl_library( ], ) -bzl_library( - name = "py_wheel", - srcs = ["py_wheel.bzl"], - deps = [ - ":attributes", - ":py_info", - ":py_package", - ":rule_builders", - ":transition_labels", - ":version", - "//python/private:stamp_bzl", - ], -) - bzl_library( name = "auth", srcs = ["auth.bzl"], @@ -903,6 +825,20 @@ bzl_library( ], ) +bzl_library( + name = "py_wheel", + srcs = ["py_wheel.bzl"], + deps = [ + ":attributes", + ":py_info", + ":py_package", + ":rule_builders", + ":stamp_impl", + ":transition_labels", + ":version", + ], +) + bzl_library( name = "bzlmod_enabled", srcs = ["bzlmod_enabled.bzl"], @@ -928,6 +864,18 @@ bzl_library( srcs = ["full_version.bzl"], ) +bzl_library( + name = "interpreter", + srcs = ["interpreter.bzl"], + deps = [ + ":common", + ":sentinel_impl", + ":toolchain_types", + "//python:py_runtime_info", + "@bazel_skylib//lib:paths", + ], +) + bzl_library( name = "normalize_name", srcs = ["normalize_name.bzl"], @@ -948,6 +896,18 @@ bzl_library( srcs = ["py_cc_toolchain_info.bzl"], ) +bzl_library( + name = "py_cc_toolchain_rule", + srcs = ["py_cc_toolchain_rule.bzl"], + deps = [ + ":common_labels", + ":py_cc_toolchain_info", + ":sentinel_impl", + "@bazel_skylib//rules:common_settings", + "@rules_cc//cc/common", + ], +) + bzl_library( name = "py_console_script_gen", srcs = ["py_console_script_gen.bzl"], @@ -958,11 +918,33 @@ bzl_library( srcs = ["py_exec_tools_info.bzl"], ) +bzl_library( + name = "py_exec_tools_toolchain", + srcs = ["py_exec_tools_toolchain.bzl"], + deps = [ + ":common_labels", + ":py_exec_tools_info", + ":sentinel_impl", + ":toolchain_types", + "@bazel_skylib//lib:paths", + "@bazel_skylib//rules:common_settings", + ], +) + bzl_library( name = "py_executable_info", srcs = ["py_executable_info.bzl"], ) +bzl_library( + name = "py_interpreter_program", + srcs = ["py_interpreter_program.bzl"], + deps = [ + ":sentinel_impl", + "@bazel_skylib//rules:common_settings", + ], +) + bzl_library( name = "py_runtime_info", srcs = ["py_runtime_info.bzl"], @@ -978,6 +960,16 @@ bzl_library( srcs = ["runtimes_manifest_workspace.bzl"], ) +bzl_library( + name = "sentinel_impl", + srcs = ["sentinel_impl.bzl"], +) + +bzl_library( + name = "stamp_impl", + srcs = ["stamp_impl.bzl"], +) + bzl_library( name = "text_util", srcs = ["text_util.bzl"], diff --git a/python/private/interpreter.bzl b/python/private/interpreter.bzl index c66d3dc21e..b281be9639 100644 --- a/python/private/interpreter.bzl +++ b/python/private/interpreter.bzl @@ -17,7 +17,7 @@ load("@bazel_skylib//lib:paths.bzl", "paths") load("//python:py_runtime_info.bzl", "PyRuntimeInfo") load(":common.bzl", "runfiles_root_path") -load(":sentinel.bzl", "SentinelInfo") +load(":sentinel_impl.bzl", "SentinelInfo") load(":toolchain_types.bzl", "TARGET_TOOLCHAIN_TYPE") def _interpreter_binary_impl(ctx): diff --git a/python/private/py_cc_toolchain_rule.bzl b/python/private/py_cc_toolchain_rule.bzl index b89ea0e6b0..315de2d3f2 100644 --- a/python/private/py_cc_toolchain_rule.bzl +++ b/python/private/py_cc_toolchain_rule.bzl @@ -22,7 +22,7 @@ load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") load(":common_labels.bzl", "labels") load(":py_cc_toolchain_info.bzl", "PyCcToolchainInfo") -load(":sentinel.bzl", "SentinelInfo") +load(":sentinel_impl.bzl", "SentinelInfo") def _py_cc_toolchain_impl(ctx): if ctx.attr.libs: diff --git a/python/private/py_exec_tools_toolchain.bzl b/python/private/py_exec_tools_toolchain.bzl index ec8d4e53d0..d126262033 100644 --- a/python/private/py_exec_tools_toolchain.bzl +++ b/python/private/py_exec_tools_toolchain.bzl @@ -18,7 +18,7 @@ load("@bazel_skylib//lib:paths.bzl", "paths") load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") load(":common_labels.bzl", "labels") load(":py_exec_tools_info.bzl", "PyExecToolsInfo") -load(":sentinel.bzl", "SentinelInfo") +load(":sentinel_impl.bzl", "SentinelInfo") load(":toolchain_types.bzl", "TARGET_TOOLCHAIN_TYPE") def _py_exec_tools_toolchain_impl(ctx): diff --git a/python/private/py_interpreter_program.bzl b/python/private/py_interpreter_program.bzl index 7eb3e28bd9..1f1abb1bfe 100644 --- a/python/private/py_interpreter_program.bzl +++ b/python/private/py_interpreter_program.bzl @@ -15,7 +15,7 @@ """Internal only bootstrap level binary-like rule.""" load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") -load("//python/private:sentinel.bzl", "SentinelInfo") +load("//python/private:sentinel_impl.bzl", "SentinelInfo") PyInterpreterProgramInfo = provider( doc = "Information about how to run a program with an external interpreter.", diff --git a/python/private/py_wheel.bzl b/python/private/py_wheel.bzl index 1ca344c086..b622411c56 100644 --- a/python/private/py_wheel.bzl +++ b/python/private/py_wheel.bzl @@ -18,7 +18,7 @@ load(":attributes.bzl", "CONFIG_SETTINGS_ATTR", "apply_config_settings_attr") load(":py_info.bzl", "PyInfo") load(":py_package.bzl", "py_package_lib") load(":rule_builders.bzl", "ruleb") -load(":stamp.bzl", "is_stamping_enabled") +load(":stamp_impl.bzl", "is_stamping_enabled") load(":transition_labels.bzl", "TRANSITION_LABELS") load(":version.bzl", "version") diff --git a/python/private/sentinel.bzl b/python/private/sentinel_impl.bzl similarity index 100% rename from python/private/sentinel.bzl rename to python/private/sentinel_impl.bzl diff --git a/python/private/stamp.bzl b/python/private/stamp_impl.bzl similarity index 100% rename from python/private/stamp.bzl rename to python/private/stamp_impl.bzl diff --git a/tools/private/BUILD.bazel b/tools/private/BUILD.bazel index fbf8bc9f42..ae6951c245 100644 --- a/tools/private/BUILD.bazel +++ b/tools/private/BUILD.bazel @@ -1,4 +1,3 @@ -load("@bazel_gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle_binary") load("@bazel_skylib//:bzl_library.bzl", "bzl_library") package( @@ -17,10 +16,3 @@ bzl_library( srcs = ["publish_deps.bzl"], deps = ["//python/uv/private:lock"], ) - -gazelle_binary( - name = "gazelle_bin", - languages = DEFAULT_LANGUAGES + [ - "@bazel_skylib_gazelle_plugin//bzl", - ], -) diff --git a/tools/private/gazelle/BUILD.bazel b/tools/private/gazelle/BUILD.bazel new file mode 100644 index 0000000000..4472d13cfd --- /dev/null +++ b/tools/private/gazelle/BUILD.bazel @@ -0,0 +1,17 @@ +load("@bazel_gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary") + +package( + default_visibility = ["//:__subpackages__"], +) + +gazelle_binary( + name = "gazelle_bin", + languages = DEFAULT_LANGUAGES + [ + "@bazel_skylib_gazelle_plugin//bzl", + ], +) + +gazelle( + name = "gazelle", + gazelle = ":gazelle_bin", +) From 01c42ac80740fea09abe247c44a1f2d3d3a1654e Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Fri, 26 Jun 2026 19:27:12 +0000 Subject: [PATCH 04/36] Restrict visibility of internal dev targets in root BUILD.bazel to subpackages. Add explicit visibility attributes to internal_dev_deps, internal_dev_setup, and version targets to prevent them from being public by default. --- BUILD.bazel | 4 ++ python/private/BUILD.bazel | 92 +++++++++++++++++++------------------- 2 files changed, 50 insertions(+), 46 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index ec9e989e04..1dc8b4f474 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -77,6 +77,7 @@ filegroup( bzl_library( name = "internal_dev_deps", srcs = ["internal_dev_deps.bzl"], + visibility = ["//:__subpackages__"], deps = [ "//python/private:internal_config_repo", "@bazel_tools//tools/build_defs/repo:http.bzl", @@ -88,6 +89,7 @@ bzl_library( bzl_library( name = "internal_dev_setup", srcs = ["internal_dev_setup.bzl"], + visibility = ["//:__subpackages__"], deps = [ ":version", "//python:versions", @@ -106,7 +108,9 @@ bzl_library( ], ) +# keep bzl_library( name = "version", srcs = ["version.bzl"], + visibility = ["//:__subpackages__"], ) diff --git a/python/private/BUILD.bazel b/python/private/BUILD.bazel index e06ca9f3c4..91410d5f5c 100644 --- a/python/private/BUILD.bazel +++ b/python/private/BUILD.bazel @@ -839,6 +839,52 @@ bzl_library( ], ) +bzl_library( + name = "interpreter", + srcs = ["interpreter.bzl"], + deps = [ + ":common", + ":sentinel_impl", + ":toolchain_types", + "//python:py_runtime_info", + "@bazel_skylib//lib:paths", + ], +) + +bzl_library( + name = "py_cc_toolchain_rule", + srcs = ["py_cc_toolchain_rule.bzl"], + deps = [ + ":common_labels", + ":py_cc_toolchain_info", + ":sentinel_impl", + "@bazel_skylib//rules:common_settings", + "@rules_cc//cc/common", + ], +) + +bzl_library( + name = "py_exec_tools_toolchain", + srcs = ["py_exec_tools_toolchain.bzl"], + deps = [ + ":common_labels", + ":py_exec_tools_info", + ":sentinel_impl", + ":toolchain_types", + "@bazel_skylib//lib:paths", + "@bazel_skylib//rules:common_settings", + ], +) + +bzl_library( + name = "py_interpreter_program", + srcs = ["py_interpreter_program.bzl"], + deps = [ + ":sentinel_impl", + "@bazel_skylib//rules:common_settings", + ], +) + bzl_library( name = "bzlmod_enabled", srcs = ["bzlmod_enabled.bzl"], @@ -864,18 +910,6 @@ bzl_library( srcs = ["full_version.bzl"], ) -bzl_library( - name = "interpreter", - srcs = ["interpreter.bzl"], - deps = [ - ":common", - ":sentinel_impl", - ":toolchain_types", - "//python:py_runtime_info", - "@bazel_skylib//lib:paths", - ], -) - bzl_library( name = "normalize_name", srcs = ["normalize_name.bzl"], @@ -896,18 +930,6 @@ bzl_library( srcs = ["py_cc_toolchain_info.bzl"], ) -bzl_library( - name = "py_cc_toolchain_rule", - srcs = ["py_cc_toolchain_rule.bzl"], - deps = [ - ":common_labels", - ":py_cc_toolchain_info", - ":sentinel_impl", - "@bazel_skylib//rules:common_settings", - "@rules_cc//cc/common", - ], -) - bzl_library( name = "py_console_script_gen", srcs = ["py_console_script_gen.bzl"], @@ -918,33 +940,11 @@ bzl_library( srcs = ["py_exec_tools_info.bzl"], ) -bzl_library( - name = "py_exec_tools_toolchain", - srcs = ["py_exec_tools_toolchain.bzl"], - deps = [ - ":common_labels", - ":py_exec_tools_info", - ":sentinel_impl", - ":toolchain_types", - "@bazel_skylib//lib:paths", - "@bazel_skylib//rules:common_settings", - ], -) - bzl_library( name = "py_executable_info", srcs = ["py_executable_info.bzl"], ) -bzl_library( - name = "py_interpreter_program", - srcs = ["py_interpreter_program.bzl"], - deps = [ - ":sentinel_impl", - "@bazel_skylib//rules:common_settings", - ], -) - bzl_library( name = "py_runtime_info", srcs = ["py_runtime_info.bzl"], From 1e61956124f1de79526e9589f9510bd25e386e1b Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Fri, 26 Jun 2026 19:35:09 +0000 Subject: [PATCH 05/36] Exclude the tests directory from Gazelle Starlark target generation and add safety keep shields to public test-related targets. This ensures test targets are not incorrectly managed or pruned by Gazelle. --- BUILD.bazel | 1 + gazelle/python/BUILD.bazel | 1 + python/BUILD.bazel | 1 + python/zipapp/BUILD.bazel | 1 + 4 files changed, 4 insertions(+) diff --git a/BUILD.bazel b/BUILD.bazel index 1dc8b4f474..44c15f6c7f 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -19,6 +19,7 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") # gazelle:resolve starlark @com_google_protobuf//bazel:py_proto_library.bzl @com_google_protobuf//bazel:py_proto_library_bzl # 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 +# gazelle:exclude tests package(default_visibility = ["//visibility:public"]) diff --git a/gazelle/python/BUILD.bazel b/gazelle/python/BUILD.bazel index a98eddb83c..6a73e55b15 100644 --- a/gazelle/python/BUILD.bazel +++ b/gazelle/python/BUILD.bazel @@ -124,6 +124,7 @@ go_test( ], ) +# keep bzl_library( name = "gazelle_test", srcs = ["gazelle_test.bzl"], diff --git a/python/BUILD.bazel b/python/BUILD.bazel index 47ac5d8fa6..a3d95edd05 100644 --- a/python/BUILD.bazel +++ b/python/BUILD.bazel @@ -395,6 +395,7 @@ alias( deprecation = "Use //python:py_runtime_pair instead", ) +# keep bzl_library( name = "py_test", srcs = ["py_test.bzl"], diff --git a/python/zipapp/BUILD.bazel b/python/zipapp/BUILD.bazel index 5e8c51171b..77a8752701 100644 --- a/python/zipapp/BUILD.bazel +++ b/python/zipapp/BUILD.bazel @@ -19,6 +19,7 @@ bzl_library( ], ) +# keep bzl_library( name = "py_zipapp_test", srcs = ["py_zipapp_test.bzl"], From 59a3281281b1e93eb7adc082acc20fb7c775ce2c Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Fri, 26 Jun 2026 19:44:22 +0000 Subject: [PATCH 06/36] Add explanatory comment to the toml.bzl Gazelle resolution override in the root BUILD file. This documents the Gazelle suffix-stripping bug for future maintainers. --- BUILD.bazel | 1 + 1 file changed, 1 insertion(+) diff --git a/BUILD.bazel b/BUILD.bazel index bcc715222a..ac16a5fa20 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -19,6 +19,7 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") # gazelle:resolve starlark @com_google_protobuf//bazel:py_proto_library.bzl @com_google_protobuf//bazel:py_proto_library_bzl # 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 # gazelle:resolve starlark @toml.bzl//:toml.bzl @toml.bzl//:toml # gazelle:exclude tests From 8254ca87aa12bed7cfd1be31c119b068045399d5 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Fri, 26 Jun 2026 19:53:44 +0000 Subject: [PATCH 07/36] Exclude examples directory from Gazelle and revert all Gazelle-generated changes in tests and examples directories to match upstream. This ensures these directories remain completely untouched by the Gazelle migration. --- BUILD.bazel | 1 + examples/pip_parse_vendored/BUILD.bazel | 9 +-- examples/wheel/private/BUILD.bazel | 7 -- tests/BUILD.bazel | 37 +++++------ tests/base_rules/BUILD.bazel | 9 --- tests/entry_points/BUILD.bazel | 9 --- .../integration/local_toolchains/BUILD.bazel | 19 ------ .../py_cc_toolchain_registered/BUILD.bazel | 8 --- tests/integration/uv_lock/BUILD.bazel | 7 -- tests/load_from_macro/BUILD.bazel | 8 --- tests/pypi/extension/BUILD.bazel | 8 --- tests/pypi/integration/BUILD.bazel | 7 -- tests/pypi/whl_library/testdata/BUILD.bazel | 7 -- tests/python_bzlmod_ext/BUILD.bazel | 12 ---- tests/support/BUILD.bazel | 66 ------------------- tests/support/cc_toolchains/BUILD.bazel | 11 ---- tests/support/mocks/BUILD.bazel | 14 ++-- tests/support/platforms/BUILD.bazel | 7 -- tests/support/whl_from_dir/BUILD.bazel | 8 --- tests/toolchains/BUILD.bazel | 19 ------ 20 files changed, 24 insertions(+), 249 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index ac16a5fa20..8699efe511 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -22,6 +22,7 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") # Prevent Gazelle from incorrectly stripping the .bzl suffix from the toml.bzl repo name # gazelle:resolve starlark @toml.bzl//:toml.bzl @toml.bzl//:toml # gazelle:exclude tests +# gazelle:exclude examples package(default_visibility = ["//visibility:public"]) diff --git a/examples/pip_parse_vendored/BUILD.bazel b/examples/pip_parse_vendored/BUILD.bazel index 7e39983b93..74b9286359 100644 --- a/examples/pip_parse_vendored/BUILD.bazel +++ b/examples/pip_parse_vendored/BUILD.bazel @@ -1,4 +1,3 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@bazel_skylib//rules:build_test.bzl", "build_test") load("@bazel_skylib//rules:diff_test.bzl", "diff_test") load("@bazel_skylib//rules:write_file.bzl", "write_file") @@ -52,7 +51,7 @@ write_file( sh_binary( name = "vendor_requirements", srcs = ["update.sh"], - data = [":requirement"], + data = [":requirement_bzl"], ) # Similarly ensures that the requirements.bzl file is updated @@ -76,9 +75,3 @@ build_test( name = "test_requirement_lists", targets = all_requirements + all_whl_requirements + all_data_requirements, ) - -bzl_library( - name = "requirements.clean", - srcs = ["requirements.clean.bzl"], - visibility = ["//visibility:public"], -) diff --git a/examples/wheel/private/BUILD.bazel b/examples/wheel/private/BUILD.bazel index d8401addf8..326fc3538c 100644 --- a/examples/wheel/private/BUILD.bazel +++ b/examples/wheel/private/BUILD.bazel @@ -1,4 +1,3 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@rules_python//python:py_binary.bzl", "py_binary") py_binary( @@ -6,9 +5,3 @@ py_binary( srcs = ["directory_writer.py"], visibility = ["//:__subpackages__"], ) - -bzl_library( - name = "wheel_utils", - srcs = ["wheel_utils.bzl"], - visibility = ["//examples/wheel:__subpackages__"], -) diff --git a/tests/BUILD.bazel b/tests/BUILD.bazel index e5d9a58243..e7dbef65d8 100644 --- a/tests/BUILD.bazel +++ b/tests/BUILD.bazel @@ -1,4 +1,3 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@bazel_skylib//rules:build_test.bzl", "build_test") package(default_visibility = ["//visibility:public"]) @@ -9,26 +8,20 @@ build_test( name = "bzl_libraries_build_test", targets = [ # keep sorted - "//python:current_py_toolchain", - "//python:defs", - "//python:proto", - "//python:py_binary", - "//python:py_cc_link_params_info", - "//python:py_import", - "//python:py_info", - "//python:py_library", - "//python:py_runtime", - "//python:py_runtime_info", - "//python:py_runtime_pair", - "//python:py_test", - "//python/cc:py_cc_toolchain", - "//python/cc:py_cc_toolchain_info", - "//python/entry_points:py_console_script_binary", + "//python:current_py_toolchain_bzl", + "//python:defs_bzl", + "//python:proto_bzl", + "//python:py_binary_bzl", + "//python:py_cc_link_params_info_bzl", + "//python:py_import_bzl", + "//python:py_info_bzl", + "//python:py_library_bzl", + "//python:py_runtime_bzl", + "//python:py_runtime_info_bzl", + "//python:py_runtime_pair_bzl", + "//python:py_test_bzl", + "//python/cc:py_cc_toolchain_bzl", + "//python/cc:py_cc_toolchain_info_bzl", + "//python/entry_points:py_console_script_binary_bzl", ], ) - -bzl_library( - name = "default_info_subject", - srcs = ["default_info_subject.bzl"], - deps = ["@rules_testing//lib/private:runfiles_subject"], -) diff --git a/tests/base_rules/BUILD.bazel b/tests/base_rules/BUILD.bazel index 5d97b3eac6..aa21042e25 100644 --- a/tests/base_rules/BUILD.bazel +++ b/tests/base_rules/BUILD.bazel @@ -1,5 +1,3 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - # Copyright 2023 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,10 +11,3 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - -bzl_library( - name = "util", - srcs = ["util.bzl"], - visibility = ["//visibility:public"], - deps = ["@bazel_skylib//lib:structs"], -) diff --git a/tests/entry_points/BUILD.bazel b/tests/entry_points/BUILD.bazel index e98a610f87..c877462f54 100644 --- a/tests/entry_points/BUILD.bazel +++ b/tests/entry_points/BUILD.bazel @@ -1,5 +1,3 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - # Copyright 2023 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -46,10 +44,3 @@ build_test( ":twine_pkg", ], ) - -bzl_library( - name = "simple_macro", - srcs = ["simple_macro.bzl"], - visibility = ["//visibility:public"], - deps = ["//python/entry_points:py_console_script_binary"], -) diff --git a/tests/integration/local_toolchains/BUILD.bazel b/tests/integration/local_toolchains/BUILD.bazel index 6e846ad0f5..20ee7bcfe6 100644 --- a/tests/integration/local_toolchains/BUILD.bazel +++ b/tests/integration/local_toolchains/BUILD.bazel @@ -1,5 +1,3 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - # Copyright 2024 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -87,20 +85,3 @@ py_test( srcs = ["echo_test.py"], deps = [":echo_ext"], ) - -bzl_library( - name = "py_extension", - srcs = ["py_extension.bzl"], - visibility = ["//visibility:public"], - deps = [ - "@bazel_skylib//rules:copy_file", - "@rules_cc//cc:cc_binary", - "@rules_python//python:defs", - ], -) - -bzl_library( - name = "pbs_archive", - srcs = ["pbs_archive.bzl"], - visibility = ["//visibility:public"], -) diff --git a/tests/integration/py_cc_toolchain_registered/BUILD.bazel b/tests/integration/py_cc_toolchain_registered/BUILD.bazel index c2d50143af..9c9275c7c1 100644 --- a/tests/integration/py_cc_toolchain_registered/BUILD.bazel +++ b/tests/integration/py_cc_toolchain_registered/BUILD.bazel @@ -1,5 +1,3 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - # Copyright 2024 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,9 +17,3 @@ load(":defs.bzl", "py_cc_toolchain_available_test") # Simple test to verify that the py_cc_toolchain is registered and available # by default (for bzlmod) and when users setup a hermetic toolchain (workspace) py_cc_toolchain_available_test(name = "py_cc_toolchain_available_test") - -bzl_library( - name = "defs", - srcs = ["defs.bzl"], - visibility = ["//visibility:public"], -) diff --git a/tests/integration/uv_lock/BUILD.bazel b/tests/integration/uv_lock/BUILD.bazel index 0ba2272cce..da6482ba08 100644 --- a/tests/integration/uv_lock/BUILD.bazel +++ b/tests/integration/uv_lock/BUILD.bazel @@ -1,4 +1,3 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@bazel_skylib//rules:diff_test.bzl", "diff_test") load("@rules_python//python/uv:lock.bzl", "lock") load(":uv_runner.bzl", "uv_runner") @@ -25,9 +24,3 @@ diff_test( file1 = ":requirements", file2 = ":requirements.txt", ) - -bzl_library( - name = "uv_runner", - srcs = ["uv_runner.bzl"], - visibility = ["//visibility:public"], -) diff --git a/tests/load_from_macro/BUILD.bazel b/tests/load_from_macro/BUILD.bazel index 40ea405d1c..ecb5de51a7 100644 --- a/tests/load_from_macro/BUILD.bazel +++ b/tests/load_from_macro/BUILD.bazel @@ -1,5 +1,3 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - # Copyright 2019 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,9 +32,3 @@ genrule( cmd = "$(PYTHON3) --version > $(location out.txt)", toolchains = ["//python:current_py_toolchain"], ) - -bzl_library( - name = "tags", - srcs = ["tags.bzl"], - visibility = ["//visibility:public"], -) diff --git a/tests/pypi/extension/BUILD.bazel b/tests/pypi/extension/BUILD.bazel index 46ce2a3613..39000e8c1b 100644 --- a/tests/pypi/extension/BUILD.bazel +++ b/tests/pypi/extension/BUILD.bazel @@ -1,5 +1,3 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - # Copyright 2024 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,9 +15,3 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load(":extension_tests.bzl", "extension_test_suite") extension_test_suite(name = "extension_tests") - -bzl_library( - name = "pip_parse", - srcs = ["pip_parse.bzl"], - visibility = ["//visibility:public"], -) diff --git a/tests/pypi/integration/BUILD.bazel b/tests/pypi/integration/BUILD.bazel index 0971cb05f7..316abe8271 100644 --- a/tests/pypi/integration/BUILD.bazel +++ b/tests/pypi/integration/BUILD.bazel @@ -1,4 +1,3 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@bazel_skylib//rules:build_test.bzl", "build_test") load("@rules_python_publish_deps//:requirements.bzl", "all_requirements") @@ -6,9 +5,3 @@ build_test( name = "all_requirements_build_test", targets = all_requirements, ) - -bzl_library( - name = "transitions", - srcs = ["transitions.bzl"], - visibility = ["//visibility:public"], -) diff --git a/tests/pypi/whl_library/testdata/BUILD.bazel b/tests/pypi/whl_library/testdata/BUILD.bazel index fc9d518702..e69de29bb2 100644 --- a/tests/pypi/whl_library/testdata/BUILD.bazel +++ b/tests/pypi/whl_library/testdata/BUILD.bazel @@ -1,7 +0,0 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - -bzl_library( - name = "packages", - srcs = ["packages.bzl"], - visibility = ["//visibility:public"], -) diff --git a/tests/python_bzlmod_ext/BUILD.bazel b/tests/python_bzlmod_ext/BUILD.bazel index 45006674b9..e266c01b9c 100644 --- a/tests/python_bzlmod_ext/BUILD.bazel +++ b/tests/python_bzlmod_ext/BUILD.bazel @@ -1,4 +1,3 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load(":test_helpers.bzl", "register_python_bzlmod_ext_tests") register_python_bzlmod_ext_tests( @@ -6,14 +5,3 @@ register_python_bzlmod_ext_tests( parse_runtime_manifest_name = "parse_runtime_manifest_tests", runtime_manifests_name = "runtime_manifests_tests", ) - -bzl_library( - name = "test_helpers", - srcs = ["test_helpers.bzl"], - visibility = ["//visibility:public"], - deps = [ - ":parse_runtime_manifest_tests", - ":runtime_manifests_tests", - "//python/private:bzlmod_enabled", - ], -) diff --git a/tests/support/BUILD.bazel b/tests/support/BUILD.bazel index 74a67f9169..45f43c89e2 100644 --- a/tests/support/BUILD.bazel +++ b/tests/support/BUILD.bazel @@ -1,5 +1,3 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - # Copyright 2023 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -36,67 +34,3 @@ config_setting( ":custom_runtime": "linux-x86-install-only-stripped", }, ) - -bzl_library( - name = "cc_info_subject", - srcs = ["cc_info_subject.bzl"], - deps = ["@rules_testing//lib:truth"], -) - -bzl_library( - name = "py_cc_toolchain_info_subject", - srcs = ["py_cc_toolchain_info_subject.bzl"], - deps = ["@rules_testing//lib:truth"], -) - -bzl_library( - name = "py_executable_info_subject", - srcs = ["py_executable_info_subject.bzl"], - deps = ["@rules_testing//lib:truth"], -) - -bzl_library( - name = "py_info_subject", - srcs = ["py_info_subject.bzl"], - deps = ["@rules_testing//lib:truth"], -) - -bzl_library( - name = "py_reconfig", - srcs = ["py_reconfig.bzl"], - deps = [ - ":support", - "//python/private:attr_builders", - "//python/private:common_labels", - "//python/private:py_binary_macro", - "//python/private:py_binary_rule", - "//python/private:py_test_macro", - "//python/private:py_test_rule", - "@rules_python_internal//:rules_python_config", - ], -) - -bzl_library( - name = "py_runtime_info_subject", - srcs = ["py_runtime_info_subject.bzl"], - deps = ["@rules_testing//lib:truth"], -) - -bzl_library( - name = "support", - srcs = ["support.bzl"], - deps = [ - "//python/private:bzlmod_enabled", - "@rules_python_internal//:rules_python_config", - ], -) - -bzl_library( - name = "copy_file", - srcs = ["copy_file.bzl"], -) - -bzl_library( - name = "mocks", - srcs = ["mocks.bzl"], -) diff --git a/tests/support/cc_toolchains/BUILD.bazel b/tests/support/cc_toolchains/BUILD.bazel index 73d00e8e2a..1c1a714626 100644 --- a/tests/support/cc_toolchains/BUILD.bazel +++ b/tests/support/cc_toolchains/BUILD.bazel @@ -1,5 +1,3 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - # Copyright 2023 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -174,12 +172,3 @@ fake_cc_toolchain_config( target_cpu = "windows_x86_64", toolchain_identifier = "windows-toolchain", ) - -bzl_library( - name = "fake_cc_toolchain_config", - srcs = ["fake_cc_toolchain_config.bzl"], - deps = [ - "@rules_cc//cc/common:cc_common", - "@rules_cc//cc/toolchains:cc_toolchain_config_info", - ], -) diff --git a/tests/support/mocks/BUILD.bazel b/tests/support/mocks/BUILD.bazel index bb6130e2ed..07bdb2bffc 100644 --- a/tests/support/mocks/BUILD.bazel +++ b/tests/support/mocks/BUILD.bazel @@ -5,15 +5,15 @@ package( default_visibility = ["//:__subpackages__"], ) -mocks_test_suite(name = "mocks_tests") - bzl_library( - name = "python_ext", - srcs = ["python_ext.bzl"], - deps = [":mocks"], + name = "mocks_bzl", + srcs = ["mocks.bzl"], ) bzl_library( - name = "mocks", - srcs = ["mocks.bzl"], + name = "python_ext_bzl", + srcs = ["python_ext.bzl"], + deps = [":mocks_bzl"], ) + +mocks_test_suite(name = "mocks_tests") diff --git a/tests/support/platforms/BUILD.bazel b/tests/support/platforms/BUILD.bazel index 7e2ba49911..eeb7ccb597 100644 --- a/tests/support/platforms/BUILD.bazel +++ b/tests/support/platforms/BUILD.bazel @@ -1,5 +1,3 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - package( default_visibility = ["//:__subpackages__"], ) @@ -85,8 +83,3 @@ platform( "@platforms//cpu:s390x", ], ) - -bzl_library( - name = "platforms", - srcs = ["platforms.bzl"], -) diff --git a/tests/support/whl_from_dir/BUILD.bazel b/tests/support/whl_from_dir/BUILD.bazel index e4a4d423d5..e69de29bb2 100644 --- a/tests/support/whl_from_dir/BUILD.bazel +++ b/tests/support/whl_from_dir/BUILD.bazel @@ -1,8 +0,0 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - -bzl_library( - name = "whl_from_dir_repo", - srcs = ["whl_from_dir_repo.bzl"], - visibility = ["//visibility:public"], - deps = ["//python/private:repo_utils"], -) diff --git a/tests/toolchains/BUILD.bazel b/tests/toolchains/BUILD.bazel index 65e0153381..b336a06269 100644 --- a/tests/toolchains/BUILD.bazel +++ b/tests/toolchains/BUILD.bazel @@ -1,5 +1,3 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - # Copyright 2022 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -56,20 +54,3 @@ diff_test( file1 = "//python/private:runtimes_manifest_workspace.bzl", file2 = ":expected_runtimes_manifest_workspace.bzl", ) - -bzl_library( - name = "defs", - srcs = ["defs.bzl"], - visibility = ["//visibility:public"], - deps = [ - "//python:versions", - "//python/private:version", - "//tests/support:py_reconfig", - ], -) - -bzl_library( - name = "expected_runtimes_manifest_workspace", - srcs = ["expected_runtimes_manifest_workspace.bzl"], - visibility = ["//visibility:public"], -) From 4927119c5b75ced9bb794b4fe8ac9ec8f1e4a91b Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Fri, 26 Jun 2026 20:10:19 +0000 Subject: [PATCH 08/36] Resolve upstream dependency and target mismatch failures after merge. Update build targets to align with upgraded external rulesets (rules_cc, platforms, protobuf) and restore compatibility aliases for renamed public targets. --- BUILD.bazel | 9 ++++++--- python/cc/BUILD.bazel | 14 ++++++++++++++ python/entry_points/BUILD.bazel | 7 +++++++ python/private/BUILD.bazel | 12 +++++------- python/private/pypi/BUILD.bazel | 7 ------- python/uv/private/BUILD.bazel | 16 +++++----------- tests/support/whl_from_dir/BUILD.bazel | 22 ++++++++++++++++++++++ 7 files changed, 59 insertions(+), 28 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 8699efe511..606e70dac1 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -21,6 +21,11 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") # 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 # gazelle:resolve starlark @toml.bzl//:toml.bzl @toml.bzl//:toml +# Override Gazelle's incorrect default resolution for platforms host constraints Starlark library +# gazelle:resolve starlark @platforms//host:constraints.bzl @platforms//host:constraints_lib +# Override Gazelle's incorrect default resolution for rules_cc Starlark libraries +# gazelle:resolve starlark @rules_cc//cc:cc_import.bzl @rules_cc//cc:core_rules +# gazelle:resolve starlark @rules_cc//cc:cc_library.bzl @rules_cc//cc:core_rules # gazelle:exclude tests # gazelle:exclude examples @@ -90,6 +95,7 @@ bzl_library( ], ) +# keep bzl_library( name = "internal_dev_setup", srcs = ["internal_dev_setup.bzl"], @@ -104,11 +110,8 @@ bzl_library( "//tests/support/whl_from_dir:whl_from_dir_repo", "@bazel_features//:deps", "@bazel_skylib//:workspace", - "@cgrindel_bazel_starlib//:deps", - "@com_google_protobuf//:protobuf_deps", "@rules_bazel_integration_test//bazel_integration_test:deps", "@rules_bazel_integration_test//bazel_integration_test:repo_defs", - "@rules_shell//shell:repositories", ], ) diff --git a/python/cc/BUILD.bazel b/python/cc/BUILD.bazel index 2b3af42bcb..64f5bbc51a 100644 --- a/python/cc/BUILD.bazel +++ b/python/cc/BUILD.bazel @@ -63,3 +63,17 @@ bzl_library( srcs = ["py_cc_toolchain_info.bzl"], deps = ["//python/private:py_cc_toolchain_info"], ) + +alias( + name = "py_cc_toolchain_bzl", + actual = ":py_cc_toolchain", + deprecation = "Use //python/cc:py_cc_toolchain instead", + visibility = ["//visibility:public"], +) + +alias( + name = "py_cc_toolchain_info_bzl", + actual = ":py_cc_toolchain_info", + deprecation = "Use //python/cc:py_cc_toolchain_info instead", + visibility = ["//visibility:public"], +) diff --git a/python/entry_points/BUILD.bazel b/python/entry_points/BUILD.bazel index 182d8fa85c..7cfd0cdf25 100644 --- a/python/entry_points/BUILD.bazel +++ b/python/entry_points/BUILD.bazel @@ -33,3 +33,10 @@ bzl_library( visibility = ["//visibility:public"], deps = ["//python/private:py_console_script_binary"], ) + +alias( + name = "py_console_script_binary_bzl", + actual = ":py_console_script_binary", + deprecation = "Use //python/entry_points:py_console_script_binary instead", + visibility = ["//visibility:public"], +) diff --git a/python/private/BUILD.bazel b/python/private/BUILD.bazel index 003febf3aa..c8d2a40c6c 100644 --- a/python/private/BUILD.bazel +++ b/python/private/BUILD.bazel @@ -365,8 +365,7 @@ bzl_library( "//python:py_runtime", "//python:py_runtime_pair", "//python/cc:py_cc_toolchain", - "@rules_cc//cc:cc_import", - "@rules_cc//cc:cc_library", + "@rules_cc//cc:core_rules", ], ) @@ -379,6 +378,7 @@ bzl_library( ], ) +# keep bzl_library( name = "internal_dev_deps", srcs = ["internal_dev_deps.bzl"], @@ -386,7 +386,6 @@ bzl_library( ":runtime_env_repo", "//python/private/pypi:whl_library", "//tests/support/whl_from_dir:whl_from_dir_repo", - "@bazel_ci_rules//:rbe_repo", ], ) @@ -410,8 +409,7 @@ bzl_library( srcs = ["local_runtime_repo_setup.bzl"], deps = [ "@bazel_skylib//lib:selects", - "@rules_cc//cc:cc_import", - "@rules_cc//cc:cc_library", + "@rules_cc//cc:core_rules", "@rules_python//python:py_runtime", "@rules_python//python:py_runtime_pair", "@rules_python//python/cc:py_cc_toolchain", @@ -639,7 +637,7 @@ bzl_library( ":text_util", ":toolchain_types", "@bazel_skylib//lib:selects", - "@platforms//host:constraints", + "@platforms//host:constraints_lib", ], ) @@ -743,7 +741,7 @@ bzl_library( "//python:py_runtime", "//python:py_runtime_pair", "//python/cc:py_cc_toolchain", - "@rules_cc//cc:cc_library", + "@rules_cc//cc:core_rules", ], ) diff --git a/python/private/pypi/BUILD.bazel b/python/private/pypi/BUILD.bazel index 1feb26b58e..5faa0ff1a7 100644 --- a/python/private/pypi/BUILD.bazel +++ b/python/private/pypi/BUILD.bazel @@ -13,7 +13,6 @@ # limitations under the License. load("@bazel_skylib//:bzl_library.bzl", "bzl_library") -load("//python:py_library.bzl", "py_library") package(default_visibility = ["//:__subpackages__"]) @@ -77,12 +76,6 @@ filegroup( # Keep sorted by library name and keep the files named by the main symbol they export -py_library( - name = "repack_whl", - srcs = ["repack_whl.py"], - deps = ["//tools:wheelmaker"], -) - bzl_library( name = "config_settings", srcs = ["config_settings.bzl"], diff --git a/python/uv/private/BUILD.bazel b/python/uv/private/BUILD.bazel index c12543e521..d311037011 100644 --- a/python/uv/private/BUILD.bazel +++ b/python/uv/private/BUILD.bazel @@ -24,16 +24,6 @@ filegroup( visibility = ["//python/uv:__pkg__"], ) -filegroup( - name = "lock_template", - srcs = select({ - "@platforms//os:windows": ["lock.bat"], - "//conditions:default": ["lock.sh"], - }), - target_compatible_with = [] if BZLMOD_ENABLED else ["@platforms//:incompatible"], - visibility = ["//visibility:public"], -) - filegroup( name = "lock_copier_template", srcs = ["template/lock_copier.py"], @@ -68,10 +58,14 @@ bzl_library( deps = [":toolchain_types"], ) +# keep bzl_library( name = "lock", srcs = ["lock.bzl"], - visibility = ["//python/uv:__subpackages__"], + visibility = [ + "//python/uv:__subpackages__", + "//tools/private:__subpackages__", + ], deps = [ ":toolchain_types", "//python:py_binary", diff --git a/tests/support/whl_from_dir/BUILD.bazel b/tests/support/whl_from_dir/BUILD.bazel index e69de29bb2..fc1eebe15a 100644 --- a/tests/support/whl_from_dir/BUILD.bazel +++ b/tests/support/whl_from_dir/BUILD.bazel @@ -0,0 +1,22 @@ +# Copyright 2024 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + +bzl_library( + name = "whl_from_dir_repo", + srcs = ["whl_from_dir_repo.bzl"], + visibility = ["//visibility:public"], + deps = ["//python/private:repo_utils"], +) From 16fc85315e580e8800163965483ead137d2c82b8 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Fri, 26 Jun 2026 22:05:02 +0000 Subject: [PATCH 09/36] Exclude internal dev-setup files from Gazelle and revert tests/ support targets. This ensures the tests/ directory remains completely pristine and untouched by custom targets, while satisfying Bazel loading phase requirements. --- BUILD.bazel | 35 +++----------------------- python/private/BUILD.bazel | 11 -------- tests/support/whl_from_dir/BUILD.bazel | 22 ---------------- 3 files changed, 3 insertions(+), 65 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 606e70dac1..dc15e9c9d8 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -28,6 +28,9 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") # gazelle:resolve starlark @rules_cc//cc:cc_library.bzl @rules_cc//cc:core_rules # gazelle:exclude tests # gazelle:exclude examples +# gazelle:exclude internal_dev_setup.bzl +# gazelle:exclude internal_dev_deps.bzl +# gazelle:exclude python/private/internal_dev_deps.bzl package(default_visibility = ["//visibility:public"]) @@ -83,38 +86,6 @@ filegroup( visibility = ["//visibility:public"], ) -bzl_library( - name = "internal_dev_deps", - srcs = ["internal_dev_deps.bzl"], - visibility = ["//:__subpackages__"], - deps = [ - "//python/private:internal_config_repo", - "@bazel_tools//tools/build_defs/repo:http.bzl", - "@bazel_tools//tools/build_defs/repo:local.bzl", - "@bazel_tools//tools/build_defs/repo:utils.bzl", - ], -) - -# keep -bzl_library( - name = "internal_dev_setup", - srcs = ["internal_dev_setup.bzl"], - visibility = ["//:__subpackages__"], - deps = [ - ":version", - "//python:versions", - "//python/private:pythons_hub", - "//python/private:runtime_env_repo", - "//python/private/pypi:deps", - "//python/private/pypi:whl_library", - "//tests/support/whl_from_dir:whl_from_dir_repo", - "@bazel_features//:deps", - "@bazel_skylib//:workspace", - "@rules_bazel_integration_test//bazel_integration_test:deps", - "@rules_bazel_integration_test//bazel_integration_test:repo_defs", - ], -) - # keep bzl_library( name = "version", diff --git a/python/private/BUILD.bazel b/python/private/BUILD.bazel index c8d2a40c6c..12d9dd039a 100644 --- a/python/private/BUILD.bazel +++ b/python/private/BUILD.bazel @@ -378,17 +378,6 @@ bzl_library( ], ) -# keep -bzl_library( - name = "internal_dev_deps", - srcs = ["internal_dev_deps.bzl"], - deps = [ - ":runtime_env_repo", - "//python/private/pypi:whl_library", - "//tests/support/whl_from_dir:whl_from_dir_repo", - ], -) - bzl_library( name = "is_standalone_interpreter", srcs = ["is_standalone_interpreter.bzl"], diff --git a/tests/support/whl_from_dir/BUILD.bazel b/tests/support/whl_from_dir/BUILD.bazel index fc1eebe15a..e69de29bb2 100644 --- a/tests/support/whl_from_dir/BUILD.bazel +++ b/tests/support/whl_from_dir/BUILD.bazel @@ -1,22 +0,0 @@ -# Copyright 2024 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - -bzl_library( - name = "whl_from_dir_repo", - srcs = ["whl_from_dir_repo.bzl"], - visibility = ["//visibility:public"], - deps = ["//python/private:repo_utils"], -) From ac311923a2ce887e86492c99e003a4b345ae9b4c Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sat, 27 Jun 2026 17:15:18 +0000 Subject: [PATCH 10/36] Update plan, format always_on rule, and create rule-creator skill. Apply user feedback to the Gazelle migration plan, add proper YAML front matter to the always_on rule, and introduce a new skill to guide the creation and formatting of agent rules. --- .agents/plans/gazelle-bzl-library.md | 64 ++++++++++++++++++++++++++++ .agents/rules/always.md | 8 ++++ .agents/skills/rule-creator/SKILL.md | 56 ++++++++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 .agents/plans/gazelle-bzl-library.md create mode 100644 .agents/rules/always.md create mode 100644 .agents/skills/rule-creator/SKILL.md diff --git a/.agents/plans/gazelle-bzl-library.md b/.agents/plans/gazelle-bzl-library.md new file mode 100644 index 0000000000..976be8267b --- /dev/null +++ b/.agents/plans/gazelle-bzl-library.md @@ -0,0 +1,64 @@ +# Plan: Gazelle Migration for bzl_library Targets + +This plan outlines the strategy, implementation details, edge cases, and +special directions for migrating `rules_python` to use `bazel-skylib`'s Gazelle +integration to automate the generation and maintenance of `bzl_library` +targets. + +## 1. Objective + +Automate the maintenance of `bzl_library` targets across the repository to +simplify dependency tracking, while minimizing risk and keeping tests and +examples completely pristine. + +## 2. Implementation Strategy + +* **Plugin Integration:** Integrate `bazel_skylib_gazelle_plugin` as a + `dev_dependency` in `MODULE.bazel`. +* **Gazelle Location:** Place all Gazelle rules and targets (such as the + `gazelle_binary` and the `gazelle` rule itself) entirely within + `tools/private/gazelle` to prevent any loading-time or analysis-time + production dependencies on Gazelle. +* **Root Configuration:** Root-level configuration is limited to Gazelle + directives (comments) in the root `BUILD.bazel` to guide the plugin's + behavior. +* **Directory Exclusions:** + * Exclude `tests/` and `examples/` directories from Gazelle scanning to + ensure they remain completely untouched and match `upstream/main`. + * Exclude top-level dev-setup files (`internal_dev_setup.bzl`, + `python/private/internal_dev_deps.bzl`) from Gazelle to avoid + generating targets that would require creating helper targets inside the + pristine `tests/` directory. +* **Package Markers:** Keep `tests/support/whl_from_dir/BUILD.bazel` as a + nearly empty package marker (matching upstream) to satisfy Bazel's loading + phase, without defining any targets. + +## 3. Target Naming & Compatibility Rules + +* **Naming Convention:** Rename `bzl_library` targets to match the Starlark + file name (e.g., `foo.bzl` -> `:foo` instead of `:foo_bzl`). +* **Public Targets:** For public targets, always create deprecated + backwards-compatibility aliases (e.g., `:foo_bzl` pointing to `:foo`) to + prevent breaking downstream users. +* **Private Targets:** If a `bzl_library` is visibility-restricted (private), + it is **OK to change its name** without creating a compatibility alias. + +## 4. Edge Cases & Resolving Overrides + +* **Bzlmod MVS Upgrades:** While manually upgrading dependencies is strictly + forbidden, automatic transitive upgrades by Bzlmod's Minimal Version + Selection (MVS) (e.g., upgrading `platforms` or `rules_cc` due to other + dependencies) can rename or consolidate targets. +* **Resolve Overrides:** Use `# gazelle:resolve` overrides in the root + `BUILD.bazel` to map Starlark imports to the correct consolidated external + targets (e.g., `@rules_cc//cc:core_rules` instead of separate `cc_library` + and `cc_import` targets). +* **Omitted External Targets:** If external rulesets omit `bzl_library` + targets for their setup files, remove them from our dev target `deps` and + shield our targets with `# keep` to prevent Gazelle from regenerating them. + +## 5. Special Directions + +* **Copyrights:** Unless directed by the user otherwise, do not add Bazel + copyright to new or existing files. Remove any accidentally added + copyrights. diff --git a/.agents/rules/always.md b/.agents/rules/always.md new file mode 100644 index 0000000000..aa326d0f3f --- /dev/null +++ b/.agents/rules/always.md @@ -0,0 +1,8 @@ +--- +trigger: always_on +--- + +# Always On Rules + +Unless directed by the user otherwise, do not add Bazel copyright to new or +existing files. diff --git a/.agents/skills/rule-creator/SKILL.md b/.agents/skills/rule-creator/SKILL.md new file mode 100644 index 0000000000..9ed7978120 --- /dev/null +++ b/.agents/skills/rule-creator/SKILL.md @@ -0,0 +1,56 @@ +--- +name: rule-creator +description: Create and format agent rules with proper front matter in the workspace +--- + +Use this skill when you need to create a new rule for the agent in the +workspace. + +### Rule File Location + +All workspace-specific rules must be created as individual Markdown files under +the `.agents/rules/` directory: +``` +.agents/rules/.md +``` + +### Rule Format + +Every rule file must start with a YAML front matter block defining the trigger +condition, followed by the rule content in Markdown. + +```yaml +--- +trigger: +--- + +# + + +``` + +#### Trigger Conditions +* `always_on`: The rule is always active and must be followed for all tasks. +* Custom triggers: You can specify other trigger conditions if the rule only + applies in certain contexts. + +### Formatting Guidelines +* **Line Wrapping:** Always wrap all text in the rule file (including the + title and description) to **80 columns** to ensure readability and + compatibility. +* **Clarity:** Write clear, actionable directives. + +### Example + +To create a rule that prevents adding copyrights: + +```markdown +--- +trigger: always_on +--- + +# No Copyrights Rule + +Unless directed by the user otherwise, do not add Bazel copyright to new or +existing files. +``` From 791864b762d5d09b640da6020807d86509c6f65a Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sat, 27 Jun 2026 17:17:04 +0000 Subject: [PATCH 11/36] Rename always.md rule to copyright.md and update title. --- .agents/rules/{always.md => copyright.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .agents/rules/{always.md => copyright.md} (87%) diff --git a/.agents/rules/always.md b/.agents/rules/copyright.md similarity index 87% rename from .agents/rules/always.md rename to .agents/rules/copyright.md index aa326d0f3f..aae1945aef 100644 --- a/.agents/rules/always.md +++ b/.agents/rules/copyright.md @@ -2,7 +2,7 @@ trigger: always_on --- -# Always On Rules +# Copyright Rules Unless directed by the user otherwise, do not add Bazel copyright to new or existing files. From ed78d82cad13c8f73df20435d48479dee0cb775f Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sat, 27 Jun 2026 17:17:52 +0000 Subject: [PATCH 12/36] Rename copyright.md rule to when-to-use-copyright.md and update title. --- .agents/rules/{copyright.md => when-to-use-copyright.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .agents/rules/{copyright.md => when-to-use-copyright.md} (83%) diff --git a/.agents/rules/copyright.md b/.agents/rules/when-to-use-copyright.md similarity index 83% rename from .agents/rules/copyright.md rename to .agents/rules/when-to-use-copyright.md index aae1945aef..a73cbbfd70 100644 --- a/.agents/rules/copyright.md +++ b/.agents/rules/when-to-use-copyright.md @@ -2,7 +2,7 @@ trigger: always_on --- -# Copyright Rules +# When to Use Copyright Unless directed by the user otherwise, do not add Bazel copyright to new or existing files. From 97c6b3e08bdbb52cc534a78f2756d837a32999b9 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sat, 27 Jun 2026 17:55:26 +0000 Subject: [PATCH 13/36] Complete Gazelle migration refinements and final plan updates. Remove dependency patches and overrides, restrict config_settings visibility, add compatibility aliases for extensions and local_toolchains, exclude legacy common paths, sort python targets, and finalize the migration plan with the public targets list. --- .agents/plans/gazelle-bzl-library.md | 74 ++++++++++++++++++++ BUILD.bazel | 1 + MODULE.bazel | 6 -- docs/BUILD.bazel | 1 + gazelle/BUILD.bazel | 19 +---- gazelle/python/BUILD.bazel | 7 +- gazelle/python/private/BUILD.bazel | 9 +-- patches/BUILD.bazel | 1 - patches/bazel_skylib_gazelle_plugin.patch | 85 ----------------------- python/BUILD.bazel | 22 +++--- python/config_settings/BUILD.bazel | 4 +- python/extensions/BUILD.bazel | 18 +++++ python/local_toolchains/BUILD.bazel | 10 ++- python/private/common/BUILD.bazel | 25 ------- 14 files changed, 120 insertions(+), 162 deletions(-) delete mode 100644 patches/BUILD.bazel delete mode 100644 patches/bazel_skylib_gazelle_plugin.patch delete mode 100644 python/private/common/BUILD.bazel diff --git a/.agents/plans/gazelle-bzl-library.md b/.agents/plans/gazelle-bzl-library.md index 976be8267b..dc9f562244 100644 --- a/.agents/plans/gazelle-bzl-library.md +++ b/.agents/plans/gazelle-bzl-library.md @@ -29,6 +29,23 @@ examples completely pristine. `python/private/internal_dev_deps.bzl`) from Gazelle to avoid generating targets that would require creating helper targets inside the pristine `tests/` directory. + * **Bzlmod & Repository-Phase Exclusions:** Exclude Starlark files that + are only evaluated during the Bzlmod or repository-loading phases (e.g., + module extensions, repository rules, or startup setup macros). These + files do not run at analysis/build time and therefore do not need + `bzl_library` targets. + * Examples: `gazelle/deps.bzl` (repository-phase Go helper) and + `extensions.bzl` (Bzlmod module extension files, such as those in + `gazelle/python/` and `gazelle/python/private/`) are excluded. + * **Special Case Exclusions:** + * `internal_dev_deps.bzl`: Exclude all instances of this file across + the repository (including in the root, `python/private/`, and + `gazelle/` directories) from Gazelle processing, as they are + dev-setup files that should not pollute the Starlark library graph. + * `python/private/common/`: Exclude this entire directory from Gazelle + processing. It contains legacy file paths and symlinks for older + Bazel versions, which do not need to be part of the modern Starlark + library graph. * **Package Markers:** Keep `tests/support/whl_from_dir/BUILD.bazel` as a nearly empty package marker (matching upstream) to satisfy Bazel's loading phase, without defining any targets. @@ -42,6 +59,19 @@ examples completely pristine. prevent breaking downstream users. * **Private Targets:** If a `bzl_library` is visibility-restricted (private), it is **OK to change its name** without creating a compatibility alias. +* **Visibility of New Targets:** Restrict the visibility of + `bzl_library` targets created for files that did not previously + have a `bzl_library` target to `//:__subpackages__`. Do not make + newly introduced targets public. +* **Bzlmod-Only Public Targets (`python/extensions/`):** Targets in + `python/extensions/BUILD.bazel` are Bzlmod-only but are public. We let + Gazelle process them (generating `:config`, `:pip`, `:python`), but we must + manually create deprecated backwards-compatibility aliases (`:config_bzl`, + `:pip_bzl`, `:python_bzl`) to support any legacy references. +* **Documentation Targets:** When renaming or migrating targets, ensure that + all documentation targets (such as `bzl_api_docs` in `docs/BUILD.bazel`) + are updated to reference the new target names (e.g., ensuring + `//python:py_info` is included). ## 4. Edge Cases & Resolving Overrides @@ -62,3 +92,47 @@ examples completely pristine. * **Copyrights:** Unless directed by the user otherwise, do not add Bazel copyright to new or existing files. Remove any accidentally added copyrights. +* **Patches & Overrides:** Patching dependencies is strictly prohibited. + Consequently, using `single_version_override` (or any other module + overrides) to apply patches in `MODULE.bazel` is not permitted. + +## 6. Public bzl_library Targets + +The following are all the public `bzl_library` targets in the repository (across +both the main module and the Gazelle module) that must be maintained with +backwards-compatibility aliases if they are renamed: + +### Main Module (`@rules_python`) +* `//python:current_py_toolchain_bzl` +* `//python:defs` +* `//python:features` +* `//python:packaging` +* `//python:pip` +* `//python:proto` +* `//python:py_binary` +* `//python:py_cc_link_params_info` +* `//python:py_exec_tools_info` +* `//python:py_exec_tools_toolchain` +* `//python:py_executable_info` +* `//python:py_import` +* `//python:py_info` +* `//python:py_library` +* `//python:py_runtime` +* `//python:py_runtime_info` +* `//python:py_runtime_pair` +* `//python:py_test` +* `//python:python` +* `//python:repositories` +* `//python:versions` +* `//python/entry_points:py_console_script_binary` +* `//python/extensions:config` +* `//python/extensions:pip` +* `//python/extensions:python` +* `//python/zipapp:py_zipapp_binary` +* `//python/zipapp:py_zipapp_test` + +### Gazelle Module (`@rules_python_gazelle_plugin`) +* `@rules_python_gazelle_plugin//:def` +* `@rules_python_gazelle_plugin//manifest:defs` +* `@rules_python_gazelle_plugin//modules_mapping:def` +* `@rules_python_gazelle_plugin//python:gazelle_test` diff --git a/BUILD.bazel b/BUILD.bazel index dc15e9c9d8..bbe2565515 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -30,6 +30,7 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") # gazelle:exclude examples # gazelle:exclude internal_dev_setup.bzl # gazelle:exclude internal_dev_deps.bzl +# gazelle:exclude python/private/common # gazelle:exclude python/private/internal_dev_deps.bzl package(default_visibility = ["//visibility:public"]) diff --git a/MODULE.bazel b/MODULE.bazel index f3f48011b3..c4afa60640 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -348,9 +348,3 @@ uv_dev.configure( # name = "experimental_python_import_all_repositories", # starlark_flag = "//python/config_settings:experimental_python_import_all_repositories", # ) - -single_version_override( - module_name = "bazel_skylib_gazelle_plugin", - patch_strip = 1, - patches = ["//patches:bazel_skylib_gazelle_plugin.patch"], -) diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel index 52531f43c0..2e13da1296 100644 --- a/docs/BUILD.bazel +++ b/docs/BUILD.bazel @@ -116,6 +116,7 @@ sphinx_stardocs( "//python:py_exec_tools_info", "//python:py_exec_tools_toolchain", "//python:py_executable_info", + "//python:py_info", "//python:py_library", "//python:py_runtime", "//python:py_runtime_info", diff --git a/gazelle/BUILD.bazel b/gazelle/BUILD.bazel index f7ae54eca4..30758181ed 100644 --- a/gazelle/BUILD.bazel +++ b/gazelle/BUILD.bazel @@ -5,6 +5,8 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") # See https://github.com/bazelbuild/bazel-gazelle#running-gazelle-with-bazel # gazelle:prefix github.com/bazel-contrib/rules_python/gazelle # gazelle:exclude bazel-out +# gazelle:exclude deps.bzl +# gazelle:exclude internal_dev_deps.bzl gazelle( name = "gazelle", ) @@ -38,23 +40,6 @@ filegroup( visibility = ["@rules_python//:__pkg__"], ) -bzl_library( - name = "deps", - srcs = ["deps.bzl"], - visibility = ["//visibility:public"], - deps = [ - "@bazel_gazelle//:deps", - "@bazel_tools//tools/build_defs/repo:http.bzl", - ], -) - -bzl_library( - name = "internal_dev_deps", - srcs = ["internal_dev_deps.bzl"], - visibility = ["//visibility:public"], - deps = ["@bazel_tools//tools/build_defs/repo:http.bzl"], -) - bzl_library( name = "def", srcs = ["def.bzl"], diff --git a/gazelle/python/BUILD.bazel b/gazelle/python/BUILD.bazel index 6a73e55b15..73aec2ec8d 100644 --- a/gazelle/python/BUILD.bazel +++ b/gazelle/python/BUILD.bazel @@ -66,6 +66,7 @@ copy_file( ) # gazelle:exclude testdata/ +# gazelle:exclude extensions.bzl gazelle_test( name = "python_test", @@ -131,9 +132,3 @@ bzl_library( visibility = ["//visibility:public"], deps = ["@io_bazel_rules_go//go:def"], ) - -bzl_library( - name = "extensions", - srcs = ["extensions.bzl"], - visibility = ["//visibility:public"], -) diff --git a/gazelle/python/private/BUILD.bazel b/gazelle/python/private/BUILD.bazel index 61644f6272..ccdc080664 100644 --- a/gazelle/python/private/BUILD.bazel +++ b/gazelle/python/private/BUILD.bazel @@ -1,8 +1 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - -bzl_library( - name = "extensions", - srcs = ["extensions.bzl"], - visibility = ["//gazelle/python:__subpackages__"], - deps = ["@bazel_skylib//lib:modules"], -) +# gazelle:exclude extensions.bzl diff --git a/patches/BUILD.bazel b/patches/BUILD.bazel deleted file mode 100644 index 9ffe771b28..0000000000 --- a/patches/BUILD.bazel +++ /dev/null @@ -1 +0,0 @@ -# Package marker for patches. diff --git a/patches/bazel_skylib_gazelle_plugin.patch b/patches/bazel_skylib_gazelle_plugin.patch deleted file mode 100644 index f51a636c40..0000000000 --- a/patches/bazel_skylib_gazelle_plugin.patch +++ /dev/null @@ -1,85 +0,0 @@ ---- a/bzl/gazelle.go -+++ b/bzl/gazelle.go -@@ -160,13 +160,26 @@ - // the index only contains absolute labels, not relative - impLabel = impLabel.Abs(from.Repo, from.Pkg) - -- if impLabel.Repo == "bazel_tools" { -- // The @bazel_tools repo is tricky because it is a part of the "shipped -- // with bazel" core library for interacting with the outside world. -- // This means that it can not depend on skylib. Fortunately there is a -- // fairly simple workaround for this, which is that you can add those -- // bzl files as `deps` entries. -- deps = append(deps, imp) -+ log.Printf("JETSKI_DEBUG: imp=%q, impLabel.Abs()=%s", imp, impLabel.String()) -+ res := resolve.ImportSpec{ -+ Lang: languageName, -+ Imp: impLabel.String(), -+ } -+ depLabel, ok := resolve.FindRuleWithOverride(c, res, languageName) -+ log.Printf("JETSKI_DEBUG: FindRuleWithOverride(%q) -> label=%s, ok=%t", res.Imp, depLabel.String(), ok) -+ if ok { -+ depLabel = depLabel.Rel(from.Repo, from.Pkg) -+ deps = append(deps, depLabel.String()) -+ continue -+ } -+ -+ matches := ix.FindRulesByImportWithConfig(c, res, languageName) -+ if len(matches) > 0 { -+ for _, m := range matches { -+ depLabel := m.Label -+ depLabel = depLabel.Rel(from.Repo, from.Pkg) -+ deps = append(deps, depLabel.String()) -+ } - continue - } - -@@ -177,23 +190,11 @@ - continue - } - -- res := resolve.ImportSpec{ -- Lang: languageName, -- Imp: impLabel.String(), -- } -- matches := ix.FindRulesByImportWithConfig(c, res, languageName) -- if len(matches) == 0 { -- log.Printf("%s: %q (%s) was not found in dependency index. Skipping. This may result in an incomplete deps section and require manual BUILD file intervention.\n", from.String(), imp, impLabel.String()) -- } -- -- for _, m := range matches { -- depLabel := m.Label -- depLabel = depLabel.Rel(from.Repo, from.Pkg) -- deps = append(deps, depLabel.String()) -- } -+ log.Printf("%s: %q (%s) was not found in dependency index. Skipping. This may result in an incomplete deps section and require manual BUILD file intervention.\n", from.String(), imp, impLabel.String()) - } - - sort.Strings(deps) -+ log.Printf("JETSKI_DEBUG: Rule %s (from %s) final deps: %v", r.Name(), from.String(), deps) - if len(deps) > 0 { - r.SetAttr("deps", deps) - } -@@ -223,7 +224,7 @@ - var rules []*rule.Rule - var imports []interface{} - for _, f := range append(args.RegularFiles, args.GenFiles...) { -- if !isBzlSourceFile(f) { -+ if !isBzlSourceFile(f, args.Rel) { - continue - } - name := strings.TrimSuffix(f, fileType) -@@ -278,8 +279,11 @@ - return loads, nil - } - --func isBzlSourceFile(f string) bool { -- return strings.HasSuffix(f, fileType) && !ignoreSuffix.Matches(f) -+func isBzlSourceFile(f string, rel string) bool { -+ if rel == "tests" || strings.HasPrefix(rel, "tests/") { -+ return strings.HasSuffix(f, fileType) && !ignoreSuffix.Matches(f) -+ } -+ return strings.HasSuffix(f, fileType) - } - - // generateEmpty generates the list of rules that don't need to exist in the diff --git a/python/BUILD.bazel b/python/BUILD.bazel index a3d95edd05..518a812b24 100644 --- a/python/BUILD.bazel +++ b/python/BUILD.bazel @@ -77,6 +77,7 @@ filegroup( # ========= Core rules ========= +# @unused exports_files([ "defs.bzl", "python.bzl", # Deprecated, please use defs.bzl @@ -105,6 +106,7 @@ exports_files([ # ... # }), # ... +# ... # ) # # Caution: Do not `select()` on the built-in command-line flags `--force_python` @@ -206,6 +208,11 @@ alias( deprecation = "Use //python:defs instead", ) +bzl_library( + name = "features", + srcs = ["features.bzl"], +) + alias( name = "features_bzl", actual = ":features", @@ -408,6 +415,11 @@ alias( deprecation = "Use //python:py_test instead", ) +bzl_library( + name = "python", + srcs = ["python.bzl"], +) + alias( name = "python_bzl", actual = ":python", @@ -447,13 +459,3 @@ alias( actual = ":versions", deprecation = "Use //python:versions instead", ) - -bzl_library( - name = "features", - srcs = ["features.bzl"], -) - -bzl_library( - name = "python", - srcs = ["python.bzl"], -) diff --git a/python/config_settings/BUILD.bazel b/python/config_settings/BUILD.bazel index 2056e335cc..2eb261e1d1 100644 --- a/python/config_settings/BUILD.bazel +++ b/python/config_settings/BUILD.bazel @@ -222,14 +222,14 @@ string_flag( bzl_library( name = "config_settings", srcs = ["config_settings.bzl"], - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], deps = ["//python/private:config_settings"], ) bzl_library( name = "transition", srcs = ["transition.bzl"], - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], deps = [ "//python:py_binary", "//python/private:deprecation", diff --git a/python/extensions/BUILD.bazel b/python/extensions/BUILD.bazel index c64ff7cc64..281067c76f 100644 --- a/python/extensions/BUILD.bazel +++ b/python/extensions/BUILD.bazel @@ -45,3 +45,21 @@ bzl_library( srcs = ["python.bzl"], deps = ["//python/private:python"], ) + +alias( + name = "config_bzl", + actual = ":config", + deprecation = "Use //python/extensions:config instead", +) + +alias( + name = "pip_bzl", + actual = ":pip", + deprecation = "Use //python/extensions:pip instead", +) + +alias( + name = "python_bzl", + actual = ":python", + deprecation = "Use //python/extensions:python instead", +) diff --git a/python/local_toolchains/BUILD.bazel b/python/local_toolchains/BUILD.bazel index 9ca71264fd..7c4ad1a8e0 100644 --- a/python/local_toolchains/BUILD.bazel +++ b/python/local_toolchains/BUILD.bazel @@ -11,7 +11,13 @@ bzl_library( name = "repos", srcs = ["repos.bzl"], deps = [ - "@rules_python//python/private:local_runtime_repo", - "@rules_python//python/private:local_runtime_toolchains_repo", + "//python/private:local_runtime_repo", + "//python/private:local_runtime_toolchains_repo", ], ) + +alias( + name = "repos_bzl", + actual = ":repos", + deprecation = "Use //python/local_toolchains:repos instead", +) diff --git a/python/private/common/BUILD.bazel b/python/private/common/BUILD.bazel deleted file mode 100644 index c72025ca89..0000000000 --- a/python/private/common/BUILD.bazel +++ /dev/null @@ -1,25 +0,0 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - -bzl_library( - name = "py_binary_rule_bazel", - srcs = ["py_binary_rule_bazel.bzl"], - visibility = ["//python:__subpackages__"], -) - -bzl_library( - name = "py_library_rule_bazel", - srcs = ["py_library_rule_bazel.bzl"], - visibility = ["//python:__subpackages__"], -) - -bzl_library( - name = "py_runtime_rule", - srcs = ["py_runtime_rule.bzl"], - visibility = ["//python:__subpackages__"], -) - -bzl_library( - name = "py_test_rule_bazel", - srcs = ["py_test_rule_bazel.bzl"], - visibility = ["//python:__subpackages__"], -) From 61fae1a8373e301373898d74e858b4ef2f909d61 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 28 Jun 2026 00:44:40 +0000 Subject: [PATCH 14/36] Make python/cc targets public and update plan list. Expose py_cc_toolchain and py_cc_toolchain_info bzl_library targets to the public to match their deprecated aliases, and add them to the public targets list in the plan. --- .agents/plans/gazelle-bzl-library.md | 2 ++ python/cc/BUILD.bazel | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.agents/plans/gazelle-bzl-library.md b/.agents/plans/gazelle-bzl-library.md index dc9f562244..f864e1ea6f 100644 --- a/.agents/plans/gazelle-bzl-library.md +++ b/.agents/plans/gazelle-bzl-library.md @@ -124,6 +124,8 @@ backwards-compatibility aliases if they are renamed: * `//python:python` * `//python:repositories` * `//python:versions` +* `//python/cc:py_cc_toolchain` +* `//python/cc:py_cc_toolchain_info` * `//python/entry_points:py_console_script_binary` * `//python/extensions:config` * `//python/extensions:pip` diff --git a/python/cc/BUILD.bazel b/python/cc/BUILD.bazel index 64f5bbc51a..f17805d92f 100644 --- a/python/cc/BUILD.bazel +++ b/python/cc/BUILD.bazel @@ -55,12 +55,14 @@ filegroup( bzl_library( name = "py_cc_toolchain", srcs = ["py_cc_toolchain.bzl"], + visibility = ["//visibility:public"], deps = ["//python/private:py_cc_toolchain_macro"], ) bzl_library( name = "py_cc_toolchain_info", srcs = ["py_cc_toolchain_info.bzl"], + visibility = ["//visibility:public"], deps = ["//python/private:py_cc_toolchain_info"], ) From d9efc20c3ebecf1595d99d0514b49d4eb869100f Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 28 Jun 2026 02:03:52 +0000 Subject: [PATCH 15/36] Restrict Gazelle binary to bzl language only. Remove DEFAULT_LANGUAGES and configure the Gazelle binary to only use the Starlark bzl plugin, avoiding unnecessary Go and proto overhead in the main module. --- tools/private/gazelle/BUILD.bazel | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/private/gazelle/BUILD.bazel b/tools/private/gazelle/BUILD.bazel index 4472d13cfd..e782df13b6 100644 --- a/tools/private/gazelle/BUILD.bazel +++ b/tools/private/gazelle/BUILD.bazel @@ -1,4 +1,4 @@ -load("@bazel_gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary") +load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary") package( default_visibility = ["//:__subpackages__"], @@ -6,7 +6,7 @@ package( gazelle_binary( name = "gazelle_bin", - languages = DEFAULT_LANGUAGES + [ + languages = [ "@bazel_skylib_gazelle_plugin//bzl", ], ) From f6947ea0966aaf76f2b7c297cf698f243394c29b Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 28 Jun 2026 02:04:33 +0000 Subject: [PATCH 16/36] Add CI failure handling plan for PR 3852. --- .agents/plans/ci-handling.md | 66 ++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .agents/plans/ci-handling.md diff --git a/.agents/plans/ci-handling.md b/.agents/plans/ci-handling.md new file mode 100644 index 0000000000..97bf483776 --- /dev/null +++ b/.agents/plans/ci-handling.md @@ -0,0 +1,66 @@ +# Plan: Autonomous CI Failure Handling for PR #3852 + +This plan outlines the strategy and workflow for autonomously monitoring, +diagnosing, and resolving CI failures for PR #3852, ensuring a rapid and +reliable path to merging while handling known network flakiness. + +## 1. Objective + +Autonomously oversee the CI lifecycle for PR #3852, immediately detecting +failures, diagnosing their root causes, and applying resolutions (either +retrying flakes or fixing code/configuration errors) to minimize manual +intervention. + +## 2. Automated Monitoring + +* **Continuous Polling:** We launch a long-running background monitoring + service (`monitor_remote_ci.py`) dedicated to PR #3852. +* **Scope:** This service continuously monitors both GitHub PR checks and + Buildkite workflow executions. +* **Trigger:** The service runs continuously in the background and alerts the + main agent conversation immediately upon any job failure. + +## 3. Autonomous Diagnosis + +When any CI job completes with a non-zero exit code or errors: +1. **Log Retrieval:** The monitoring service automatically downloads the raw + CI log file to `ci_logs/`. +2. **Failure Analysis:** The service triggers the `analyze_ci_failure.py` + diagnostic tool. +3. **Synthesis:** The analyzer scans the logs for failure signatures + (tracebacks, compiler aborts, network timeouts) and synthesizes an + actionable, structured Markdown fix plan. +4. **Notification:** The analyzer dispatches a high-priority notification + containing the log path and the fix plan back to the active agent + conversation. + +## 4. Resolution Strategy + +We categorize failures into two types and address them as follows: + +### Category A: Infrastructure & Network Flakes +* **Identified by:** 504 Gateway errors, fetch timeouts, or unresolved external + repository downloads. +* **Resolution:** + * **Retries:** If Buildkite permissions allow, we autonomously retry the + failed job. If not, we notify the user to trigger a manual retry. + * **Timeout Scaling:** If timeouts persist, we modify `.bazelrc` to + increase `--http_timeout_scaling` or repository downloader retries. + * **Mirroring:** If a dependency download fails, we check if it is + available on `mirror.bazel.build`. If so, we add it to + `downloader_config.cfg` and push the update. + +### Category B: Code & Test Failures +* **Identified by:** Compilation errors, unit test assertion failures, or + lint/style violations. +* **Resolution:** + * **Apply Fix:** We analyze the generated fix plan, apply the necessary + code corrections locally, and run the validation suite (`bazel test + //...`). + * **Push:** Once verified green locally, we commit and push the fix + directly to the PR branch to trigger a new CI run. + +## 5. Execution + +The monitoring service is launched immediately upon updating the PR and runs +until the PR is merged or closed. From c058b6834136c17cac37fec2d3355ad354a84870 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 28 Jun 2026 02:12:43 +0000 Subject: [PATCH 17/36] Fix Gazelle path conflicts and Sphinxdocs compatibility in CI Revert premature target renames in Gazelle and Sphinxdocs to maintain compatibility with released versions of rules_python, and resolve a Python path shadowing bug in Sphinxdocs by reverting the helper package rename. Correct internal target paths in the Gazelle module to resolve Bzlmod resolution failures. --- .agents/plans/gazelle-bzl-library.md | 6 +++++ gazelle/manifest/BUILD.bazel | 2 +- gazelle/manifest/generate/BUILD.bazel | 2 +- gazelle/python/BUILD.bazel | 2 +- gazelle/pythonconfig/BUILD.bazel | 2 +- sphinxdocs/sphinxdocs/private/BUILD.bazel | 4 +-- sphinxdocs/tests/sphinx_stardoc/BUILD.bazel | 30 +++++++++++++++++---- 7 files changed, 37 insertions(+), 11 deletions(-) diff --git a/.agents/plans/gazelle-bzl-library.md b/.agents/plans/gazelle-bzl-library.md index f864e1ea6f..7b81ed2682 100644 --- a/.agents/plans/gazelle-bzl-library.md +++ b/.agents/plans/gazelle-bzl-library.md @@ -95,6 +95,12 @@ examples completely pristine. * **Patches & Overrides:** Patching dependencies is strictly prohibited. Consequently, using `single_version_override` (or any other module overrides) to apply patches in `MODULE.bazel` is not permitted. +* **Sphinxdocs & Gazelle Release Dependency:** `sphinxdocs` and the code + under `gazelle/` are released separately from `rules_python`. They + cannot refer to unreleased changes in `rules_python`. Thus, they must + refer to the old target names in `rules_python` (using the `_bzl` + suffix, e.g., `@rules_python//python:py_binary_bzl` and + `@rules_python//python:defs_bzl`). ## 6. Public bzl_library Targets diff --git a/gazelle/manifest/BUILD.bazel b/gazelle/manifest/BUILD.bazel index f9c64d73d6..68f4e1be30 100644 --- a/gazelle/manifest/BUILD.bazel +++ b/gazelle/manifest/BUILD.bazel @@ -41,6 +41,6 @@ bzl_library( deps = [ "@bazel_skylib//rules:diff_test", "@io_bazel_rules_go//go:def", - "@rules_python//python:defs", + "@rules_python//python:defs_bzl", ], ) diff --git a/gazelle/manifest/generate/BUILD.bazel b/gazelle/manifest/generate/BUILD.bazel index 906d4bf06b..77d2467cef 100644 --- a/gazelle/manifest/generate/BUILD.bazel +++ b/gazelle/manifest/generate/BUILD.bazel @@ -6,7 +6,7 @@ go_library( srcs = ["generate.go"], importpath = "github.com/bazel-contrib/rules_python/gazelle/manifest/generate", visibility = ["//visibility:public"], - deps = ["//gazelle/manifest"], + deps = ["//manifest"], ) sources_hash( diff --git a/gazelle/python/BUILD.bazel b/gazelle/python/BUILD.bazel index 73aec2ec8d..a283b2e48b 100644 --- a/gazelle/python/BUILD.bazel +++ b/gazelle/python/BUILD.bazel @@ -30,7 +30,7 @@ go_library( importpath = "github.com/bazel-contrib/rules_python/gazelle/python", visibility = ["//visibility:public"], deps = [ - "//gazelle/pythonconfig", + "//pythonconfig", "@bazel_gazelle//config", "@bazel_gazelle//label", "@bazel_gazelle//language", diff --git a/gazelle/pythonconfig/BUILD.bazel b/gazelle/pythonconfig/BUILD.bazel index 567252d606..a82a7f19ca 100644 --- a/gazelle/pythonconfig/BUILD.bazel +++ b/gazelle/pythonconfig/BUILD.bazel @@ -9,7 +9,7 @@ go_library( importpath = "github.com/bazel-contrib/rules_python/gazelle/pythonconfig", visibility = ["//visibility:public"], deps = [ - "//gazelle/manifest", + "//manifest", "@bazel_gazelle//label", "@com_github_emirpasic_gods//lists/singlylinkedlist:go_default_library", ], diff --git a/sphinxdocs/sphinxdocs/private/BUILD.bazel b/sphinxdocs/sphinxdocs/private/BUILD.bazel index 8c9ea58e88..b054ed2611 100644 --- a/sphinxdocs/sphinxdocs/private/BUILD.bazel +++ b/sphinxdocs/sphinxdocs/private/BUILD.bazel @@ -74,7 +74,7 @@ bzl_library( "@bazel_skylib//rules:build_test", "@bazel_skylib//rules:common_settings", "@io_bazel_stardoc//stardoc:stardoc_lib", - "@rules_python//python:py_binary", + "@rules_python//python:py_binary_bzl", ], ) @@ -98,7 +98,7 @@ bzl_library( srcs = ["readthedocs.bzl"], deps = [ ":util", - "@rules_python//python:py_binary", + "@rules_python//python:py_binary_bzl", ], ) diff --git a/sphinxdocs/tests/sphinx_stardoc/BUILD.bazel b/sphinxdocs/tests/sphinx_stardoc/BUILD.bazel index 36472f12f5..2cbc773f77 100644 --- a/sphinxdocs/tests/sphinx_stardoc/BUILD.bazel +++ b/sphinxdocs/tests/sphinx_stardoc/BUILD.bazel @@ -1,3 +1,4 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@bazel_skylib//rules:build_test.bzl", "build_test") load("@rules_python//python:py_test.bzl", "py_test") load("//sphinxdocs:sphinx.bzl", "sphinx_build_binary", "sphinx_docs") @@ -47,8 +48,8 @@ build_test( sphinx_stardocs( name = "simple_bzl_docs", srcs = [ - ":bzl_rule", - ":bzl_typedef", + ":bzl_rule_bzl", + ":bzl_typedef_bzl", ], target_compatible_with = _TARGET_COMPATIBLE_WITH, ) @@ -57,7 +58,7 @@ sphinx_stardoc( name = "bzl_function", src = ":bzl_function.bzl", target_compatible_with = _TARGET_COMPATIBLE_WITH, - deps = [":func_and_providers"], + deps = [":func_and_providers_bzl"], ) sphinx_stardoc( @@ -65,7 +66,26 @@ sphinx_stardoc( src = ":bzl_providers.bzl", prefix = "addprefix_", target_compatible_with = _TARGET_COMPATIBLE_WITH, - deps = [":func_and_providers"], + deps = [":func_and_providers_bzl"], +) + +bzl_library( + name = "func_and_providers_bzl", + srcs = [ + "bzl_function.bzl", + "bzl_providers.bzl", + ], +) + +bzl_library( + name = "bzl_rule_bzl", + srcs = ["bzl_rule.bzl"], + deps = [":func_and_providers_bzl"], +) + +bzl_library( + name = "bzl_typedef_bzl", + srcs = ["bzl_typedef.bzl"], ) # A bzl_library with multiple sources @@ -73,7 +93,7 @@ sphinx_build_binary( name = "sphinx-build", tags = ["manual"], # Only needed as part of sphinx doc building deps = [ - "//sphinxdocs/src/sphinx", + "//sphinxdocs/src/sphinx_bzl", "@dev_pip//myst_parser", "@dev_pip//sphinx", "@dev_pip//typing_extensions", # Needed by sphinx_stardoc From 0233673fc4aa65128840d8985ad9b8928ca3c446 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 28 Jun 2026 02:16:08 +0000 Subject: [PATCH 18/36] Mark Gazelle targets as Bzlmod-only to fix WORKSPACE CI Gate the gazelle_bin and gazelle targets in tools/private/gazelle with Bzlmod compatibility, marking them as incompatible when Bzlmod is disabled. This prevents Go toolchain resolution failures in WORKSPACE-only CI jobs. --- tools/private/gazelle/BUILD.bazel | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/private/gazelle/BUILD.bazel b/tools/private/gazelle/BUILD.bazel index e782df13b6..9a84469a25 100644 --- a/tools/private/gazelle/BUILD.bazel +++ b/tools/private/gazelle/BUILD.bazel @@ -1,4 +1,5 @@ load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary") +load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") # buildifier: disable=bzl-visibility package( default_visibility = ["//:__subpackages__"], @@ -9,9 +10,11 @@ gazelle_binary( languages = [ "@bazel_skylib_gazelle_plugin//bzl", ], + target_compatible_with = [] if BZLMOD_ENABLED else ["@platforms//:incompatible"], ) gazelle( name = "gazelle", gazelle = ":gazelle_bin", + target_compatible_with = [] if BZLMOD_ENABLED else ["@platforms//:incompatible"], ) From 9d0cd9a9138aed196f58a33009fb7ff2fa8c49e0 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 28 Jun 2026 02:21:05 +0000 Subject: [PATCH 19/36] Remove unsupported GCC flag from macOS config in .bazelrc Remove the GCC-specific -Wno-stringop-overread flag from the build:macos configuration. This flag is not supported by Clang on macOS and was causing Go stdlib compilation failures in CGO. --- .bazelrc | 2 -- 1 file changed, 2 deletions(-) diff --git a/.bazelrc b/.bazelrc index 044990fdb1..0f9aefcaa3 100644 --- a/.bazelrc +++ b/.bazelrc @@ -71,10 +71,8 @@ build:linux --host_copt=-Wno-deprecated-declarations build:linux --host_copt=-Wno-stringop-overread build:linux --host_copt=-Wno-sign-compare build:macos --copt=-Wno-deprecated-declarations -build:macos --copt=-Wno-stringop-overread build:macos --copt=-Wno-sign-compare build:macos --host_copt=-Wno-deprecated-declarations -build:macos --host_copt=-Wno-stringop-overread build:macos --host_copt=-Wno-sign-compare import %workspace%/specialized_configs.bazelrc From d7e78609b83a980228c0442940dbef1c8e2e6896 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 28 Jun 2026 02:51:40 +0000 Subject: [PATCH 20/36] Revert .bazelrc changes and mark Gazelle targets as manual Revert the previous changes to .bazelrc. Mark the gazelle and gazelle_bin targets in tools/private/gazelle as manual to exclude them from wildcard builds, resolving the CI failures without modifying global compiler flags. --- .bazelrc | 2 ++ tools/private/gazelle/BUILD.bazel | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.bazelrc b/.bazelrc index 0f9aefcaa3..044990fdb1 100644 --- a/.bazelrc +++ b/.bazelrc @@ -71,8 +71,10 @@ build:linux --host_copt=-Wno-deprecated-declarations build:linux --host_copt=-Wno-stringop-overread build:linux --host_copt=-Wno-sign-compare build:macos --copt=-Wno-deprecated-declarations +build:macos --copt=-Wno-stringop-overread build:macos --copt=-Wno-sign-compare build:macos --host_copt=-Wno-deprecated-declarations +build:macos --host_copt=-Wno-stringop-overread build:macos --host_copt=-Wno-sign-compare import %workspace%/specialized_configs.bazelrc diff --git a/tools/private/gazelle/BUILD.bazel b/tools/private/gazelle/BUILD.bazel index 9a84469a25..a9acac17df 100644 --- a/tools/private/gazelle/BUILD.bazel +++ b/tools/private/gazelle/BUILD.bazel @@ -1,5 +1,4 @@ load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary") -load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") # buildifier: disable=bzl-visibility package( default_visibility = ["//:__subpackages__"], @@ -10,11 +9,11 @@ gazelle_binary( languages = [ "@bazel_skylib_gazelle_plugin//bzl", ], - target_compatible_with = [] if BZLMOD_ENABLED else ["@platforms//:incompatible"], + tags = ["manual"], ) gazelle( name = "gazelle", gazelle = ":gazelle_bin", - target_compatible_with = [] if BZLMOD_ENABLED else ["@platforms//:incompatible"], + tags = ["manual"], ) From dcaafa421808d8403841255eb2c5ea3290dc7b3e Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 28 Jun 2026 03:13:52 +0000 Subject: [PATCH 21/36] Address code review feedback and sort targets Address various code review comments by reverting a premature target rename, removing deprecated aliases, and adding explanatory comments for manually maintained targets. Additionally, sort the Starlark library targets alphabetically to conform to project conventions. --- BUILD.bazel | 16 +- python/BUILD.bazel | 232 +++++------ python/features.bzl | 18 +- python/private/BUILD.bazel | 432 ++++++++++---------- python/private/pythons_hub.bzl | 16 - tools/build_defs/python/private/BUILD.bazel | 5 +- 6 files changed, 359 insertions(+), 360 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index bbe2565515..5d85f23182 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -14,25 +14,39 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") +# Resolve rules_cc Starlark libraries to their correct targets # gazelle:resolve starlark @rules_cc//cc/common:cc_info.bzl @rules_cc//cc/common:common # gazelle:resolve starlark @rules_cc//cc/common:cc_common.bzl @rules_cc//cc/common:common + +# Resolve protobuf Starlark libraries # gazelle:resolve starlark @com_google_protobuf//bazel:py_proto_library.bzl @com_google_protobuf//bazel:py_proto_library_bzl + +# Resolve bazel_tools repo rules to our internal wrapper to avoid transitive dependencies # 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 # gazelle:resolve starlark @toml.bzl//:toml.bzl @toml.bzl//:toml + # Override Gazelle's incorrect default resolution for platforms host constraints Starlark library # gazelle:resolve starlark @platforms//host:constraints.bzl @platforms//host:constraints_lib + # Override Gazelle's incorrect default resolution for rules_cc Starlark libraries # gazelle:resolve starlark @rules_cc//cc:cc_import.bzl @rules_cc//cc:core_rules # gazelle:resolve starlark @rules_cc//cc:cc_library.bzl @rules_cc//cc:core_rules + +# Exclude directories that are separate packages/workspaces or only for testing/examples # gazelle:exclude tests # gazelle:exclude examples + +# Exclude internal development tools and dependencies that users don't need # gazelle:exclude internal_dev_setup.bzl # gazelle:exclude internal_dev_deps.bzl -# gazelle:exclude python/private/common # gazelle:exclude python/private/internal_dev_deps.bzl +# Exclude legacy paths that are only kept for backwards compatibility +# gazelle:exclude python/private/common + package(default_visibility = ["//visibility:public"]) licenses(["notice"]) diff --git a/python/BUILD.bazel b/python/BUILD.bazel index 518a812b24..ec2a4ded19 100644 --- a/python/BUILD.bazel +++ b/python/BUILD.bazel @@ -24,6 +24,7 @@ In an ideal renaming, we'd move the packaging rules to a different package so that @rules_python//python is only concerned with the core rules. """ +# TODO: make current_py_toolchain.bzl private # gazelle:resolve starlark @rules_python//python:current_py_toolchain.bzl //python:current_py_toolchain_bzl # gazelle:resolve starlark //python:current_py_toolchain.bzl //python:current_py_toolchain_bzl @@ -77,7 +78,6 @@ filegroup( # ========= Core rules ========= -# @unused exports_files([ "defs.bzl", "python.bzl", # Deprecated, please use defs.bzl @@ -106,7 +106,6 @@ exports_files([ # ... # }), # ... -# ... # ) # # Caution: Do not `select()` on the built-in command-line flags `--force_python` @@ -179,6 +178,7 @@ current_py_toolchain( name = "current_py_toolchain", ) +# Keep this target because it is a public API and Gazelle might otherwise remove it if it is not loaded by other bzl_library targets. # keep bzl_library( name = "current_py_toolchain_bzl", @@ -202,23 +202,11 @@ bzl_library( ], ) -alias( - name = "defs_bzl", - actual = ":defs", - deprecation = "Use //python:defs instead", -) - bzl_library( name = "features", srcs = ["features.bzl"], ) -alias( - name = "features_bzl", - actual = ":features", - deprecation = "Use //python:features instead", -) - bzl_library( name = "packaging", srcs = ["packaging.bzl"], @@ -232,12 +220,6 @@ bzl_library( ], ) -alias( - name = "packaging_bzl", - actual = ":packaging", - deprecation = "Use //python:packaging instead", -) - bzl_library( name = "pip", srcs = ["pip.bzl"], @@ -252,156 +234,78 @@ bzl_library( ], ) -alias( - name = "pip_bzl", - actual = ":pip", - deprecation = "Use //python:pip instead", -) - bzl_library( name = "proto", srcs = ["proto.bzl"], deps = ["@com_google_protobuf//bazel:py_proto_library_bzl"], ) -alias( - name = "proto_bzl", - actual = ":proto", - deprecation = "Use //python:proto instead", -) - bzl_library( name = "py_binary", srcs = ["py_binary.bzl"], deps = ["//python/private:py_binary_macro"], ) -alias( - name = "py_binary_bzl", - actual = ":py_binary", - deprecation = "Use //python:py_binary instead", -) - bzl_library( name = "py_cc_link_params_info", srcs = ["py_cc_link_params_info.bzl"], deps = ["//python/private:py_cc_link_params_info"], ) -alias( - name = "py_cc_link_params_info_bzl", - actual = ":py_cc_link_params_info", - deprecation = "Use //python:py_cc_link_params_info instead", -) - bzl_library( name = "py_exec_tools_info", srcs = ["py_exec_tools_info.bzl"], deps = ["//python/private:py_exec_tools_info"], ) -alias( - name = "py_exec_tools_info_bzl", - actual = ":py_exec_tools_info", - deprecation = "Use //python:py_exec_tools_info instead", -) - bzl_library( name = "py_exec_tools_toolchain", srcs = ["py_exec_tools_toolchain.bzl"], deps = ["//python/private:py_exec_tools_toolchain"], ) -alias( - name = "py_exec_tools_toolchain_bzl", - actual = ":py_exec_tools_toolchain", - deprecation = "Use //python:py_exec_tools_toolchain instead", -) - bzl_library( name = "py_executable_info", srcs = ["py_executable_info.bzl"], deps = ["//python/private:py_executable_info"], ) -alias( - name = "py_executable_info_bzl", - actual = ":py_executable_info", - deprecation = "Use //python:py_executable_info instead", -) - bzl_library( name = "py_import", srcs = ["py_import.bzl"], deps = [":py_info"], ) -alias( - name = "py_import_bzl", - actual = ":py_import", - deprecation = "Use //python:py_import instead", -) - bzl_library( name = "py_info", srcs = ["py_info.bzl"], deps = ["//python/private:py_info"], ) -alias( - name = "py_info_bzl", - actual = ":py_info", - deprecation = "Use //python:py_info instead", -) - bzl_library( name = "py_library", srcs = ["py_library.bzl"], deps = ["//python/private:py_library_macro"], ) -alias( - name = "py_library_bzl", - actual = ":py_library", - deprecation = "Use //python:py_library instead", -) - bzl_library( name = "py_runtime", srcs = ["py_runtime.bzl"], deps = ["//python/private:py_runtime_macro"], ) -alias( - name = "py_runtime_bzl", - actual = ":py_runtime", - deprecation = "Use //python:py_runtime instead", -) - bzl_library( name = "py_runtime_info", srcs = ["py_runtime_info.bzl"], deps = ["//python/private:py_runtime_info"], ) -alias( - name = "py_runtime_info_bzl", - actual = ":py_runtime_info", - deprecation = "Use //python:py_runtime_info instead", -) - bzl_library( name = "py_runtime_pair", srcs = ["py_runtime_pair.bzl"], deps = ["//python/private:py_runtime_pair_macro"], ) -alias( - name = "py_runtime_pair_bzl", - actual = ":py_runtime_pair", - deprecation = "Use //python:py_runtime_pair instead", -) - # keep bzl_library( name = "py_test", @@ -409,23 +313,11 @@ bzl_library( deps = ["//python/private:py_test_macro"], ) -alias( - name = "py_test_bzl", - actual = ":py_test", - deprecation = "Use //python:py_test instead", -) - bzl_library( name = "python", srcs = ["python.bzl"], ) -alias( - name = "python_bzl", - actual = ":python", - deprecation = "Use //python:python instead", -) - bzl_library( name = "repositories", srcs = ["repositories.bzl"], @@ -438,12 +330,6 @@ bzl_library( ], ) -alias( - name = "repositories_bzl", - actual = ":repositories", - deprecation = "Use //python:repositories instead", -) - bzl_library( name = "versions", srcs = ["versions.bzl"], @@ -454,6 +340,120 @@ bzl_library( ], ) +alias( + name = "defs_bzl", + actual = ":defs", + deprecation = "Use //python:defs instead", +) + +alias( + name = "features_bzl", + actual = ":features", + deprecation = "Use //python:features instead", +) + +alias( + name = "packaging_bzl", + actual = ":packaging", + deprecation = "Use //python:packaging instead", +) + +alias( + name = "pip_bzl", + actual = ":pip", + deprecation = "Use //python:pip instead", +) + +alias( + name = "proto_bzl", + actual = ":proto", + deprecation = "Use //python:proto instead", +) + +alias( + name = "py_binary_bzl", + actual = ":py_binary", + deprecation = "Use //python:py_binary instead", +) + +alias( + name = "py_cc_link_params_info_bzl", + actual = ":py_cc_link_params_info", + deprecation = "Use //python:py_cc_link_params_info instead", +) + +alias( + name = "py_exec_tools_info_bzl", + actual = ":py_exec_tools_info", + deprecation = "Use //python:py_exec_tools_info instead", +) + +alias( + name = "py_exec_tools_toolchain_bzl", + actual = ":py_exec_tools_toolchain", + deprecation = "Use //python:py_exec_tools_toolchain instead", +) + +alias( + name = "py_executable_info_bzl", + actual = ":py_executable_info", + deprecation = "Use //python:py_executable_info instead", +) + +alias( + name = "py_import_bzl", + actual = ":py_import", + deprecation = "Use //python:py_import instead", +) + +alias( + name = "py_info_bzl", + actual = ":py_info", + deprecation = "Use //python:py_info instead", +) + +alias( + name = "py_library_bzl", + actual = ":py_library", + deprecation = "Use //python:py_library instead", +) + +alias( + name = "py_runtime_bzl", + actual = ":py_runtime", + deprecation = "Use //python:py_runtime instead", +) + +alias( + name = "py_runtime_info_bzl", + actual = ":py_runtime_info", + deprecation = "Use //python:py_runtime_info instead", +) + +alias( + name = "py_runtime_pair_bzl", + actual = ":py_runtime_pair", + deprecation = "Use //python:py_runtime_pair instead", +) + +alias( + name = "py_test_bzl", + actual = ":py_test", + deprecation = "Use //python:py_test instead", +) + +alias( + name = "python_bzl", + actual = ":python", + deprecation = "Use //python:python instead", +) + +alias( + name = "repositories_bzl", + actual = ":repositories", + deprecation = "Use //python:repositories instead", +) + alias( name = "versions_bzl", actual = ":versions", diff --git a/python/features.bzl b/python/features.bzl index 0314bb3765..ee850ade9e 100644 --- a/python/features.bzl +++ b/python/features.bzl @@ -49,6 +49,15 @@ def _features_typedef(): ::: :::: + ::::{field} loadable_symbols + :type: dict[str, list[str]] + + A map of bzl paths to the list of public symbols they export. + + :::{versionadded} VERSION_NEXT_FEATURE + ::: + :::: + ::::{field} py_info_venv_symlinks True if the `PyInfo.venv_symlinks` field is available. @@ -81,15 +90,6 @@ def _features_typedef(): :::{versionadded} 1.9.0 :::: - - ::::{field} loadable_symbols - :type: dict[str, list[str]] - - A map of bzl paths to the list of public symbols they export. - - :::{versionadded} VERSION_NEXT_FEATURE - ::: - :::: """ _TARGETS = { diff --git a/python/private/BUILD.bazel b/python/private/BUILD.bazel index 12d9dd039a..24ff9002ba 100644 --- a/python/private/BUILD.bazel +++ b/python/private/BUILD.bazel @@ -74,37 +74,6 @@ define_uncachable_version_file( name = "uncachable_version_file", ) -# @bazel_tools can't define bzl_library itself, so we just put a wrapper around it. -# keep -bzl_library( - name = "bazel_tools", - srcs = [ - # This set of sources is overly broad, but it's the only public - # target available across Bazel versions that has all the necessary - # sources. - "@bazel_tools//tools:bzl_srcs", - ], -) - -# keep -bzl_library( - name = "rules_cc_srcs", - srcs = [ - # rules_cc 0.0.13 and earlier load cc_proto_libary (and thus protobuf@), - # but their bzl srcs targets don't transitively refer to protobuf. - "@com_google_protobuf//:bzl_srcs", - # NOTE: As of rules_cc 0.10, cc:bzl_srcs no longer contains - # everything and sub-targets must be used instead - "@rules_cc//cc:bzl_srcs", - "@rules_cc//cc/common", - "@rules_cc//cc/toolchains:toolchain_rules", - ], - deps = [ - ":bazel_tools", - "@rules_cc//cc/common", - ], -) - # Needed to define bzl_library targets for docgen. (We don't define the # bzl_library target here because it'd give our users a transitive dependency # on Skylib.) @@ -276,6 +245,25 @@ bzl_library( ], ) +bzl_library( + name = "auth", + srcs = ["auth.bzl"], + deps = ["//python/private:bazel_tools"], +) + +# @bazel_tools can't define bzl_library itself, so we just put a wrapper around it. +# Keep this target because Gazelle does not automatically generate bzl_library targets for external repositories like @bazel_tools. +# keep +bzl_library( + name = "bazel_tools", + srcs = [ + # This set of sources is overly broad, but it's the only public + # target available across Bazel versions that has all the necessary + # sources. + "@bazel_tools//tools:bzl_srcs", + ], +) + bzl_library( name = "builders", srcs = ["builders.bzl"], @@ -291,6 +279,11 @@ bzl_library( ], ) +bzl_library( + name = "bzlmod_enabled", + srcs = ["bzlmod_enabled.bzl"], +) + bzl_library( name = "cc_helper", srcs = ["cc_helper.bzl"], @@ -315,6 +308,11 @@ bzl_library( ], ) +bzl_library( + name = "common_labels", + srcs = ["common_labels.bzl"], +) + bzl_library( name = "config_settings", srcs = ["config_settings.bzl"], @@ -326,6 +324,16 @@ bzl_library( ], ) +bzl_library( + name = "coverage_deps", + srcs = ["coverage_deps.bzl"], + deps = [ + ":repo_utils", + ":version_label", + "//python/private:bazel_tools", + ], +) + bzl_library( name = "current_py_cc_headers", srcs = ["current_py_cc_headers.bzl"], @@ -347,6 +355,16 @@ bzl_library( deps = ["@rules_python_internal//:rules_python_config"], ) +bzl_library( + name = "enum", + srcs = ["enum.bzl"], +) + +bzl_library( + name = "envsubst", + srcs = ["envsubst.bzl"], +) + bzl_library( name = "flags", srcs = ["flags.bzl"], @@ -356,6 +374,11 @@ bzl_library( ], ) +bzl_library( + name = "full_version", + srcs = ["full_version.bzl"], +) + bzl_library( name = "hermetic_runtime_repo_setup", srcs = ["hermetic_runtime_repo_setup.bzl"], @@ -378,6 +401,18 @@ bzl_library( ], ) +bzl_library( + name = "interpreter", + srcs = ["interpreter.bzl"], + deps = [ + ":common", + ":sentinel_impl", + ":toolchain_types", + "//python:py_runtime_info", + "@bazel_skylib//lib:paths", + ], +) + bzl_library( name = "is_standalone_interpreter", srcs = ["is_standalone_interpreter.bzl"], @@ -415,6 +450,21 @@ bzl_library( ], ) +bzl_library( + name = "normalize_name", + srcs = ["normalize_name.bzl"], +) + +bzl_library( + name = "pbs_manifest", + srcs = ["pbs_manifest.bzl"], +) + +bzl_library( + name = "platform_info", + srcs = ["platform_info.bzl"], +) + bzl_library( name = "precompile", srcs = ["precompile.bzl"], @@ -451,6 +501,11 @@ bzl_library( deps = ["@rules_cc//cc/common"], ) +bzl_library( + name = "py_cc_toolchain_info", + srcs = ["py_cc_toolchain_info.bzl"], +) + bzl_library( name = "py_cc_toolchain_macro", srcs = ["py_cc_toolchain_macro.bzl"], @@ -460,6 +515,18 @@ bzl_library( ], ) +bzl_library( + name = "py_cc_toolchain_rule", + srcs = ["py_cc_toolchain_rule.bzl"], + deps = [ + ":common_labels", + ":py_cc_toolchain_info", + ":sentinel_impl", + "@bazel_skylib//rules:common_settings", + "@rules_cc//cc/common", + ], +) + bzl_library( name = "py_console_script_binary", srcs = ["py_console_script_binary.bzl"], @@ -469,6 +536,29 @@ bzl_library( ], ) +bzl_library( + name = "py_console_script_gen", + srcs = ["py_console_script_gen.bzl"], +) + +bzl_library( + name = "py_exec_tools_info", + srcs = ["py_exec_tools_info.bzl"], +) + +bzl_library( + name = "py_exec_tools_toolchain", + srcs = ["py_exec_tools_toolchain.bzl"], + deps = [ + ":common_labels", + ":py_exec_tools_info", + ":sentinel_impl", + ":toolchain_types", + "@bazel_skylib//lib:paths", + "@bazel_skylib//rules:common_settings", + ], +) + bzl_library( name = "py_executable", srcs = ["py_executable.bzl"], @@ -500,6 +590,11 @@ bzl_library( ], ) +bzl_library( + name = "py_executable_info", + srcs = ["py_executable_info.bzl"], +) + bzl_library( name = "py_info", srcs = ["py_info.bzl"], @@ -512,7 +607,16 @@ bzl_library( bzl_library( name = "py_internal", srcs = ["py_internal.bzl"], - deps = ["//tools/build_defs/python/private:py_internal_renamed"], + deps = ["//tools/build_defs/python/private:py_internal_renamed_bzl"], +) + +bzl_library( + name = "py_interpreter_program", + srcs = ["py_interpreter_program.bzl"], + deps = [ + ":sentinel_impl", + "@bazel_skylib//rules:common_settings", + ], ) bzl_library( @@ -561,6 +665,23 @@ bzl_library( ], ) +bzl_library( + name = "py_repositories", + srcs = ["py_repositories.bzl"], + deps = [ + ":internal_config_repo", + ":pythons_hub", + "//python:versions", + "//python/private:bazel_tools", + "//python/private/pypi:deps", + ], +) + +bzl_library( + name = "py_runtime_info", + srcs = ["py_runtime_info.bzl"], +) + bzl_library( name = "py_runtime_macro", srcs = ["py_runtime_macro.bzl"], @@ -630,6 +751,20 @@ bzl_library( ], ) +bzl_library( + name = "py_wheel", + srcs = ["py_wheel.bzl"], + deps = [ + ":attributes", + ":py_info", + ":py_package", + ":rule_builders", + ":stamp_impl", + ":transition_labels", + ":version", + ], +) + bzl_library( name = "python", srcs = ["python.bzl"], @@ -705,6 +840,11 @@ bzl_library( deps = ["//python:py_binary"], ) +bzl_library( + name = "repo_utils", + srcs = ["repo_utils.bzl"], +) + bzl_library( name = "rule_builders", srcs = ["rule_builders.bzl"], @@ -714,6 +854,26 @@ bzl_library( ], ) +# Keep this target because Gazelle does not automatically generate or maintain composite bzl_library targets. We need this to group external dependency sources. +# keep +bzl_library( + name = "rules_cc_srcs", + srcs = [ + # rules_cc 0.0.13 and earlier load cc_proto_libary (and thus protobuf@), + # but their bzl srcs targets don't transitively refer to protobuf. + "@com_google_protobuf//:bzl_srcs", + # NOTE: As of rules_cc 0.10, cc:bzl_srcs no longer contains + # everything and sub-targets must be used instead + "@rules_cc//cc:bzl_srcs", + "@rules_cc//cc/common", + "@rules_cc//cc/toolchains:toolchain_rules", + ], + deps = [ + ":bazel_tools", + "@rules_cc//cc/common", + ], +) + bzl_library( name = "runtime_env_repo", srcs = ["runtime_env_repo.bzl"], @@ -734,6 +894,26 @@ bzl_library( ], ) +bzl_library( + name = "runtimes_manifest_workspace", + srcs = ["runtimes_manifest_workspace.bzl"], +) + +bzl_library( + name = "sentinel_impl", + srcs = ["sentinel_impl.bzl"], +) + +bzl_library( + name = "stamp_impl", + srcs = ["stamp_impl.bzl"], +) + +bzl_library( + name = "text_util", + srcs = ["text_util.bzl"], +) + bzl_library( name = "toolchain_aliases", srcs = ["toolchain_aliases.bzl"], @@ -743,6 +923,11 @@ bzl_library( ], ) +bzl_library( + name = "toolchain_types", + srcs = ["toolchain_types.bzl"], +) + bzl_library( name = "toolchains_repo", srcs = ["toolchains_repo.bzl"], @@ -783,189 +968,6 @@ bzl_library( ], ) -bzl_library( - name = "auth", - srcs = ["auth.bzl"], - deps = ["//python/private:bazel_tools"], -) - -bzl_library( - name = "coverage_deps", - srcs = ["coverage_deps.bzl"], - deps = [ - ":repo_utils", - ":version_label", - "//python/private:bazel_tools", - ], -) - -bzl_library( - name = "py_repositories", - srcs = ["py_repositories.bzl"], - deps = [ - ":internal_config_repo", - ":pythons_hub", - "//python:versions", - "//python/private:bazel_tools", - "//python/private/pypi:deps", - ], -) - -bzl_library( - name = "py_wheel", - srcs = ["py_wheel.bzl"], - deps = [ - ":attributes", - ":py_info", - ":py_package", - ":rule_builders", - ":stamp_impl", - ":transition_labels", - ":version", - ], -) - -bzl_library( - name = "interpreter", - srcs = ["interpreter.bzl"], - deps = [ - ":common", - ":sentinel_impl", - ":toolchain_types", - "//python:py_runtime_info", - "@bazel_skylib//lib:paths", - ], -) - -bzl_library( - name = "py_cc_toolchain_rule", - srcs = ["py_cc_toolchain_rule.bzl"], - deps = [ - ":common_labels", - ":py_cc_toolchain_info", - ":sentinel_impl", - "@bazel_skylib//rules:common_settings", - "@rules_cc//cc/common", - ], -) - -bzl_library( - name = "py_exec_tools_toolchain", - srcs = ["py_exec_tools_toolchain.bzl"], - deps = [ - ":common_labels", - ":py_exec_tools_info", - ":sentinel_impl", - ":toolchain_types", - "@bazel_skylib//lib:paths", - "@bazel_skylib//rules:common_settings", - ], -) - -bzl_library( - name = "py_interpreter_program", - srcs = ["py_interpreter_program.bzl"], - deps = [ - ":sentinel_impl", - "@bazel_skylib//rules:common_settings", - ], -) - -bzl_library( - name = "bzlmod_enabled", - srcs = ["bzlmod_enabled.bzl"], -) - -bzl_library( - name = "common_labels", - srcs = ["common_labels.bzl"], -) - -bzl_library( - name = "enum", - srcs = ["enum.bzl"], -) - -bzl_library( - name = "envsubst", - srcs = ["envsubst.bzl"], -) - -bzl_library( - name = "full_version", - srcs = ["full_version.bzl"], -) - -bzl_library( - name = "normalize_name", - srcs = ["normalize_name.bzl"], -) - -bzl_library( - name = "pbs_manifest", - srcs = ["pbs_manifest.bzl"], -) - -bzl_library( - name = "platform_info", - srcs = ["platform_info.bzl"], -) - -bzl_library( - name = "py_cc_toolchain_info", - srcs = ["py_cc_toolchain_info.bzl"], -) - -bzl_library( - name = "py_console_script_gen", - srcs = ["py_console_script_gen.bzl"], -) - -bzl_library( - name = "py_exec_tools_info", - srcs = ["py_exec_tools_info.bzl"], -) - -bzl_library( - name = "py_executable_info", - srcs = ["py_executable_info.bzl"], -) - -bzl_library( - name = "py_runtime_info", - srcs = ["py_runtime_info.bzl"], -) - -bzl_library( - name = "repo_utils", - srcs = ["repo_utils.bzl"], -) - -bzl_library( - name = "runtimes_manifest_workspace", - srcs = ["runtimes_manifest_workspace.bzl"], -) - -bzl_library( - name = "sentinel_impl", - srcs = ["sentinel_impl.bzl"], -) - -bzl_library( - name = "stamp_impl", - srcs = ["stamp_impl.bzl"], -) - -bzl_library( - name = "text_util", - srcs = ["text_util.bzl"], -) - -bzl_library( - name = "toolchain_types", - srcs = ["toolchain_types.bzl"], -) - bzl_library( name = "version", srcs = ["version.bzl"], diff --git a/python/private/pythons_hub.bzl b/python/private/pythons_hub.bzl index d6f6bcec92..c64abf9887 100644 --- a/python/private/pythons_hub.bzl +++ b/python/private/pythons_hub.bzl @@ -36,28 +36,12 @@ bzl_library( visibility = ["@rules_python//:__subpackages__"], ) -# deprecated: use :interpreters instead -alias( - name = "interpreters_bzl", - actual = ":interpreters", - deprecation = "Use :interpreters instead. The _bzl suffix targets are deprecated and will be removed in a future release.", - visibility = ["@rules_python//:__subpackages__"], -) - bzl_library( name = "versions", srcs = ["versions.bzl"], visibility = ["@rules_python//:__subpackages__"], ) -# deprecated: use :versions instead -alias( - name = "versions_bzl", - actual = ":versions", - deprecation = "Use :versions instead. The _bzl suffix targets are deprecated and will be removed in a future release.", - visibility = ["@rules_python//:__subpackages__"], -) - {toolchains} """ diff --git a/tools/build_defs/python/private/BUILD.bazel b/tools/build_defs/python/private/BUILD.bazel index bb15727346..d57807f574 100644 --- a/tools/build_defs/python/private/BUILD.bazel +++ b/tools/build_defs/python/private/BUILD.bazel @@ -20,9 +20,8 @@ filegroup( visibility = ["//python:__subpackages__"], ) -# keep bzl_library( - name = "py_internal_renamed", + name = "py_internal_renamed_bzl", srcs = ["py_internal_renamed.bzl"], - visibility = ["//python/private:__pkg__"], + visibility = ["//:__subpackages__"], ) From 87b7f378765bdc9e086702a266647fc74b7d9acb Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 28 Jun 2026 03:26:08 +0000 Subject: [PATCH 22/36] Address final code review comments and intersperse aliases Wrap explanatory comments to 80 columns and revert the internal target rename in the tools package. Additionally, sort and intersperse the deprecated aliases with their respective Starlark library targets in the Python package. --- python/BUILD.bazel | 231 ++++++++++---------- python/private/BUILD.bazel | 9 +- tools/build_defs/python/private/BUILD.bazel | 3 +- 3 files changed, 124 insertions(+), 119 deletions(-) diff --git a/python/BUILD.bazel b/python/BUILD.bazel index ec2a4ded19..1da9ab4a8c 100644 --- a/python/BUILD.bazel +++ b/python/BUILD.bazel @@ -178,7 +178,8 @@ current_py_toolchain( name = "current_py_toolchain", ) -# Keep this target because it is a public API and Gazelle might otherwise remove it if it is not loaded by other bzl_library targets. +# Keep this target because it is a public API and Gazelle might otherwise +# remove it if it is not loaded by other bzl_library targets. # keep bzl_library( name = "current_py_toolchain_bzl", @@ -202,11 +203,23 @@ bzl_library( ], ) +alias( + name = "defs_bzl", + actual = ":defs", + deprecation = "Use //python:defs instead", +) + bzl_library( name = "features", srcs = ["features.bzl"], ) +alias( + name = "features_bzl", + actual = ":features", + deprecation = "Use //python:features instead", +) + bzl_library( name = "packaging", srcs = ["packaging.bzl"], @@ -220,6 +233,12 @@ bzl_library( ], ) +alias( + name = "packaging_bzl", + actual = ":packaging", + deprecation = "Use //python:packaging instead", +) + bzl_library( name = "pip", srcs = ["pip.bzl"], @@ -234,78 +253,156 @@ bzl_library( ], ) +alias( + name = "pip_bzl", + actual = ":pip", + deprecation = "Use //python:pip instead", +) + bzl_library( name = "proto", srcs = ["proto.bzl"], deps = ["@com_google_protobuf//bazel:py_proto_library_bzl"], ) +alias( + name = "proto_bzl", + actual = ":proto", + deprecation = "Use //python:proto instead", +) + bzl_library( name = "py_binary", srcs = ["py_binary.bzl"], deps = ["//python/private:py_binary_macro"], ) +alias( + name = "py_binary_bzl", + actual = ":py_binary", + deprecation = "Use //python:py_binary instead", +) + bzl_library( name = "py_cc_link_params_info", srcs = ["py_cc_link_params_info.bzl"], deps = ["//python/private:py_cc_link_params_info"], ) +alias( + name = "py_cc_link_params_info_bzl", + actual = ":py_cc_link_params_info", + deprecation = "Use //python:py_cc_link_params_info instead", +) + bzl_library( name = "py_exec_tools_info", srcs = ["py_exec_tools_info.bzl"], deps = ["//python/private:py_exec_tools_info"], ) +alias( + name = "py_exec_tools_info_bzl", + actual = ":py_exec_tools_info", + deprecation = "Use //python:py_exec_tools_info instead", +) + bzl_library( name = "py_exec_tools_toolchain", srcs = ["py_exec_tools_toolchain.bzl"], deps = ["//python/private:py_exec_tools_toolchain"], ) +alias( + name = "py_exec_tools_toolchain_bzl", + actual = ":py_exec_tools_toolchain", + deprecation = "Use //python:py_exec_tools_toolchain instead", +) + bzl_library( name = "py_executable_info", srcs = ["py_executable_info.bzl"], deps = ["//python/private:py_executable_info"], ) +alias( + name = "py_executable_info_bzl", + actual = ":py_executable_info", + deprecation = "Use //python:py_executable_info instead", +) + bzl_library( name = "py_import", srcs = ["py_import.bzl"], deps = [":py_info"], ) +alias( + name = "py_import_bzl", + actual = ":py_import", + deprecation = "Use //python:py_import instead", +) + bzl_library( name = "py_info", srcs = ["py_info.bzl"], deps = ["//python/private:py_info"], ) +alias( + name = "py_info_bzl", + actual = ":py_info", + deprecation = "Use //python:py_info instead", +) + bzl_library( name = "py_library", srcs = ["py_library.bzl"], deps = ["//python/private:py_library_macro"], ) +alias( + name = "py_library_bzl", + actual = ":py_library", + deprecation = "Use //python:py_library instead", +) + bzl_library( name = "py_runtime", srcs = ["py_runtime.bzl"], deps = ["//python/private:py_runtime_macro"], ) +alias( + name = "py_runtime_bzl", + actual = ":py_runtime", + deprecation = "Use //python:py_runtime instead", +) + bzl_library( name = "py_runtime_info", srcs = ["py_runtime_info.bzl"], deps = ["//python/private:py_runtime_info"], ) +alias( + name = "py_runtime_info_bzl", + actual = ":py_runtime_info", + deprecation = "Use //python:py_runtime_info instead", +) + bzl_library( name = "py_runtime_pair", srcs = ["py_runtime_pair.bzl"], deps = ["//python/private:py_runtime_pair_macro"], ) +alias( + name = "py_runtime_pair_bzl", + actual = ":py_runtime_pair", + deprecation = "Use //python:py_runtime_pair instead", +) + # keep bzl_library( name = "py_test", @@ -313,11 +410,23 @@ bzl_library( deps = ["//python/private:py_test_macro"], ) +alias( + name = "py_test_bzl", + actual = ":py_test", + deprecation = "Use //python:py_test instead", +) + bzl_library( name = "python", srcs = ["python.bzl"], ) +alias( + name = "python_bzl", + actual = ":python", + deprecation = "Use //python:python instead", +) + bzl_library( name = "repositories", srcs = ["repositories.bzl"], @@ -330,6 +439,12 @@ bzl_library( ], ) +alias( + name = "repositories_bzl", + actual = ":repositories", + deprecation = "Use //python:repositories instead", +) + bzl_library( name = "versions", srcs = ["versions.bzl"], @@ -340,120 +455,6 @@ bzl_library( ], ) -alias( - name = "defs_bzl", - actual = ":defs", - deprecation = "Use //python:defs instead", -) - -alias( - name = "features_bzl", - actual = ":features", - deprecation = "Use //python:features instead", -) - -alias( - name = "packaging_bzl", - actual = ":packaging", - deprecation = "Use //python:packaging instead", -) - -alias( - name = "pip_bzl", - actual = ":pip", - deprecation = "Use //python:pip instead", -) - -alias( - name = "proto_bzl", - actual = ":proto", - deprecation = "Use //python:proto instead", -) - -alias( - name = "py_binary_bzl", - actual = ":py_binary", - deprecation = "Use //python:py_binary instead", -) - -alias( - name = "py_cc_link_params_info_bzl", - actual = ":py_cc_link_params_info", - deprecation = "Use //python:py_cc_link_params_info instead", -) - -alias( - name = "py_exec_tools_info_bzl", - actual = ":py_exec_tools_info", - deprecation = "Use //python:py_exec_tools_info instead", -) - -alias( - name = "py_exec_tools_toolchain_bzl", - actual = ":py_exec_tools_toolchain", - deprecation = "Use //python:py_exec_tools_toolchain instead", -) - -alias( - name = "py_executable_info_bzl", - actual = ":py_executable_info", - deprecation = "Use //python:py_executable_info instead", -) - -alias( - name = "py_import_bzl", - actual = ":py_import", - deprecation = "Use //python:py_import instead", -) - -alias( - name = "py_info_bzl", - actual = ":py_info", - deprecation = "Use //python:py_info instead", -) - -alias( - name = "py_library_bzl", - actual = ":py_library", - deprecation = "Use //python:py_library instead", -) - -alias( - name = "py_runtime_bzl", - actual = ":py_runtime", - deprecation = "Use //python:py_runtime instead", -) - -alias( - name = "py_runtime_info_bzl", - actual = ":py_runtime_info", - deprecation = "Use //python:py_runtime_info instead", -) - -alias( - name = "py_runtime_pair_bzl", - actual = ":py_runtime_pair", - deprecation = "Use //python:py_runtime_pair instead", -) - -alias( - name = "py_test_bzl", - actual = ":py_test", - deprecation = "Use //python:py_test instead", -) - -alias( - name = "python_bzl", - actual = ":python", - deprecation = "Use //python:python instead", -) - -alias( - name = "repositories_bzl", - actual = ":repositories", - deprecation = "Use //python:repositories instead", -) - alias( name = "versions_bzl", actual = ":versions", diff --git a/python/private/BUILD.bazel b/python/private/BUILD.bazel index 24ff9002ba..7064f52cd3 100644 --- a/python/private/BUILD.bazel +++ b/python/private/BUILD.bazel @@ -252,7 +252,8 @@ bzl_library( ) # @bazel_tools can't define bzl_library itself, so we just put a wrapper around it. -# Keep this target because Gazelle does not automatically generate bzl_library targets for external repositories like @bazel_tools. +# Keep this target because Gazelle does not automatically generate +# bzl_library targets for external repositories like @bazel_tools. # keep bzl_library( name = "bazel_tools", @@ -607,7 +608,7 @@ bzl_library( bzl_library( name = "py_internal", srcs = ["py_internal.bzl"], - deps = ["//tools/build_defs/python/private:py_internal_renamed_bzl"], + deps = ["//tools/build_defs/python/private:py_internal_renamed"], ) bzl_library( @@ -854,7 +855,9 @@ bzl_library( ], ) -# Keep this target because Gazelle does not automatically generate or maintain composite bzl_library targets. We need this to group external dependency sources. +# Keep this target because Gazelle does not automatically generate or +# maintain composite bzl_library targets. We need this to group external +# dependency sources. # keep bzl_library( name = "rules_cc_srcs", diff --git a/tools/build_defs/python/private/BUILD.bazel b/tools/build_defs/python/private/BUILD.bazel index d57807f574..e189b18880 100644 --- a/tools/build_defs/python/private/BUILD.bazel +++ b/tools/build_defs/python/private/BUILD.bazel @@ -20,8 +20,9 @@ filegroup( visibility = ["//python:__subpackages__"], ) +# keep bzl_library( - name = "py_internal_renamed_bzl", + name = "py_internal_renamed", srcs = ["py_internal_renamed.bzl"], visibility = ["//:__subpackages__"], ) From 7f734da67afdf63b0293d97f7ec42726af3f238a Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 28 Jun 2026 03:43:29 +0000 Subject: [PATCH 23/36] Remove test helper target and exclude from Gazelle Remove the Starlark library target for the Gazelle test helper. Exclude the test helper file from Gazelle processing with an explanatory comment, as it is a test-only utility that does not require a public library target. --- gazelle/python/BUILD.bazel | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/gazelle/python/BUILD.bazel b/gazelle/python/BUILD.bazel index a283b2e48b..8218d0b6d9 100644 --- a/gazelle/python/BUILD.bazel +++ b/gazelle/python/BUILD.bazel @@ -1,5 +1,4 @@ load("@bazel_gazelle//:def.bzl", "gazelle_binary") -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@bazel_skylib//rules:copy_file.bzl", "copy_file") load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") load(":gazelle_test.bzl", "gazelle_test") @@ -67,6 +66,8 @@ copy_file( # gazelle:exclude testdata/ # gazelle:exclude extensions.bzl +# Exclude test-only Starlark helper from Gazelle to avoid generating an unnecessary bzl_library +# gazelle:exclude gazelle_test.bzl gazelle_test( name = "python_test", @@ -124,11 +125,3 @@ go_test( "@com_github_stretchr_testify//assert", ], ) - -# keep -bzl_library( - name = "gazelle_test", - srcs = ["gazelle_test.bzl"], - visibility = ["//visibility:public"], - deps = ["@io_bazel_rules_go//go:def"], -) From 21767ee4fdd72c68bbb34967b91c0824674d6629 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 28 Jun 2026 03:46:54 +0000 Subject: [PATCH 24/36] Remove config_settings/transition bzl_libraries and widen py_args visibility Remove the Starlark library targets for config_settings and transition, excluding them from Gazelle. Widen the visibility of the private py_args target to all subpackages in the repository. --- python/config_settings/BUILD.bazel | 23 ++++------------------ python/config_settings/private/BUILD.bazel | 2 +- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/python/config_settings/BUILD.bazel b/python/config_settings/BUILD.bazel index 2eb261e1d1..7037a06877 100644 --- a/python/config_settings/BUILD.bazel +++ b/python/config_settings/BUILD.bazel @@ -1,4 +1,3 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag") load("@pythons_hub//:versions.bzl", "DEFAULT_PYTHON_VERSION", "MINOR_MAPPING", "PYTHON_VERSIONS") load("@rules_python_internal//:rules_python_config.bzl", "config") @@ -18,6 +17,10 @@ load( load("//python/private/pypi:flags.bzl", "define_pypi_internal_flags") load(":config_settings.bzl", "construct_config_settings") +# Exclude Starlark files from Gazelle processing to avoid generating bzl_library targets +# gazelle:exclude config_settings.bzl +# gazelle:exclude transition.bzl + filegroup( name = "distribution", srcs = glob(["**"]) + [ @@ -218,21 +221,3 @@ string_flag( scope = "universal", visibility = ["//visibility:public"], ) - -bzl_library( - name = "config_settings", - srcs = ["config_settings.bzl"], - visibility = ["//:__subpackages__"], - deps = ["//python/private:config_settings"], -) - -bzl_library( - name = "transition", - srcs = ["transition.bzl"], - visibility = ["//:__subpackages__"], - deps = [ - "//python:py_binary", - "//python/private:deprecation", - "//python/private:text_util", - ], -) diff --git a/python/config_settings/private/BUILD.bazel b/python/config_settings/private/BUILD.bazel index 6b69ee8879..88cd689862 100644 --- a/python/config_settings/private/BUILD.bazel +++ b/python/config_settings/private/BUILD.bazel @@ -9,5 +9,5 @@ filegroup( bzl_library( name = "py_args", srcs = ["py_args.bzl"], - visibility = ["//python/config_settings:__subpackages__"], + visibility = ["//:__subpackages__"], ) From 6f15161b768923da137f92382bc8155dd7fea0d6 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 28 Jun 2026 03:47:44 +0000 Subject: [PATCH 25/36] Revise Gazelle exclude comment in config_settings Update the comment explaining why config_settings.bzl and transition.bzl are excluded from Gazelle to clarify that they are not public targets and should be moved. --- python/config_settings/BUILD.bazel | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/config_settings/BUILD.bazel b/python/config_settings/BUILD.bazel index 7037a06877..97761bea83 100644 --- a/python/config_settings/BUILD.bazel +++ b/python/config_settings/BUILD.bazel @@ -17,7 +17,8 @@ load( load("//python/private/pypi:flags.bzl", "define_pypi_internal_flags") load(":config_settings.bzl", "construct_config_settings") -# Exclude Starlark files from Gazelle processing to avoid generating bzl_library targets +# We don't generate bzl_library for these because they aren't public targets +# and should be moved # gazelle:exclude config_settings.bzl # gazelle:exclude transition.bzl From 7b7f2f7e86aca37e65699953c5f583a11ebadc5b Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 28 Jun 2026 03:50:31 +0000 Subject: [PATCH 26/36] Fix visibility for extensions and local_toolchains Align the visibility of targets in python/extensions/BUILD.bazel and python/local_toolchains/BUILD.bazel with their original definitions. Restrict extensions to subpackages and restore public access to local toolchains. --- python/extensions/BUILD.bazel | 6 ++++++ python/local_toolchains/BUILD.bazel | 2 ++ 2 files changed, 8 insertions(+) diff --git a/python/extensions/BUILD.bazel b/python/extensions/BUILD.bazel index 281067c76f..af18fa15b7 100644 --- a/python/extensions/BUILD.bazel +++ b/python/extensions/BUILD.bazel @@ -27,6 +27,7 @@ filegroup( bzl_library( name = "config", srcs = ["config.bzl"], + visibility = ["//:__subpackages__"], deps = [ "//python/private:internal_config_repo", "//python/private/pypi:deps", @@ -37,12 +38,14 @@ bzl_library( bzl_library( name = "pip", srcs = ["pip.bzl"], + visibility = ["//:__subpackages__"], deps = ["//python/private/pypi:pip"], ) bzl_library( name = "python", srcs = ["python.bzl"], + visibility = ["//:__subpackages__"], deps = ["//python/private:python"], ) @@ -50,16 +53,19 @@ alias( name = "config_bzl", actual = ":config", deprecation = "Use //python/extensions:config instead", + visibility = ["//:__subpackages__"], ) alias( name = "pip_bzl", actual = ":pip", deprecation = "Use //python/extensions:pip instead", + visibility = ["//:__subpackages__"], ) alias( name = "python_bzl", actual = ":python", deprecation = "Use //python/extensions:python instead", + visibility = ["//:__subpackages__"], ) diff --git a/python/local_toolchains/BUILD.bazel b/python/local_toolchains/BUILD.bazel index 7c4ad1a8e0..256dffb337 100644 --- a/python/local_toolchains/BUILD.bazel +++ b/python/local_toolchains/BUILD.bazel @@ -10,6 +10,7 @@ filegroup( bzl_library( name = "repos", srcs = ["repos.bzl"], + visibility = ["//visibility:public"], deps = [ "//python/private:local_runtime_repo", "//python/private:local_runtime_toolchains_repo", @@ -20,4 +21,5 @@ alias( name = "repos_bzl", actual = ":repos", deprecation = "Use //python/local_toolchains:repos instead", + visibility = ["//visibility:public"], ) From 5837b5d40a01f267583f854c320a79113c25571d Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 28 Jun 2026 03:55:43 +0000 Subject: [PATCH 27/36] Sort targets in python/private/pypi Sort all bzl_library targets alphabetically in python/private/pypi/BUILD.bazel to maintain project style conventions. --- python/private/pypi/BUILD.bazel | 129 ++++++++++++++++---------------- 1 file changed, 64 insertions(+), 65 deletions(-) diff --git a/python/private/pypi/BUILD.bazel b/python/private/pypi/BUILD.bazel index 5faa0ff1a7..c7b1d793c2 100644 --- a/python/private/pypi/BUILD.bazel +++ b/python/private/pypi/BUILD.bazel @@ -74,6 +74,15 @@ filegroup( visibility = ["//tools/private/update_deps:__pkg__"], ) +bzl_library( + name = "argparse", + srcs = ["argparse.bzl"], +) + +bzl_library( + name = "attrs", + srcs = ["attrs.bzl"], +) # Keep sorted by library name and keep the files named by the main symbol they export bzl_library( @@ -88,6 +97,11 @@ bzl_library( deps = ["//python/private:bazel_tools"], ) +bzl_library( + name = "env_marker_info", + srcs = ["env_marker_info.bzl"], +) + bzl_library( name = "env_marker_setting", srcs = ["env_marker_setting.bzl"], @@ -194,6 +208,16 @@ bzl_library( ], ) +bzl_library( + name = "index_sources", + srcs = ["index_sources.bzl"], +) + +bzl_library( + name = "labels", + srcs = ["labels.bzl"], +) + bzl_library( name = "missing_package", srcs = ["missing_package.bzl"], @@ -218,6 +242,11 @@ bzl_library( deps = ["@bazel_skylib//rules:copy_file"], ) +bzl_library( + name = "package_annotation", + srcs = ["package_annotation.bzl"], +) + bzl_library( name = "parse_requirements", srcs = ["parse_requirements.bzl"], @@ -234,6 +263,11 @@ bzl_library( ], ) +bzl_library( + name = "parse_requirements_txt", + srcs = ["parse_requirements_txt.bzl"], +) + bzl_library( name = "parse_simpleapi_html", srcs = ["parse_simpleapi_html.bzl"], @@ -243,6 +277,11 @@ bzl_library( ], ) +bzl_library( + name = "parse_whl_name", + srcs = ["parse_whl_name.bzl"], +) + bzl_library( name = "patch_whl", srcs = ["patch_whl.bzl"], @@ -337,6 +376,11 @@ bzl_library( ], ) +bzl_library( + name = "platform", + srcs = ["platform.bzl"], +) + bzl_library( name = "pypi_cache", srcs = ["pypi_cache.bzl"], @@ -415,6 +459,11 @@ bzl_library( ], ) +bzl_library( + name = "urllib", + srcs = ["urllib.bzl"], +) + bzl_library( name = "venv_entry_point", srcs = ["venv_entry_point.bzl"], @@ -436,6 +485,11 @@ bzl_library( ], ) +bzl_library( + name = "version_from_filename", + srcs = ["version_from_filename.bzl"], +) + bzl_library( name = "whl_config_repo", srcs = ["whl_config_repo.bzl"], @@ -445,6 +499,11 @@ bzl_library( ], ) +bzl_library( + name = "whl_config_setting", + srcs = ["whl_config_setting.bzl"], +) + bzl_library( name = "whl_extract", srcs = ["whl_extract.bzl"], @@ -502,6 +561,11 @@ bzl_library( ], ) +bzl_library( + name = "whl_metadata", + srcs = ["whl_metadata.bzl"], +) + bzl_library( name = "whl_repo_name", srcs = ["whl_repo_name.bzl"], @@ -511,71 +575,6 @@ bzl_library( ], ) -bzl_library( - name = "argparse", - srcs = ["argparse.bzl"], -) - -bzl_library( - name = "attrs", - srcs = ["attrs.bzl"], -) - -bzl_library( - name = "env_marker_info", - srcs = ["env_marker_info.bzl"], -) - -bzl_library( - name = "index_sources", - srcs = ["index_sources.bzl"], -) - -bzl_library( - name = "labels", - srcs = ["labels.bzl"], -) - -bzl_library( - name = "package_annotation", - srcs = ["package_annotation.bzl"], -) - -bzl_library( - name = "parse_requirements_txt", - srcs = ["parse_requirements_txt.bzl"], -) - -bzl_library( - name = "parse_whl_name", - srcs = ["parse_whl_name.bzl"], -) - -bzl_library( - name = "platform", - srcs = ["platform.bzl"], -) - -bzl_library( - name = "urllib", - srcs = ["urllib.bzl"], -) - -bzl_library( - name = "version_from_filename", - srcs = ["version_from_filename.bzl"], -) - -bzl_library( - name = "whl_config_setting", - srcs = ["whl_config_setting.bzl"], -) - -bzl_library( - name = "whl_metadata", - srcs = ["whl_metadata.bzl"], -) - bzl_library( name = "whl_target_platforms", srcs = ["whl_target_platforms.bzl"], From bc329da5f2c95005ce772e6ee75d23e876f631cc Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 28 Jun 2026 05:48:06 +0000 Subject: [PATCH 28/36] Delete unused py_args.bzl and its test Remove python/config_settings/private/py_args.bzl and tests/config_settings/transition/py_args_tests.bzl as they are no longer used in the repository. Clean up their respective BUILD files. --- python/config_settings/private/BUILD.bazel | 8 --- python/config_settings/private/py_args.bzl | 42 ------------ tests/config_settings/transition/BUILD.bazel | 3 - .../transition/py_args_tests.bzl | 68 ------------------- 4 files changed, 121 deletions(-) delete mode 100644 python/config_settings/private/py_args.bzl delete mode 100644 tests/config_settings/transition/py_args_tests.bzl diff --git a/python/config_settings/private/BUILD.bazel b/python/config_settings/private/BUILD.bazel index 88cd689862..cb42e4999a 100644 --- a/python/config_settings/private/BUILD.bazel +++ b/python/config_settings/private/BUILD.bazel @@ -1,13 +1,5 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - filegroup( name = "distribution", srcs = glob(["**"]), visibility = ["//python/config_settings:__pkg__"], ) - -bzl_library( - name = "py_args", - srcs = ["py_args.bzl"], - visibility = ["//:__subpackages__"], -) diff --git a/python/config_settings/private/py_args.bzl b/python/config_settings/private/py_args.bzl deleted file mode 100644 index 09a26461b7..0000000000 --- a/python/config_settings/private/py_args.bzl +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright 2023 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""A helper to extract default args for the transition rule.""" - -def py_args(name, kwargs): - """A helper to extract common py_binary and py_test args - - See https://bazel.build/reference/be/python#py_binary and - https://bazel.build/reference/be/python#py_test for the list - that should be returned - - Args: - name: The name of the target. - kwargs: The kwargs to be extracted from; MODIFIED IN-PLACE. - - Returns: - A dict with the extracted arguments - """ - return dict( - args = kwargs.pop("args", None), - data = kwargs.pop("data", None), - env = kwargs.pop("env", None), - srcs = kwargs.pop("srcs", None), - deps = kwargs.pop("deps", None), - # See https://bazel.build/reference/be/python#py_binary.main - # for default logic. - # NOTE: This doesn't match the exact way a regular py_binary searches for - # it's main amongst the srcs, but is close enough for most cases. - main = kwargs.pop("main", name + ".py"), - ) diff --git a/tests/config_settings/transition/BUILD.bazel b/tests/config_settings/transition/BUILD.bazel index 19d4958669..093de50959 100644 --- a/tests/config_settings/transition/BUILD.bazel +++ b/tests/config_settings/transition/BUILD.bazel @@ -1,6 +1,3 @@ load(":multi_version_tests.bzl", "multi_version_test_suite") -load(":py_args_tests.bzl", "py_args_test_suite") - -py_args_test_suite(name = "py_args_tests") multi_version_test_suite(name = "multi_version_tests") diff --git a/tests/config_settings/transition/py_args_tests.bzl b/tests/config_settings/transition/py_args_tests.bzl deleted file mode 100644 index 4538c88a5c..0000000000 --- a/tests/config_settings/transition/py_args_tests.bzl +++ /dev/null @@ -1,68 +0,0 @@ -# Copyright 2023 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"" - -load("@rules_testing//lib:test_suite.bzl", "test_suite") -load("//python/config_settings/private:py_args.bzl", "py_args") # buildifier: disable=bzl-visibility - -_tests = [] - -def _test_py_args_default(env): - actual = py_args("foo", {}) - - want = { - "args": None, - "data": None, - "deps": None, - "env": None, - "main": "foo.py", - "srcs": None, - } - env.expect.that_dict(actual).contains_exactly(want) - -_tests.append(_test_py_args_default) - -def _test_kwargs_get_consumed(env): - kwargs = { - "args": ["some", "args"], - "data": ["data"], - "deps": ["deps"], - "env": {"key": "value"}, - "main": "__main__.py", - "srcs": ["__main__.py"], - "visibility": ["//visibility:public"], - } - actual = py_args("bar_bin", kwargs) - - want = { - "args": ["some", "args"], - "data": ["data"], - "deps": ["deps"], - "env": {"key": "value"}, - "main": "__main__.py", - "srcs": ["__main__.py"], - } - env.expect.that_dict(actual).contains_exactly(want) - env.expect.that_dict(kwargs).keys().contains_exactly(["visibility"]) - -_tests.append(_test_kwargs_get_consumed) - -def py_args_test_suite(name): - """Create the test suite. - - Args: - name: the name of the test suite - """ - test_suite(name = name, basic_tests = _tests) From a3ad2c649d05131a5de481c813e2f60f996d70a1 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 28 Jun 2026 06:24:32 +0000 Subject: [PATCH 29/36] Add comment explaining why Gazelle targets are manual Add explanatory comment to tools/private/gazelle/BUILD.bazel to document why the Gazelle targets are marked manual. --- tools/private/gazelle/BUILD.bazel | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/private/gazelle/BUILD.bazel b/tools/private/gazelle/BUILD.bazel index a9acac17df..1bda0e7c04 100644 --- a/tools/private/gazelle/BUILD.bazel +++ b/tools/private/gazelle/BUILD.bazel @@ -4,6 +4,7 @@ package( default_visibility = ["//:__subpackages__"], ) +# Marked manual because we don't need CI to build them. gazelle_binary( name = "gazelle_bin", languages = [ From 64d9262f6a8ce07eabe20808d0df14950e15874b Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 28 Jun 2026 06:26:35 +0000 Subject: [PATCH 30/36] Clarify manual tags on Gazelle targets Update comments in tools/private/gazelle/BUILD.bazel to clarify that the targets are marked manual to avoid building in CI, which fails due to copt settings. Add the comment to both targets. --- tools/private/gazelle/BUILD.bazel | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/private/gazelle/BUILD.bazel b/tools/private/gazelle/BUILD.bazel index 1bda0e7c04..d147ae496b 100644 --- a/tools/private/gazelle/BUILD.bazel +++ b/tools/private/gazelle/BUILD.bazel @@ -4,7 +4,7 @@ package( default_visibility = ["//:__subpackages__"], ) -# Marked manual because we don't need CI to build them. +# Marked manual to avoid building in CI, which fails due to copt settings. gazelle_binary( name = "gazelle_bin", languages = [ @@ -13,6 +13,7 @@ gazelle_binary( tags = ["manual"], ) +# Marked manual to avoid building in CI, which fails due to copt settings. gazelle( name = "gazelle", gazelle = ":gazelle_bin", From a77089d9da1abab5f1995c698b303be69e90f930 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 28 Jun 2026 06:28:31 +0000 Subject: [PATCH 31/36] Move manual tag comments inside Gazelle targets Move the explanatory comments for the manual tags to be directly above the tags attribute inside the gazelle_binary and gazelle targets in tools/private/gazelle/BUILD.bazel. --- tools/private/gazelle/BUILD.bazel | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/private/gazelle/BUILD.bazel b/tools/private/gazelle/BUILD.bazel index d147ae496b..2a38e8f3a1 100644 --- a/tools/private/gazelle/BUILD.bazel +++ b/tools/private/gazelle/BUILD.bazel @@ -4,18 +4,18 @@ package( default_visibility = ["//:__subpackages__"], ) -# Marked manual to avoid building in CI, which fails due to copt settings. gazelle_binary( name = "gazelle_bin", languages = [ "@bazel_skylib_gazelle_plugin//bzl", ], + # Marked manual to avoid building in CI, which fails due to copt settings. tags = ["manual"], ) -# Marked manual to avoid building in CI, which fails due to copt settings. gazelle( name = "gazelle", gazelle = ":gazelle_bin", + # Marked manual to avoid building in CI, which fails due to copt settings. tags = ["manual"], ) From 4c74dc0cfa6784c04293a56576929c824f810501 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 28 Jun 2026 07:23:13 +0000 Subject: [PATCH 32/36] add workspace+bazel9 workaround --- WORKSPACE | 11 ++++------- workspace_bazel9.bzl | 10 ++++++++++ 2 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 workspace_bazel9.bzl diff --git a/WORKSPACE b/WORKSPACE index 077ddb5e68..8b5479f6a4 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -17,13 +17,10 @@ workspace(name = "rules_python") # Everything below this line is used only for developing rules_python. Users # should not copy it to their WORKSPACE. -# Necessary so that Bazel 9 recognizes this as rules_python and doesn't try -# to load the version Bazel itself uses by default. -# buildifier: disable=duplicated-name -local_repository( - name = "rules_python", - path = ".", -) +# Workaround for Bazel 9 duplicate name issue in Gazelle. +load("//:workspace_workaround.bzl", "bazel_9_workaround") + +bazel_9_workaround() load("//:internal_dev_deps.bzl", "rules_python_internal_deps") diff --git a/workspace_bazel9.bzl b/workspace_bazel9.bzl new file mode 100644 index 0000000000..dad59378a9 --- /dev/null +++ b/workspace_bazel9.bzl @@ -0,0 +1,10 @@ +"""Workaround for Bazel 9 duplicate name issue in Gazelle.""" + +def bazel_9_workaround(name = "bazel_9_workaround"): + # Necessary so that Bazel 9 recognizes this as rules_python and doesn't try + # to load the version Bazel itself uses by default. + # We hide this from Gazelle's WORKSPACE parser by putting it in a macro. + native.local_repository( + name = "rules_python", + path = ".", + ) From 70f26b179e10d7bde1cedfad1c39eb3a0f20bc9a Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 28 Jun 2026 07:35:59 +0000 Subject: [PATCH 33/36] manually run gazelle --- BUILD.bazel | 1 + python/BUILD.bazel | 20 ++-- python/private/BUILD.bazel | 190 ++++++++++++++++---------------- python/private/pypi/BUILD.bazel | 131 +++++++++++----------- python/uv/private/BUILD.bazel | 12 +- 5 files changed, 177 insertions(+), 177 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 5d85f23182..a52251393d 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -43,6 +43,7 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") # gazelle:exclude internal_dev_setup.bzl # gazelle:exclude internal_dev_deps.bzl # gazelle:exclude python/private/internal_dev_deps.bzl +# gazelle:exclude workspace_bazel9.bzl # Exclude legacy paths that are only kept for backwards compatibility # gazelle:exclude python/private/common diff --git a/python/BUILD.bazel b/python/BUILD.bazel index 1da9ab4a8c..a4dd98c572 100644 --- a/python/BUILD.bazel +++ b/python/BUILD.bazel @@ -209,11 +209,6 @@ alias( deprecation = "Use //python:defs instead", ) -bzl_library( - name = "features", - srcs = ["features.bzl"], -) - alias( name = "features_bzl", actual = ":features", @@ -416,11 +411,6 @@ alias( deprecation = "Use //python:py_test instead", ) -bzl_library( - name = "python", - srcs = ["python.bzl"], -) - alias( name = "python_bzl", actual = ":python", @@ -460,3 +450,13 @@ alias( actual = ":versions", deprecation = "Use //python:versions instead", ) + +bzl_library( + name = "features", + srcs = ["features.bzl"], +) + +bzl_library( + name = "python", + srcs = ["python.bzl"], +) diff --git a/python/private/BUILD.bazel b/python/private/BUILD.bazel index 7064f52cd3..c3d60ffaf1 100644 --- a/python/private/BUILD.bazel +++ b/python/private/BUILD.bazel @@ -280,11 +280,6 @@ bzl_library( ], ) -bzl_library( - name = "bzlmod_enabled", - srcs = ["bzlmod_enabled.bzl"], -) - bzl_library( name = "cc_helper", srcs = ["cc_helper.bzl"], @@ -309,11 +304,6 @@ bzl_library( ], ) -bzl_library( - name = "common_labels", - srcs = ["common_labels.bzl"], -) - bzl_library( name = "config_settings", srcs = ["config_settings.bzl"], @@ -356,16 +346,6 @@ bzl_library( deps = ["@rules_python_internal//:rules_python_config"], ) -bzl_library( - name = "enum", - srcs = ["enum.bzl"], -) - -bzl_library( - name = "envsubst", - srcs = ["envsubst.bzl"], -) - bzl_library( name = "flags", srcs = ["flags.bzl"], @@ -375,11 +355,6 @@ bzl_library( ], ) -bzl_library( - name = "full_version", - srcs = ["full_version.bzl"], -) - bzl_library( name = "hermetic_runtime_repo_setup", srcs = ["hermetic_runtime_repo_setup.bzl"], @@ -451,21 +426,6 @@ bzl_library( ], ) -bzl_library( - name = "normalize_name", - srcs = ["normalize_name.bzl"], -) - -bzl_library( - name = "pbs_manifest", - srcs = ["pbs_manifest.bzl"], -) - -bzl_library( - name = "platform_info", - srcs = ["platform_info.bzl"], -) - bzl_library( name = "precompile", srcs = ["precompile.bzl"], @@ -502,11 +462,6 @@ bzl_library( deps = ["@rules_cc//cc/common"], ) -bzl_library( - name = "py_cc_toolchain_info", - srcs = ["py_cc_toolchain_info.bzl"], -) - bzl_library( name = "py_cc_toolchain_macro", srcs = ["py_cc_toolchain_macro.bzl"], @@ -537,16 +492,6 @@ bzl_library( ], ) -bzl_library( - name = "py_console_script_gen", - srcs = ["py_console_script_gen.bzl"], -) - -bzl_library( - name = "py_exec_tools_info", - srcs = ["py_exec_tools_info.bzl"], -) - bzl_library( name = "py_exec_tools_toolchain", srcs = ["py_exec_tools_toolchain.bzl"], @@ -591,11 +536,6 @@ bzl_library( ], ) -bzl_library( - name = "py_executable_info", - srcs = ["py_executable_info.bzl"], -) - bzl_library( name = "py_info", srcs = ["py_info.bzl"], @@ -678,11 +618,6 @@ bzl_library( ], ) -bzl_library( - name = "py_runtime_info", - srcs = ["py_runtime_info.bzl"], -) - bzl_library( name = "py_runtime_macro", srcs = ["py_runtime_macro.bzl"], @@ -841,11 +776,6 @@ bzl_library( deps = ["//python:py_binary"], ) -bzl_library( - name = "repo_utils", - srcs = ["repo_utils.bzl"], -) - bzl_library( name = "rule_builders", srcs = ["rule_builders.bzl"], @@ -897,26 +827,6 @@ bzl_library( ], ) -bzl_library( - name = "runtimes_manifest_workspace", - srcs = ["runtimes_manifest_workspace.bzl"], -) - -bzl_library( - name = "sentinel_impl", - srcs = ["sentinel_impl.bzl"], -) - -bzl_library( - name = "stamp_impl", - srcs = ["stamp_impl.bzl"], -) - -bzl_library( - name = "text_util", - srcs = ["text_util.bzl"], -) - bzl_library( name = "toolchain_aliases", srcs = ["toolchain_aliases.bzl"], @@ -926,11 +836,6 @@ bzl_library( ], ) -bzl_library( - name = "toolchain_types", - srcs = ["toolchain_types.bzl"], -) - bzl_library( name = "toolchains_repo", srcs = ["toolchains_repo.bzl"], @@ -971,6 +876,101 @@ bzl_library( ], ) +bzl_library( + name = "bzlmod_enabled", + srcs = ["bzlmod_enabled.bzl"], +) + +bzl_library( + name = "common_labels", + srcs = ["common_labels.bzl"], +) + +bzl_library( + name = "enum", + srcs = ["enum.bzl"], +) + +bzl_library( + name = "envsubst", + srcs = ["envsubst.bzl"], +) + +bzl_library( + name = "full_version", + srcs = ["full_version.bzl"], +) + +bzl_library( + name = "normalize_name", + srcs = ["normalize_name.bzl"], +) + +bzl_library( + name = "pbs_manifest", + srcs = ["pbs_manifest.bzl"], +) + +bzl_library( + name = "platform_info", + srcs = ["platform_info.bzl"], +) + +bzl_library( + name = "py_cc_toolchain_info", + srcs = ["py_cc_toolchain_info.bzl"], +) + +bzl_library( + name = "py_console_script_gen", + srcs = ["py_console_script_gen.bzl"], +) + +bzl_library( + name = "py_exec_tools_info", + srcs = ["py_exec_tools_info.bzl"], +) + +bzl_library( + name = "py_executable_info", + srcs = ["py_executable_info.bzl"], +) + +bzl_library( + name = "py_runtime_info", + srcs = ["py_runtime_info.bzl"], +) + +bzl_library( + name = "repo_utils", + srcs = ["repo_utils.bzl"], +) + +bzl_library( + name = "runtimes_manifest_workspace", + srcs = ["runtimes_manifest_workspace.bzl"], +) + +bzl_library( + name = "sentinel_impl", + srcs = ["sentinel_impl.bzl"], +) + +bzl_library( + name = "stamp_impl", + srcs = ["stamp_impl.bzl"], +) + +bzl_library( + name = "text_util", + srcs = ["text_util.bzl"], +) + +bzl_library( + name = "toolchain_types", + srcs = ["toolchain_types.bzl"], +) + bzl_library( name = "version", srcs = ["version.bzl"], diff --git a/python/private/pypi/BUILD.bazel b/python/private/pypi/BUILD.bazel index c7b1d793c2..677154ee46 100644 --- a/python/private/pypi/BUILD.bazel +++ b/python/private/pypi/BUILD.bazel @@ -74,17 +74,6 @@ filegroup( visibility = ["//tools/private/update_deps:__pkg__"], ) -bzl_library( - name = "argparse", - srcs = ["argparse.bzl"], -) - -bzl_library( - name = "attrs", - srcs = ["attrs.bzl"], -) -# Keep sorted by library name and keep the files named by the main symbol they export - bzl_library( name = "config_settings", srcs = ["config_settings.bzl"], @@ -97,11 +86,6 @@ bzl_library( deps = ["//python/private:bazel_tools"], ) -bzl_library( - name = "env_marker_info", - srcs = ["env_marker_info.bzl"], -) - bzl_library( name = "env_marker_setting", srcs = ["env_marker_setting.bzl"], @@ -208,16 +192,6 @@ bzl_library( ], ) -bzl_library( - name = "index_sources", - srcs = ["index_sources.bzl"], -) - -bzl_library( - name = "labels", - srcs = ["labels.bzl"], -) - bzl_library( name = "missing_package", srcs = ["missing_package.bzl"], @@ -242,11 +216,6 @@ bzl_library( deps = ["@bazel_skylib//rules:copy_file"], ) -bzl_library( - name = "package_annotation", - srcs = ["package_annotation.bzl"], -) - bzl_library( name = "parse_requirements", srcs = ["parse_requirements.bzl"], @@ -263,11 +232,6 @@ bzl_library( ], ) -bzl_library( - name = "parse_requirements_txt", - srcs = ["parse_requirements_txt.bzl"], -) - bzl_library( name = "parse_simpleapi_html", srcs = ["parse_simpleapi_html.bzl"], @@ -277,11 +241,6 @@ bzl_library( ], ) -bzl_library( - name = "parse_whl_name", - srcs = ["parse_whl_name.bzl"], -) - bzl_library( name = "patch_whl", srcs = ["patch_whl.bzl"], @@ -376,11 +335,6 @@ bzl_library( ], ) -bzl_library( - name = "platform", - srcs = ["platform.bzl"], -) - bzl_library( name = "pypi_cache", srcs = ["pypi_cache.bzl"], @@ -459,11 +413,6 @@ bzl_library( ], ) -bzl_library( - name = "urllib", - srcs = ["urllib.bzl"], -) - bzl_library( name = "venv_entry_point", srcs = ["venv_entry_point.bzl"], @@ -485,11 +434,6 @@ bzl_library( ], ) -bzl_library( - name = "version_from_filename", - srcs = ["version_from_filename.bzl"], -) - bzl_library( name = "whl_config_repo", srcs = ["whl_config_repo.bzl"], @@ -499,11 +443,6 @@ bzl_library( ], ) -bzl_library( - name = "whl_config_setting", - srcs = ["whl_config_setting.bzl"], -) - bzl_library( name = "whl_extract", srcs = ["whl_extract.bzl"], @@ -561,11 +500,6 @@ bzl_library( ], ) -bzl_library( - name = "whl_metadata", - srcs = ["whl_metadata.bzl"], -) - bzl_library( name = "whl_repo_name", srcs = ["whl_repo_name.bzl"], @@ -575,6 +509,71 @@ bzl_library( ], ) +bzl_library( + name = "argparse", + srcs = ["argparse.bzl"], +) + +bzl_library( + name = "attrs", + srcs = ["attrs.bzl"], +) + +bzl_library( + name = "env_marker_info", + srcs = ["env_marker_info.bzl"], +) + +bzl_library( + name = "index_sources", + srcs = ["index_sources.bzl"], +) + +bzl_library( + name = "labels", + srcs = ["labels.bzl"], +) + +bzl_library( + name = "package_annotation", + srcs = ["package_annotation.bzl"], +) + +bzl_library( + name = "parse_requirements_txt", + srcs = ["parse_requirements_txt.bzl"], +) + +bzl_library( + name = "parse_whl_name", + srcs = ["parse_whl_name.bzl"], +) + +bzl_library( + name = "platform", + srcs = ["platform.bzl"], +) + +bzl_library( + name = "urllib", + srcs = ["urllib.bzl"], +) + +bzl_library( + name = "version_from_filename", + srcs = ["version_from_filename.bzl"], +) + +bzl_library( + name = "whl_config_setting", + srcs = ["whl_config_setting.bzl"], +) + +bzl_library( + name = "whl_metadata", + srcs = ["whl_metadata.bzl"], +) + bzl_library( name = "whl_target_platforms", srcs = ["whl_target_platforms.bzl"], diff --git a/python/uv/private/BUILD.bazel b/python/uv/private/BUILD.bazel index d311037011..ce0ce0ec81 100644 --- a/python/uv/private/BUILD.bazel +++ b/python/uv/private/BUILD.bazel @@ -117,12 +117,6 @@ bzl_library( deps = ["//python/private:text_util"], ) -bzl_library( - name = "toolchain_types", - srcs = ["toolchain_types.bzl"], - visibility = ["//python/uv:__subpackages__"], -) - # keep bzl_library( name = "uv_lock_to_requirements", @@ -133,6 +127,12 @@ bzl_library( ], ) +bzl_library( + name = "toolchain_types", + srcs = ["toolchain_types.bzl"], + visibility = ["//python/uv:__subpackages__"], +) + bzl_library( name = "uv_toolchain_info", srcs = ["uv_toolchain_info.bzl"], From 408b35db6a5dba0e63e397a42d48b458fd5bcc60 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 28 Jun 2026 07:36:44 +0000 Subject: [PATCH 34/36] Add Gazelle to pre-commit config Add a local pre-commit hook to run Gazelle automatically on Starlark and build file changes, ensuring target definitions remain synchronized. --- .pre-commit-config.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e4d65c8bb6..f4107880b2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -65,3 +65,9 @@ repos: entry: ./tools/private/sync_downloader_configs.py files: downloader_config\.cfg$ pass_filenames: false + - id: gazelle + name: Run Gazelle + language: system + entry: bazel run //tools/private/gazelle + files: (\.bzl|\.bazel|BUILD|WORKSPACE(\.bzlmod)?)$ + pass_filenames: false From 4009934b094a92f75414e1f937abc60b111761a0 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 28 Jun 2026 07:41:04 +0000 Subject: [PATCH 35/36] fix workspace load --- WORKSPACE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WORKSPACE b/WORKSPACE index 8b5479f6a4..5a31274b21 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -18,7 +18,7 @@ workspace(name = "rules_python") # should not copy it to their WORKSPACE. # Workaround for Bazel 9 duplicate name issue in Gazelle. -load("//:workspace_workaround.bzl", "bazel_9_workaround") +load("//:workspace_bazel9.bzl", "bazel_9_workaround") bazel_9_workaround() From bfc2f49b94079f11066cdac2ad1c6085c9d692d2 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Sun, 28 Jun 2026 07:47:58 +0000 Subject: [PATCH 36/36] remove agent plan --- .agents/plans/ci-handling.md | 66 ------------ .agents/plans/gazelle-bzl-library.md | 146 --------------------------- 2 files changed, 212 deletions(-) delete mode 100644 .agents/plans/ci-handling.md delete mode 100644 .agents/plans/gazelle-bzl-library.md diff --git a/.agents/plans/ci-handling.md b/.agents/plans/ci-handling.md deleted file mode 100644 index 97bf483776..0000000000 --- a/.agents/plans/ci-handling.md +++ /dev/null @@ -1,66 +0,0 @@ -# Plan: Autonomous CI Failure Handling for PR #3852 - -This plan outlines the strategy and workflow for autonomously monitoring, -diagnosing, and resolving CI failures for PR #3852, ensuring a rapid and -reliable path to merging while handling known network flakiness. - -## 1. Objective - -Autonomously oversee the CI lifecycle for PR #3852, immediately detecting -failures, diagnosing their root causes, and applying resolutions (either -retrying flakes or fixing code/configuration errors) to minimize manual -intervention. - -## 2. Automated Monitoring - -* **Continuous Polling:** We launch a long-running background monitoring - service (`monitor_remote_ci.py`) dedicated to PR #3852. -* **Scope:** This service continuously monitors both GitHub PR checks and - Buildkite workflow executions. -* **Trigger:** The service runs continuously in the background and alerts the - main agent conversation immediately upon any job failure. - -## 3. Autonomous Diagnosis - -When any CI job completes with a non-zero exit code or errors: -1. **Log Retrieval:** The monitoring service automatically downloads the raw - CI log file to `ci_logs/`. -2. **Failure Analysis:** The service triggers the `analyze_ci_failure.py` - diagnostic tool. -3. **Synthesis:** The analyzer scans the logs for failure signatures - (tracebacks, compiler aborts, network timeouts) and synthesizes an - actionable, structured Markdown fix plan. -4. **Notification:** The analyzer dispatches a high-priority notification - containing the log path and the fix plan back to the active agent - conversation. - -## 4. Resolution Strategy - -We categorize failures into two types and address them as follows: - -### Category A: Infrastructure & Network Flakes -* **Identified by:** 504 Gateway errors, fetch timeouts, or unresolved external - repository downloads. -* **Resolution:** - * **Retries:** If Buildkite permissions allow, we autonomously retry the - failed job. If not, we notify the user to trigger a manual retry. - * **Timeout Scaling:** If timeouts persist, we modify `.bazelrc` to - increase `--http_timeout_scaling` or repository downloader retries. - * **Mirroring:** If a dependency download fails, we check if it is - available on `mirror.bazel.build`. If so, we add it to - `downloader_config.cfg` and push the update. - -### Category B: Code & Test Failures -* **Identified by:** Compilation errors, unit test assertion failures, or - lint/style violations. -* **Resolution:** - * **Apply Fix:** We analyze the generated fix plan, apply the necessary - code corrections locally, and run the validation suite (`bazel test - //...`). - * **Push:** Once verified green locally, we commit and push the fix - directly to the PR branch to trigger a new CI run. - -## 5. Execution - -The monitoring service is launched immediately upon updating the PR and runs -until the PR is merged or closed. diff --git a/.agents/plans/gazelle-bzl-library.md b/.agents/plans/gazelle-bzl-library.md deleted file mode 100644 index 7b81ed2682..0000000000 --- a/.agents/plans/gazelle-bzl-library.md +++ /dev/null @@ -1,146 +0,0 @@ -# Plan: Gazelle Migration for bzl_library Targets - -This plan outlines the strategy, implementation details, edge cases, and -special directions for migrating `rules_python` to use `bazel-skylib`'s Gazelle -integration to automate the generation and maintenance of `bzl_library` -targets. - -## 1. Objective - -Automate the maintenance of `bzl_library` targets across the repository to -simplify dependency tracking, while minimizing risk and keeping tests and -examples completely pristine. - -## 2. Implementation Strategy - -* **Plugin Integration:** Integrate `bazel_skylib_gazelle_plugin` as a - `dev_dependency` in `MODULE.bazel`. -* **Gazelle Location:** Place all Gazelle rules and targets (such as the - `gazelle_binary` and the `gazelle` rule itself) entirely within - `tools/private/gazelle` to prevent any loading-time or analysis-time - production dependencies on Gazelle. -* **Root Configuration:** Root-level configuration is limited to Gazelle - directives (comments) in the root `BUILD.bazel` to guide the plugin's - behavior. -* **Directory Exclusions:** - * Exclude `tests/` and `examples/` directories from Gazelle scanning to - ensure they remain completely untouched and match `upstream/main`. - * Exclude top-level dev-setup files (`internal_dev_setup.bzl`, - `python/private/internal_dev_deps.bzl`) from Gazelle to avoid - generating targets that would require creating helper targets inside the - pristine `tests/` directory. - * **Bzlmod & Repository-Phase Exclusions:** Exclude Starlark files that - are only evaluated during the Bzlmod or repository-loading phases (e.g., - module extensions, repository rules, or startup setup macros). These - files do not run at analysis/build time and therefore do not need - `bzl_library` targets. - * Examples: `gazelle/deps.bzl` (repository-phase Go helper) and - `extensions.bzl` (Bzlmod module extension files, such as those in - `gazelle/python/` and `gazelle/python/private/`) are excluded. - * **Special Case Exclusions:** - * `internal_dev_deps.bzl`: Exclude all instances of this file across - the repository (including in the root, `python/private/`, and - `gazelle/` directories) from Gazelle processing, as they are - dev-setup files that should not pollute the Starlark library graph. - * `python/private/common/`: Exclude this entire directory from Gazelle - processing. It contains legacy file paths and symlinks for older - Bazel versions, which do not need to be part of the modern Starlark - library graph. -* **Package Markers:** Keep `tests/support/whl_from_dir/BUILD.bazel` as a - nearly empty package marker (matching upstream) to satisfy Bazel's loading - phase, without defining any targets. - -## 3. Target Naming & Compatibility Rules - -* **Naming Convention:** Rename `bzl_library` targets to match the Starlark - file name (e.g., `foo.bzl` -> `:foo` instead of `:foo_bzl`). -* **Public Targets:** For public targets, always create deprecated - backwards-compatibility aliases (e.g., `:foo_bzl` pointing to `:foo`) to - prevent breaking downstream users. -* **Private Targets:** If a `bzl_library` is visibility-restricted (private), - it is **OK to change its name** without creating a compatibility alias. -* **Visibility of New Targets:** Restrict the visibility of - `bzl_library` targets created for files that did not previously - have a `bzl_library` target to `//:__subpackages__`. Do not make - newly introduced targets public. -* **Bzlmod-Only Public Targets (`python/extensions/`):** Targets in - `python/extensions/BUILD.bazel` are Bzlmod-only but are public. We let - Gazelle process them (generating `:config`, `:pip`, `:python`), but we must - manually create deprecated backwards-compatibility aliases (`:config_bzl`, - `:pip_bzl`, `:python_bzl`) to support any legacy references. -* **Documentation Targets:** When renaming or migrating targets, ensure that - all documentation targets (such as `bzl_api_docs` in `docs/BUILD.bazel`) - are updated to reference the new target names (e.g., ensuring - `//python:py_info` is included). - -## 4. Edge Cases & Resolving Overrides - -* **Bzlmod MVS Upgrades:** While manually upgrading dependencies is strictly - forbidden, automatic transitive upgrades by Bzlmod's Minimal Version - Selection (MVS) (e.g., upgrading `platforms` or `rules_cc` due to other - dependencies) can rename or consolidate targets. -* **Resolve Overrides:** Use `# gazelle:resolve` overrides in the root - `BUILD.bazel` to map Starlark imports to the correct consolidated external - targets (e.g., `@rules_cc//cc:core_rules` instead of separate `cc_library` - and `cc_import` targets). -* **Omitted External Targets:** If external rulesets omit `bzl_library` - targets for their setup files, remove them from our dev target `deps` and - shield our targets with `# keep` to prevent Gazelle from regenerating them. - -## 5. Special Directions - -* **Copyrights:** Unless directed by the user otherwise, do not add Bazel - copyright to new or existing files. Remove any accidentally added - copyrights. -* **Patches & Overrides:** Patching dependencies is strictly prohibited. - Consequently, using `single_version_override` (or any other module - overrides) to apply patches in `MODULE.bazel` is not permitted. -* **Sphinxdocs & Gazelle Release Dependency:** `sphinxdocs` and the code - under `gazelle/` are released separately from `rules_python`. They - cannot refer to unreleased changes in `rules_python`. Thus, they must - refer to the old target names in `rules_python` (using the `_bzl` - suffix, e.g., `@rules_python//python:py_binary_bzl` and - `@rules_python//python:defs_bzl`). - -## 6. Public bzl_library Targets - -The following are all the public `bzl_library` targets in the repository (across -both the main module and the Gazelle module) that must be maintained with -backwards-compatibility aliases if they are renamed: - -### Main Module (`@rules_python`) -* `//python:current_py_toolchain_bzl` -* `//python:defs` -* `//python:features` -* `//python:packaging` -* `//python:pip` -* `//python:proto` -* `//python:py_binary` -* `//python:py_cc_link_params_info` -* `//python:py_exec_tools_info` -* `//python:py_exec_tools_toolchain` -* `//python:py_executable_info` -* `//python:py_import` -* `//python:py_info` -* `//python:py_library` -* `//python:py_runtime` -* `//python:py_runtime_info` -* `//python:py_runtime_pair` -* `//python:py_test` -* `//python:python` -* `//python:repositories` -* `//python:versions` -* `//python/cc:py_cc_toolchain` -* `//python/cc:py_cc_toolchain_info` -* `//python/entry_points:py_console_script_binary` -* `//python/extensions:config` -* `//python/extensions:pip` -* `//python/extensions:python` -* `//python/zipapp:py_zipapp_binary` -* `//python/zipapp:py_zipapp_test` - -### Gazelle Module (`@rules_python_gazelle_plugin`) -* `@rules_python_gazelle_plugin//:def` -* `@rules_python_gazelle_plugin//manifest:defs` -* `@rules_python_gazelle_plugin//modules_mapping:def` -* `@rules_python_gazelle_plugin//python:gazelle_test`