From 084b877c98b580839ceab2b071b02fc6768f3de6 Mon Sep 17 00:00:00 2001 From: Greg Roodt Date: Mon, 1 Jul 2024 20:23:36 +1000 Subject: [PATCH] (chore): Remove the extra indirection and `bzlmod` folder (#2022) The `bzlmod` folder seems like unnecessary indirection now. It was perhaps useful as we developed bzlmod support, but we no longer need it and it makes navigating the repository more difficult. --- MODULE.bazel | 6 +- python/extensions/BUILD.bazel | 4 +- python/extensions/pip.bzl | 2 +- python/extensions/python.bzl | 2 +- python/private/BUILD.bazel | 23 +++++++- python/private/bzlmod/BUILD.bazel | 55 ------------------- python/private/{bzlmod => }/internal_deps.bzl | 2 +- python/private/pypi/BUILD.bazel | 12 +++- .../pypi/{bzlmod.bzl => extension.bzl} | 0 python/private/{bzlmod => pypi}/pip.bzl | 2 +- python/private/{bzlmod => }/python.bzl | 4 +- python/private/{bzlmod => }/pythons_hub.bzl | 0 12 files changed, 43 insertions(+), 69 deletions(-) delete mode 100644 python/private/bzlmod/BUILD.bazel rename python/private/{bzlmod => }/internal_deps.bzl (91%) rename python/private/pypi/{bzlmod.bzl => extension.bzl} (100%) rename python/private/{bzlmod => pypi}/pip.bzl (90%) rename python/private/{bzlmod => }/python.bzl (99%) rename python/private/{bzlmod => }/pythons_hub.bzl (100%) diff --git a/MODULE.bazel b/MODULE.bazel index 735600b98d..b6d198ffc1 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -13,7 +13,7 @@ bazel_dep(name = "platforms", version = "0.0.4") bazel_dep(name = "rules_proto", version = "6.0.0-rc1") bazel_dep(name = "protobuf", version = "24.4", repo_name = "com_google_protobuf") -internal_deps = use_extension("//python/private/bzlmod:internal_deps.bzl", "internal_deps") +internal_deps = use_extension("//python/private:internal_deps.bzl", "internal_deps") use_repo( internal_deps, "pypi__build", @@ -54,7 +54,7 @@ register_toolchains("@pythons_hub//:all") ##################### # Install twine for our own runfiles wheel publishing and allow bzlmod users to use it. -pip = use_extension("//python/private/bzlmod:pip.bzl", "pip_internal") +pip = use_extension("//python/private/pypi:pip.bzl", "pip_internal") pip.parse( hub_name = "rules_python_publish_deps", python_version = "3.11", @@ -77,7 +77,7 @@ bazel_dep(name = "rules_go", version = "0.41.0", dev_dependency = True, repo_nam bazel_dep(name = "gazelle", version = "0.33.0", dev_dependency = True, repo_name = "bazel_gazelle") dev_pip = use_extension( - "//python/private/bzlmod:pip.bzl", + "//python/private/pypi:pip.bzl", "pip_internal", dev_dependency = True, ) diff --git a/python/extensions/BUILD.bazel b/python/extensions/BUILD.bazel index 1bc2a71192..e8a63d6d5b 100644 --- a/python/extensions/BUILD.bazel +++ b/python/extensions/BUILD.bazel @@ -28,7 +28,7 @@ bzl_library( name = "pip_bzl", srcs = ["pip.bzl"], visibility = ["//:__subpackages__"], - deps = ["//python/private/bzlmod:pip_bzl"], + deps = ["//python/private/pypi:pip_bzl"], ) bzl_library( @@ -36,6 +36,6 @@ bzl_library( srcs = ["python.bzl"], visibility = ["//:__subpackages__"], deps = [ - "//python/private/bzlmod:python_bzl", + "//python/private:python_bzl", ], ) diff --git a/python/extensions/pip.bzl b/python/extensions/pip.bzl index a69ee34ae7..e9d47263d5 100644 --- a/python/extensions/pip.bzl +++ b/python/extensions/pip.bzl @@ -14,6 +14,6 @@ "pip module extension for use with bzlmod" -load("//python/private/bzlmod:pip.bzl", _pip = "pip") +load("//python/private/pypi:pip.bzl", _pip = "pip") pip = _pip diff --git a/python/extensions/python.bzl b/python/extensions/python.bzl index 5428b7542e..4148d90877 100644 --- a/python/extensions/python.bzl +++ b/python/extensions/python.bzl @@ -14,6 +14,6 @@ "Python toolchain module extensions for use with bzlmod" -load("//python/private/bzlmod:python.bzl", _python = "python") +load("//python/private:python.bzl", _python = "python") python = _python diff --git a/python/private/BUILD.bazel b/python/private/BUILD.bazel index 9c759cba9a..c5da4e31e3 100644 --- a/python/private/BUILD.bazel +++ b/python/private/BUILD.bazel @@ -29,7 +29,6 @@ licenses(["notice"]) filegroup( name = "distribution", srcs = glob(["**"]) + [ - "//python/private/bzlmod:distribution", "//python/private/common:distribution", "//python/private/proto:distribution", "//python/private/pypi:distribution", @@ -128,6 +127,28 @@ bzl_library( srcs = ["normalize_name.bzl"], ) +bzl_library( + name = "python_bzl", + srcs = ["python.bzl"], + deps = [ + ":pythons_hub_bzl", + ":toolchains_repo_bzl", + ":util_bzl", + "//python:repositories_bzl", + "@bazel_features//:features", + ], +) + +bzl_library( + name = "pythons_hub_bzl", + srcs = ["pythons_hub.bzl"], + deps = [ + ":full_version_bzl", + ":py_toolchain_suite_bzl", + "//python:versions_bzl", + ], +) + bzl_library( name = "py_cc_toolchain_bzl", srcs = [ diff --git a/python/private/bzlmod/BUILD.bazel b/python/private/bzlmod/BUILD.bazel deleted file mode 100644 index 2cb35fc03e..0000000000 --- a/python/private/bzlmod/BUILD.bazel +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright 2022 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") - -package(default_visibility = ["//:__subpackages__"]) - -licenses(["notice"]) - -filegroup( - name = "distribution", - srcs = glob(["**"]), - visibility = ["//python/private:__pkg__"], -) - -bzl_library( - name = "pip_bzl", - srcs = ["pip.bzl"], - deps = [ - "//python/private/pypi:bzlmod_bzl", - ], -) - -bzl_library( - name = "python_bzl", - srcs = ["python.bzl"], - deps = [ - ":pythons_hub_bzl", - "//python:repositories_bzl", - "//python/private:toolchains_repo_bzl", - "//python/private:util_bzl", - "@bazel_features//:features", - ], -) - -bzl_library( - name = "pythons_hub_bzl", - srcs = ["pythons_hub.bzl"], - deps = [ - "//python:versions_bzl", - "//python/private:full_version_bzl", - "//python/private:py_toolchain_suite_bzl", - ], -) diff --git a/python/private/bzlmod/internal_deps.bzl b/python/private/internal_deps.bzl similarity index 91% rename from python/private/bzlmod/internal_deps.bzl rename to python/private/internal_deps.bzl index e0eca9ef3b..6ea3fa40c7 100644 --- a/python/private/bzlmod/internal_deps.bzl +++ b/python/private/internal_deps.bzl @@ -9,8 +9,8 @@ "Python toolchain module extension for internal rule use" load("@bazel_skylib//lib:modules.bzl", "modules") -load("//python/private:internal_config_repo.bzl", "internal_config_repo") load("//python/private/pypi:deps.bzl", "pypi_deps") +load(":internal_config_repo.bzl", "internal_config_repo") def _internal_deps(): internal_config_repo(name = "rules_python_internal") diff --git a/python/private/pypi/BUILD.bazel b/python/private/pypi/BUILD.bazel index 0960b6a21d..08fb7259ec 100644 --- a/python/private/pypi/BUILD.bazel +++ b/python/private/pypi/BUILD.bazel @@ -55,8 +55,8 @@ bzl_library( ) bzl_library( - name = "bzlmod_bzl", - srcs = ["bzlmod.bzl"], + name = "extension_bzl", + srcs = ["extension.bzl"], deps = [ ":attrs_bzl", ":hub_repository_bzl", @@ -190,6 +190,14 @@ bzl_library( ], ) +bzl_library( + name = "pip_bzl", + srcs = ["pip.bzl"], + deps = [ + ":extension_bzl", + ], +) + bzl_library( name = "pip_compile_bzl", srcs = ["pip_compile.bzl"], diff --git a/python/private/pypi/bzlmod.bzl b/python/private/pypi/extension.bzl similarity index 100% rename from python/private/pypi/bzlmod.bzl rename to python/private/pypi/extension.bzl diff --git a/python/private/bzlmod/pip.bzl b/python/private/pypi/pip.bzl similarity index 90% rename from python/private/bzlmod/pip.bzl rename to python/private/pypi/pip.bzl index ecf94b69d5..cb8e111e0e 100644 --- a/python/private/bzlmod/pip.bzl +++ b/python/private/pypi/pip.bzl @@ -14,7 +14,7 @@ "pip module extensions for use with bzlmod." -load("//python/private/pypi:bzlmod.bzl", "pypi", "pypi_internal") +load("//python/private/pypi:extension.bzl", "pypi", "pypi_internal") pip = pypi pip_internal = pypi_internal diff --git a/python/private/bzlmod/python.bzl b/python/private/python.bzl similarity index 99% rename from python/private/bzlmod/python.bzl rename to python/private/python.bzl index f8be271fd6..56566790d3 100644 --- a/python/private/bzlmod/python.bzl +++ b/python/private/python.bzl @@ -16,9 +16,9 @@ load("@bazel_features//:features.bzl", "bazel_features") load("//python:repositories.bzl", "python_register_toolchains") -load("//python/private:toolchains_repo.bzl", "multi_toolchain_aliases") -load("//python/private:util.bzl", "IS_BAZEL_6_4_OR_HIGHER") load(":pythons_hub.bzl", "hub_repo") +load(":toolchains_repo.bzl", "multi_toolchain_aliases") +load(":util.bzl", "IS_BAZEL_6_4_OR_HIGHER") # This limit can be increased essentially arbitrarily, but doing so will cause a rebuild of all # targets using any of these toolchains due to the changed repository name. diff --git a/python/private/bzlmod/pythons_hub.bzl b/python/private/pythons_hub.bzl similarity index 100% rename from python/private/bzlmod/pythons_hub.bzl rename to python/private/pythons_hub.bzl