Skip to content

Commit 423c1de

Browse files
authored
docs: move dependency management into respective bzl packages (#1459)
This moves the dependency management of what transitive files are needed to generate docs for a .bzl file out of the docs directory and into the respective bzl file's directory. This ensures that the bzl_library targets we expose to users contain all the necessary dependencies. Because there are some projects using the bzl_library targets in //docs, some compatiblity aliases are added to make their migration path easier. Those targets only public for historical reasons and shouldn't be used. Work towards #1458
1 parent 7e07684 commit 423c1de

File tree

6 files changed

+217
-45
lines changed

6 files changed

+217
-45
lines changed

BUILD.bazel

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
1516
load(":version.bzl", "BAZEL_VERSION")
1617

1718
package(default_visibility = ["//visibility:public"])
@@ -44,6 +45,12 @@ filegroup(
4445
],
4546
)
4647

48+
bzl_library(
49+
name = "version_bzl",
50+
srcs = ["version.bzl"],
51+
visibility = ["//:__subpackages__"],
52+
)
53+
4754
# Reexport of all bzl files used to allow downstream rules to generate docs
4855
# without shipping with a dependency on Skylib
4956
filegroup(

docs/BUILD.bazel

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ load("@bazel_skylib//rules:write_file.bzl", "write_file")
1818
load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
1919
load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") # buildifier: disable=bzl-visibility
2020

21+
# NOTE: Only public visibility for historical reasons.
22+
# This package is only for rules_python to generate its own docs.
2123
package(default_visibility = ["//visibility:public"])
2224

2325
licenses(["notice"]) # Apache 2.0
@@ -32,47 +34,35 @@ _DOCS = {
3234
"python": "//docs:core-docs",
3335
}
3436

35-
# We define these bzl_library targets here rather than in the //python package
36-
# because they're only used for doc generation. This way, we avoid requiring
37-
# our users to depend on Skylib.
38-
39-
bzl_library(
40-
name = "bazel_repo_tools",
41-
srcs = [
42-
"@bazel_tools//tools:bzl_srcs",
43-
],
37+
# Temporary compatibility aliases for some other projects depending on the old
38+
# bzl_library targets.
39+
alias(
40+
name = "defs",
41+
actual = "//python:defs_bzl",
42+
deprecation = "Use //python:defs_bzl instead; targets under //docs are internal.",
4443
)
4544

46-
bzl_library(
47-
name = "defs",
48-
srcs = [
49-
"//python:defs.bzl",
50-
"//python/private:reexports.bzl",
51-
],
52-
deps = [
53-
":bazel_repo_tools",
54-
"//python:defs_bzl",
55-
"//python/private:reexports_bzl",
56-
],
45+
alias(
46+
name = "bazel_repo_tools",
47+
actual = "//python/private:bazel_tools_bzl",
48+
deprecation = "Use @bazel_tools//tools:bzl_srcs instead; targets under //docs are internal.",
5749
)
5850

5951
bzl_library(
6052
name = "pip_install_bzl",
61-
srcs = [
62-
"//python:bzl",
63-
"//python/pip_install:bzl",
64-
],
53+
deprecation = "Use //python:pip_bzl or //python/pip_install:pip_repository_bzl instead; " +
54+
"targets under //docs are internal.",
6555
deps = [
66-
":defs",
67-
"//:version.bzl",
56+
"//python:pip_bzl",
57+
"//python/pip_install:pip_repository_bzl",
6858
],
6959
)
7060

71-
bzl_library(
61+
alias(
7262
name = "requirements_parser_bzl",
73-
srcs = [
74-
"//python/pip_install:requirements_parser.bzl",
75-
],
63+
actual = "//python/pip_install:pip_repository_bzl",
64+
deprecation = "Use //python/pip_install:pip_repository_bzl instead; Both the requirements " +
65+
"parser and targets under //docs are internal",
7666
)
7767

7868
# Empty list means "compatible with all".
@@ -93,7 +83,9 @@ stardoc(
9383
out = "python.md_",
9484
input = "//python:defs.bzl",
9585
target_compatible_with = _TARGET_COMPATIBLE_WITH,
96-
deps = [":defs"],
86+
deps = [
87+
"//python:defs_bzl",
88+
],
9789
)
9890

9991
stardoc(
@@ -102,9 +94,7 @@ stardoc(
10294
input = "//python:pip.bzl",
10395
target_compatible_with = _TARGET_COMPATIBLE_WITH,
10496
deps = [
105-
":bazel_repo_tools",
106-
":pip_install_bzl",
107-
"@bazel_skylib//lib:versions",
97+
"//python:pip_bzl",
10898
],
10999
)
110100

@@ -114,10 +104,7 @@ stardoc(
114104
input = "//python/pip_install:pip_repository.bzl",
115105
target_compatible_with = _TARGET_COMPATIBLE_WITH,
116106
deps = [
117-
":bazel_repo_tools",
118-
":pip_install_bzl",
119-
":requirements_parser_bzl",
120-
"@bazel_skylib//lib:versions",
107+
"//python/pip_install:pip_repository_bzl",
121108
],
122109
)
123110

python/BUILD.bazel

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ bzl_library(
8282
],
8383
)
8484

85+
bzl_library(
86+
name = "pip_bzl",
87+
srcs = ["pip.bzl"],
88+
deps = [
89+
"//python/pip_install:pip_repository_bzl",
90+
"//python/pip_install:repositories_bzl",
91+
"//python/pip_install:requirements_bzl",
92+
"//python/private:bzlmod_enabled_bzl",
93+
"//python/private:full_version_bzl",
94+
"//python/private:render_pkg_aliases_bzl",
95+
],
96+
)
97+
8598
bzl_library(
8699
name = "proto_bzl",
87100
srcs = [
@@ -174,6 +187,27 @@ bzl_library(
174187
],
175188
)
176189

190+
bzl_library(
191+
name = "repositories_bzl",
192+
srcs = ["repositories.bzl"],
193+
deps = [
194+
":versions_bzl",
195+
"//python/private:bazel_tools_bzl",
196+
"//python/private:bzlmod_enabled_bzl",
197+
"//python/private:coverage_deps_bzl",
198+
"//python/private:full_version_bzl",
199+
"//python/private:internal_config_repo_bzl",
200+
"//python/private:toolchains_repo_bzl",
201+
"//python/private:which_bzl",
202+
],
203+
)
204+
205+
bzl_library(
206+
name = "versions_bzl",
207+
srcs = ["versions.bzl"],
208+
visibility = ["//:__subpackages__"],
209+
)
210+
177211
# NOTE: Remember to add bzl_library targets to //tests:bzl_libraries
178212
# ========= bzl_library targets end =========
179213

python/pip_install/BUILD.bazel

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,70 @@
1+
# Copyright 2023 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+
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
16+
17+
package(
18+
default_visibility = ["//:__subpackages__"],
19+
)
20+
21+
bzl_library(
22+
name = "pip_repository_bzl",
23+
srcs = ["pip_repository.bzl"],
24+
# Semi-public: What is intended to be public and what is intended to be
25+
# internal is unclear. Some symbols are clearly public (e.g.
26+
# package_annotations), some are clearly internal (e.g.
27+
# pip_hub_repository_bzlmod), and many are unknown.
28+
visibility = ["//visibility:public"],
29+
deps = [
30+
":repositories_bzl",
31+
":requirements_parser_bzl",
32+
"//python:repositories_bzl",
33+
"//python:versions_bzl",
34+
"//python/pip_install/private:generate_whl_library_build_bazel_bzl",
35+
"//python/pip_install/private:srcs_bzl",
36+
"//python/private:bzlmod_enabled_bzl",
37+
"//python/private:normalize_name_bzl",
38+
"//python/private:render_pkg_aliases_bzl",
39+
"//python/private:toolchains_repo_bzl",
40+
"//python/private:which_bzl",
41+
],
42+
)
43+
44+
bzl_library(
45+
name = "requirements_bzl",
46+
srcs = ["requirements.bzl"],
47+
deps = [
48+
":repositories_bzl",
49+
"//python:defs_bzl",
50+
],
51+
)
52+
53+
bzl_library(
54+
name = "requirements_parser_bzl",
55+
srcs = ["requirements_parser.bzl"],
56+
)
57+
58+
bzl_library(
59+
name = "repositories_bzl",
60+
srcs = ["repositories.bzl"],
61+
deps = [
62+
"//:version_bzl",
63+
"//python/private:bazel_tools_bzl",
64+
"@bazel_skylib//lib:versions",
65+
],
66+
)
67+
168
filegroup(
269
name = "distribution",
370
srcs = glob(["*.bzl"]) + [

python/pip_install/private/BUILD.bazel

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
12
load(":pip_install_utils.bzl", "srcs_module")
23

34
package(default_visibility = ["//:__subpackages__"])
@@ -22,3 +23,16 @@ srcs_module(
2223
srcs = "//python/pip_install:py_srcs",
2324
dest = ":srcs.bzl",
2425
)
26+
27+
bzl_library(
28+
name = "generate_whl_library_build_bazel_bzl",
29+
srcs = ["generate_whl_library_build_bazel.bzl"],
30+
deps = [
31+
"//python/private:normalize_name_bzl",
32+
],
33+
)
34+
35+
bzl_library(
36+
name = "srcs_bzl",
37+
srcs = ["srcs.bzl"],
38+
)

python/private/BUILD.bazel

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ load("//python:py_library.bzl", "py_library")
1818
load("//python:versions.bzl", "print_toolchains_checksums")
1919
load(":stamp.bzl", "stamp_build_setting")
2020

21+
package(
22+
default_visibility = ["//:__subpackages__"],
23+
)
24+
2125
licenses(["notice"])
2226

2327
filegroup(
@@ -53,13 +57,34 @@ bzl_library(
5357
)
5458

5559
bzl_library(
56-
name = "util_bzl",
57-
srcs = ["util.bzl"],
58-
visibility = [
59-
"//docs:__subpackages__",
60-
"//python:__subpackages__",
60+
name = "bzlmod_enabled_bzl",
61+
srcs = ["bzlmod_enabled.bzl"],
62+
)
63+
64+
bzl_library(
65+
name = "coverage_deps_bzl",
66+
srcs = ["coverage_deps.bzl"],
67+
deps = [
68+
":bazel_tools_bzl",
69+
":version_label_bzl",
6170
],
62-
deps = ["@bazel_skylib//lib:types"],
71+
)
72+
73+
bzl_library(
74+
name = "full_version_bzl",
75+
srcs = ["full_version.bzl"],
76+
deps = ["//python:versions_bzl"],
77+
)
78+
79+
bzl_library(
80+
name = "internal_config_repo_bzl",
81+
srcs = ["internal_config_repo.bzl"],
82+
deps = [":bzlmod_enabled_bzl"],
83+
)
84+
85+
bzl_library(
86+
name = "normalize_name_bzl",
87+
srcs = ["normalize_name.bzl"],
6388
)
6489

6590
bzl_library(
@@ -138,12 +163,51 @@ bzl_library(
138163
deps = [":bazel_tools_bzl"],
139164
)
140165

166+
bzl_library(
167+
name = "render_pkg_aliases_bzl",
168+
srcs = ["render_pkg_aliases.bzl"],
169+
deps = [
170+
":normalize_name_bzl",
171+
":text_util_bzl",
172+
":version_label_bzl",
173+
],
174+
)
175+
141176
bzl_library(
142177
name = "stamp_bzl",
143178
srcs = ["stamp.bzl"],
144179
visibility = ["//:__subpackages__"],
145180
)
146181

182+
bzl_library(
183+
name = "text_util_bzl",
184+
srcs = ["text_util.bzl"],
185+
)
186+
187+
bzl_library(
188+
name = "toolchains_repo_bzl",
189+
srcs = ["toolchains_repo.bzl"],
190+
deps = [
191+
":which_bzl",
192+
"//python:versions_bzl",
193+
],
194+
)
195+
196+
bzl_library(
197+
name = "util_bzl",
198+
srcs = ["util.bzl"],
199+
visibility = [
200+
"//docs:__subpackages__",
201+
"//python:__subpackages__",
202+
],
203+
deps = ["@bazel_skylib//lib:types"],
204+
)
205+
206+
bzl_library(
207+
name = "version_label_bzl",
208+
srcs = ["version_label.bzl"],
209+
)
210+
147211
bzl_library(
148212
name = "which_bzl",
149213
srcs = ["which.bzl"],
@@ -162,7 +226,6 @@ bzl_library(
162226
# sources.
163227
"@bazel_tools//tools:bzl_srcs",
164228
],
165-
visibility = ["//python:__pkg__"],
166229
)
167230

168231
# Needed to define bzl_library targets for docgen. (We don't define the

0 commit comments

Comments
 (0)