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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/workspace_snippet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@ Paste this snippet into your \`WORKSPACE\` file:

\`\`\`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
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module(
)

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")
Expand Down
15 changes: 3 additions & 12 deletions examples/multi_python_versions/WORKSPACE
Original file line number Diff line number Diff line change
@@ -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 = "../..",
Expand All @@ -20,7 +9,9 @@ load("@rules_python//python/pip_install:repositories.bzl", "pip_install_dependen

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"

Expand Down
15 changes: 3 additions & 12 deletions examples/pip_install/WORKSPACE
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
15 changes: 3 additions & 12 deletions examples/pip_parse/WORKSPACE
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
13 changes: 2 additions & 11 deletions examples/pip_parse_vendored/WORKSPACE
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
13 changes: 2 additions & 11 deletions examples/pip_repository_annotations/WORKSPACE
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
20 changes: 18 additions & 2 deletions python/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -32,9 +34,23 @@ load(
"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.
Expand Down
15 changes: 3 additions & 12 deletions tests/pip_repository_entry_points/WORKSPACE
Original file line number Diff line number Diff line change
@@ -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
Expand Down