fix(deps): declare our dependency on bazel_skylib (#1001)
diff --git a/.github/workflows/workspace_snippet.sh b/.github/workflows/workspace_snippet.sh
index 9a51d06..4837f73 100755
--- a/.github/workflows/workspace_snippet.sh
+++ b/.github/workflows/workspace_snippet.sh
@@ -46,11 +46,16 @@
\`\`\`starlark
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+
http_archive(
name = "rules_python",
sha256 = "${SHA}",
strip_prefix = "${PREFIX}",
url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/${TAG}.tar.gz",
)
+
+load("@rules_python//python:repositories.bzl", "py_repositories")
+
+py_repositories()
\`\`\`
EOF
diff --git a/MODULE.bazel b/MODULE.bazel
index 389ced6..af5d2e0 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -5,6 +5,7 @@
)
bazel_dep(name = "platforms", version = "0.0.4")
+bazel_dep(name = "bazel_skylib", version = "1.3.0")
# Those are loaded only when using py_proto_library
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
diff --git a/examples/multi_python_versions/WORKSPACE b/examples/multi_python_versions/WORKSPACE
index 9a6676e..698bce8 100644
--- a/examples/multi_python_versions/WORKSPACE
+++ b/examples/multi_python_versions/WORKSPACE
@@ -1,16 +1,5 @@
workspace(name = "rules_python_multi_python_versions")
-load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
-
-http_archive(
- name = "bazel_skylib",
- sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d",
- urls = [
- "https://github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
- "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
- ],
-)
-
local_repository(
name = "rules_python",
path = "../..",
@@ -20,7 +9,9 @@
pip_install_dependencies()
-load("@rules_python//python:repositories.bzl", "python_register_multi_toolchains")
+load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_multi_toolchains")
+
+py_repositories()
default_python_version = "3.9"
diff --git a/examples/pip_install/WORKSPACE b/examples/pip_install/WORKSPACE
index f63d928..b1744bf 100644
--- a/examples/pip_install/WORKSPACE
+++ b/examples/pip_install/WORKSPACE
@@ -1,22 +1,13 @@
workspace(name = "rules_python_pip_install_example")
-load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
-
-http_archive(
- name = "bazel_skylib",
- sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d",
- urls = [
- "https://github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
- "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
- ],
-)
-
local_repository(
name = "rules_python",
path = "../..",
)
-load("@rules_python//python:repositories.bzl", "python_register_toolchains")
+load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")
+
+py_repositories()
python_register_toolchains(
name = "python39",
diff --git a/examples/pip_parse/WORKSPACE b/examples/pip_parse/WORKSPACE
index cd557a3..79aca14 100644
--- a/examples/pip_parse/WORKSPACE
+++ b/examples/pip_parse/WORKSPACE
@@ -1,22 +1,13 @@
workspace(name = "rules_python_pip_parse_example")
-load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
-
-http_archive(
- name = "bazel_skylib",
- sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d",
- urls = [
- "https://github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
- "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
- ],
-)
-
local_repository(
name = "rules_python",
path = "../..",
)
-load("@rules_python//python:repositories.bzl", "python_register_toolchains")
+load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")
+
+py_repositories()
python_register_toolchains(
name = "python39",
diff --git a/examples/pip_parse_vendored/WORKSPACE b/examples/pip_parse_vendored/WORKSPACE
index 2f0bfb1..157f70a 100644
--- a/examples/pip_parse_vendored/WORKSPACE
+++ b/examples/pip_parse_vendored/WORKSPACE
@@ -1,22 +1,13 @@
workspace(name = "pip_repository_annotations_example")
-load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
-
local_repository(
name = "rules_python",
path = "../..",
)
-http_archive(
- name = "bazel_skylib",
- sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d",
- urls = [
- "https://github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
- "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
- ],
-)
+load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")
-load("@rules_python//python:repositories.bzl", "python_register_toolchains")
+py_repositories()
python_register_toolchains(
name = "python39",
diff --git a/examples/pip_repository_annotations/WORKSPACE b/examples/pip_repository_annotations/WORKSPACE
index 8fd998b..3deea03 100644
--- a/examples/pip_repository_annotations/WORKSPACE
+++ b/examples/pip_repository_annotations/WORKSPACE
@@ -1,22 +1,13 @@
workspace(name = "pip_repository_annotations_example")
-load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
-
local_repository(
name = "rules_python",
path = "../..",
)
-http_archive(
- name = "bazel_skylib",
- sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d",
- urls = [
- "https://github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
- "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
- ],
-)
+load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")
-load("@rules_python//python:repositories.bzl", "python_register_toolchains")
+py_repositories()
python_register_toolchains(
name = "python39",
diff --git a/python/repositories.bzl b/python/repositories.bzl
index e0c9b06..ba8e433 100644
--- a/python/repositories.bzl
+++ b/python/repositories.bzl
@@ -17,6 +17,8 @@
For historic reasons, pip_repositories() is defined in //python:pip.bzl.
"""
+load("@bazel_tools//tools/build_defs/repo:http.bzl", _http_archive = "http_archive")
+load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load(
"//python/private:toolchains_repo.bzl",
"multi_toolchain_aliases",
@@ -32,9 +34,23 @@
"get_release_url",
)
+def http_archive(**kwargs):
+ maybe(_http_archive, **kwargs)
+
def py_repositories():
- # buildifier: disable=print
- print("py_repositories is a no-op and is deprecated. You can remove this from your WORKSPACE file")
+ """Runtime dependencies that users must install.
+
+ This function should be loaded and called in the user's WORKSPACE.
+ With bzlmod enabled, this function is not needed since MODULE.bazel handles transitive deps.
+ """
+ http_archive(
+ name = "bazel_skylib",
+ sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
+ urls = [
+ "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
+ "https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
+ ],
+ )
########
# Remaining content of the file is only used to support toolchains.
diff --git a/tests/pip_repository_entry_points/WORKSPACE b/tests/pip_repository_entry_points/WORKSPACE
index e2915b9..1afd68c 100644
--- a/tests/pip_repository_entry_points/WORKSPACE
+++ b/tests/pip_repository_entry_points/WORKSPACE
@@ -1,22 +1,13 @@
workspace(name = "pip_repository_annotations_example")
-load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
-
-http_archive(
- name = "bazel_skylib",
- sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d",
- urls = [
- "https://github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
- "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
- ],
-)
-
local_repository(
name = "rules_python",
path = "../..",
)
-load("@rules_python//python:repositories.bzl", "python_register_toolchains")
+load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")
+
+py_repositories()
# This toolchain is explicitly 3.10 while `rules_python` is 3.9 to act as
# a regression test, ensuring 3.10 is functional