Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5ed8d3f

Browse files
authored
fix(internal): add WORKSPACE.bzlmod to ensure dependency separation (#1806)
Before this PR, WORKSPACE file would be also used when using 'rules_python' under bzlmod and when developing locally it would yield to inconsistent behaviour between the examples and the main workspace. This PR ensures that the `dev_pip` is used via `bzlmod`. Whilst there may be a little bit of duplication from now on, it ensures that non-bzlmod code paths do not leak into the bzlmod dev setup.
1 parent d5945ed commit 5ed8d3f

File tree

5 files changed

+93
-3
lines changed

5 files changed

+93
-3
lines changed

BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ filegroup(
3535
"BUILD.bazel",
3636
"MODULE.bazel",
3737
"WORKSPACE",
38+
"WORKSPACE.bzlmod",
3839
"internal_deps.bzl",
3940
"internal_setup.bzl",
4041
"version.bzl",

MODULE.bazel

+29-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ bazel_dep(name = "platforms", version = "0.0.4")
1212
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
1313
bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf")
1414

15-
internal_deps = use_extension("@rules_python//python/private/bzlmod:internal_deps.bzl", "internal_deps")
15+
internal_deps = use_extension("//python/private/bzlmod:internal_deps.bzl", "internal_deps")
1616
internal_deps.install()
1717
use_repo(
1818
internal_deps,
@@ -38,7 +38,7 @@ use_repo(
3838

3939
# We need to do another use_extension call to expose the "pythons_hub"
4040
# repo.
41-
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
41+
python = use_extension("//python/extensions:python.bzl", "python")
4242

4343
# The default toolchain to use if nobody configures a toolchain.
4444
# NOTE: This is not a stable version. It is provided for convenience, but will
@@ -56,6 +56,13 @@ register_toolchains("@pythons_hub//:all")
5656
# ===== DEV ONLY DEPS AND SETUP BELOW HERE =====
5757
bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True, repo_name = "io_bazel_stardoc")
5858
bazel_dep(name = "rules_bazel_integration_test", version = "0.20.0", dev_dependency = True)
59+
bazel_dep(name = "rules_testing", version = "0.5.0", dev_dependency = True)
60+
bazel_dep(name = "rules_cc", version = "0.0.9", dev_dependency = True)
61+
62+
# Extra gazelle plugin deps so that WORKSPACE.bzlmod can continue including it for e2e tests.
63+
# We use `WORKSPACE.bzlmod` because it is impossible to have dev-only local overrides.
64+
bazel_dep(name = "rules_go", version = "0.41.0", dev_dependency = True, repo_name = "io_bazel_rules_go")
65+
bazel_dep(name = "gazelle", version = "0.33.0", dev_dependency = True, repo_name = "bazel_gazelle")
5966

6067
dev_pip = use_extension(
6168
"//python/extensions:pip.bzl",
@@ -78,6 +85,26 @@ dev_pip.parse(
7885
requirements_lock = "//docs/sphinx:requirements.txt",
7986
)
8087

88+
#####################
89+
# Install twine for our own runfiles wheel publishing.
90+
# Eventually we might want to install twine automatically for users too, see:
91+
# https://github.com/bazelbuild/rules_python/issues/1016.
92+
93+
dev_pip.parse(
94+
hub_name = "publish_deps",
95+
python_version = "3.11",
96+
requirements_darwin = "//tools/publish:requirements_darwin.txt",
97+
requirements_lock = "//tools/publish:requirements.txt",
98+
requirements_windows = "//tools/publish:requirements_windows.txt",
99+
)
100+
use_repo(
101+
dev_pip,
102+
"dev_pip",
103+
publish_deps_twine = "publish_deps_311_twine",
104+
)
105+
106+
# Bazel integration test setup below
107+
81108
bazel_binaries = use_extension(
82109
"@rules_bazel_integration_test//:extensions.bzl",
83110
"bazel_binaries",

WORKSPACE.bzlmod

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Copyright 2024 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# This file contains everything that is needed when using bzlmod
16+
workspace(name = "rules_python")
17+
18+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
19+
20+
# Used for Bazel CI
21+
http_archive(
22+
name = "bazelci_rules",
23+
sha256 = "eca21884e6f66a88c358e580fd67a6b148d30ab57b1680f62a96c00f9bc6a07e",
24+
strip_prefix = "bazelci_rules-1.0.0",
25+
url = "https://github.com/bazelbuild/continuous-integration/releases/download/rules-1.0.0/bazelci_rules-1.0.0.tar.gz",
26+
)
27+
28+
load("@bazelci_rules//:rbe_repo.bzl", "rbe_preconfig")
29+
30+
# Creates a default toolchain config for RBE.
31+
# Use this as is if you are using the rbe_ubuntu16_04 container,
32+
# otherwise refer to RBE docs.
33+
rbe_preconfig(
34+
name = "buildkite_config",
35+
toolchain = "ubuntu1804-bazel-java11",
36+
)
37+
38+
# Add gazelle plugin so that we can run the gazelle example as an e2e integration
39+
# test and include the distribution files.
40+
local_repository(
41+
name = "rules_python_gazelle_plugin",
42+
path = "gazelle",
43+
)
44+
45+
#####################
46+
47+
# This wheel is purely here to validate the wheel extraction code. It's not
48+
# intended for anything else.
49+
http_file(
50+
name = "wheel_for_testing",
51+
downloaded_file_path = "numpy-1.25.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
52+
sha256 = "0d60fbae8e0019865fc4784745814cff1c421df5afee233db6d88ab4f14655a2",
53+
urls = [
54+
"https://files.pythonhosted.org/packages/50/67/3e966d99a07d60a21a21d7ec016e9e4c2642a86fea251ec68677daf71d4d/numpy-1.25.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
55+
],
56+
)
57+
58+
# rules_proto expects //external:python_headers to point at the python headers.
59+
bind(
60+
name = "python_headers",
61+
actual = "//python/cc:current_py_cc_headers",
62+
)

examples/bzlmod_build_file_generation/.bazelversion

-1
This file was deleted.

python/private/common/attributes.bzl

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ NATIVE_RULES_ALLOWLIST_ATTRS = _create_native_rules_allowlist_attrs()
146146
COMMON_ATTRS = union_attrs(
147147
DATA_ATTRS,
148148
NATIVE_RULES_ALLOWLIST_ATTRS,
149+
# buildifier: disable=attr-licenses
149150
{
150151
# NOTE: This attribute is deprecated and slated for removal.
151152
"distribs": attr.string_list(),

0 commit comments

Comments
 (0)