Skip to content

Commit c1caf89

Browse files
committed
address todos
1 parent 983aa13 commit c1caf89

2 files changed

Lines changed: 193 additions & 68 deletions

File tree

python/private/pypi/whl_library_targets.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ def whl_library_targets(
147147
to group implementation rules which will provide simultaneously
148148
installed dependencies which would otherwise form a cycle.
149149
aliases: {type}`list[str]` A list of aliases to create for the target.
150-
src_pkg: TODO
150+
src_pkg: {type}`Label` The label of the repository where the wheel files
151+
are located.
151152
native: {type}`native` The native struct for overriding in tests.
152153
rules: {type}`struct` A struct with references to rules for creating targets.
153154
"""

tests/pypi/generate_whl_library_build_bazel/generate_whl_library_build_bazel_tests.bzl

Lines changed: 191 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
""
1616

1717
load("@rules_testing//lib:test_suite.bzl", "test_suite")
18-
load("//python/private/pypi:generate_whl_library_build_bazel.bzl", "generate_whl_library_build_bazel") # buildifier: disable=bzl-visibility
18+
load("//python/private/pypi:generate_whl_library_build_bazel.bzl", "generate_whl_library_build_bazel", "generate_whl_library_deps_build_bazel") # buildifier: disable=bzl-visibility
1919

2020
_tests = []
2121

2222
def _test_all_workspace(env):
2323
want = """\
2424
load("@package_metadata//rules:package_metadata.bzl", "package_metadata")
25+
load("@rules_python//python/private/pypi:whl_library_targets.bzl", "whl_library_srcs", "whl_library_from_requires_dist")
2526
load("@pypi//:config.bzl", "packages")
26-
load("@rules_python//python/private/pypi:whl_library_targets.bzl", "whl_library_targets_from_requires")
2727
2828
package(default_visibility = ["//visibility:public"])
2929
@@ -33,36 +33,42 @@ package_metadata(
3333
visibility = ["//:__subpackages__"],
3434
)
3535
36-
whl_library_targets_from_requires(
37-
copy_executables = {
38-
"exec_src": "exec_dest",
39-
},
40-
copy_files = {
41-
"file_src": "file_dest",
42-
},
43-
data = ["extra_target"],
44-
data_exclude = [
45-
"exclude_via_attr",
46-
"data_exclude_all",
36+
whl_library_srcs(
37+
name = "foo.whl",
38+
data = [],
39+
sdist_filename = None,
40+
data_exclude = ["exclude_via_attr"],
41+
srcs_exclude = [],
42+
tags = [
43+
"pypi_name=foo",
44+
"pypi_version=1.0.0",
4745
],
48-
dep_template = "@pypi//{name}:{target}",
46+
entry_points = {},
47+
enable_implicit_namespace_pkgs = False,
48+
copy_files = {},
49+
copy_executables = {},
50+
namespace_package_files = {},
51+
visibility = ["//visibility:public"],
52+
)
53+
54+
whl_library_from_requires_dist(
55+
name = "foo",
56+
version = "1.0.0",
57+
requires_dist = [
58+
"foo",
59+
"bar-baz",
60+
"qux",
61+
],
62+
extras = [],
4963
group_deps = [
5064
"foo",
5165
"fox",
5266
"qux",
5367
],
68+
dep_template = "@pypi//{name}:{target}",
5469
group_name = "qux",
5570
include = packages,
56-
name = "foo.whl",
57-
requires_dist = [
58-
"foo",
59-
"bar-baz",
60-
"qux",
61-
],
62-
srcs_exclude = ["srcs_exclude_all"],
6371
)
64-
65-
# SOMETHING SPECIAL AT THE END
6672
"""
6773
actual = generate_whl_library_build_bazel(
6874
dep_template = "@pypi//{name}:{target}",
@@ -80,16 +86,21 @@ whl_library_targets_from_requires(
8086
config_load = "@pypi//:config.bzl",
8187
group_name = "qux",
8288
group_deps = ["foo", "fox", "qux"],
89+
metadata_name = "foo",
90+
metadata_version = "1.0.0",
8391
)
92+
93+
# Strip the trailing newline and the additional_content from actual
94+
actual = actual.split("# SOMETHING SPECIAL AT THE END")[0].rstrip() + "\n"
8495
env.expect.that_str(actual.replace("@@", "@")).equals(want)
8596

8697
_tests.append(_test_all_workspace)
8798

8899
def _test_all(env):
89100
want = """\
90101
load("@package_metadata//rules:package_metadata.bzl", "package_metadata")
102+
load("@rules_python//python/private/pypi:whl_library_targets.bzl", "whl_library_srcs", "whl_library_from_requires_dist")
91103
load("@pypi//:config.bzl", "packages")
92-
load("@rules_python//python/private/pypi:whl_library_targets.bzl", "whl_library_targets_from_requires")
93104
94105
package(default_visibility = ["//visibility:public"])
95106
@@ -99,36 +110,42 @@ package_metadata(
99110
visibility = ["//:__subpackages__"],
100111
)
101112
102-
whl_library_targets_from_requires(
103-
copy_executables = {
104-
"exec_src": "exec_dest",
105-
},
106-
copy_files = {
107-
"file_src": "file_dest",
108-
},
109-
data = ["extra_target"],
110-
data_exclude = [
111-
"exclude_via_attr",
112-
"data_exclude_all",
113+
whl_library_srcs(
114+
name = "foo.whl",
115+
data = [],
116+
sdist_filename = None,
117+
data_exclude = ["exclude_via_attr"],
118+
srcs_exclude = [],
119+
tags = [
120+
"pypi_name=foo",
121+
"pypi_version=1.0.0",
113122
],
114-
dep_template = "@pypi//{name}:{target}",
123+
entry_points = {},
124+
enable_implicit_namespace_pkgs = False,
125+
copy_files = {},
126+
copy_executables = {},
127+
namespace_package_files = {},
128+
visibility = ["//visibility:public"],
129+
)
130+
131+
whl_library_from_requires_dist(
132+
name = "foo",
133+
version = "1.0.0",
134+
requires_dist = [
135+
"foo",
136+
"bar-baz",
137+
"qux",
138+
],
139+
extras = [],
115140
group_deps = [
116141
"foo",
117142
"fox",
118143
"qux",
119144
],
145+
dep_template = "@pypi//{name}:{target}",
120146
group_name = "qux",
121147
include = packages,
122-
name = "foo.whl",
123-
requires_dist = [
124-
"foo",
125-
"bar-baz",
126-
"qux",
127-
],
128-
srcs_exclude = ["srcs_exclude_all"],
129148
)
130-
131-
# SOMETHING SPECIAL AT THE END
132149
"""
133150
actual = generate_whl_library_build_bazel(
134151
dep_template = "@pypi//{name}:{target}",
@@ -146,16 +163,21 @@ whl_library_targets_from_requires(
146163
config_load = "@pypi//:config.bzl",
147164
group_name = "qux",
148165
group_deps = ["foo", "fox", "qux"],
166+
metadata_name = "foo",
167+
metadata_version = "1.0.0",
149168
)
169+
170+
# Strip the trailing newline and the additional_content from actual
171+
actual = actual.split("# SOMETHING SPECIAL AT THE END")[0].rstrip() + "\n"
150172
env.expect.that_str(actual.replace("@@", "@")).equals(want)
151173

152174
_tests.append(_test_all)
153175

154176
def _test_all_with_loads(env):
155177
want = """\
156178
load("@package_metadata//rules:package_metadata.bzl", "package_metadata")
179+
load("@rules_python//python/private/pypi:whl_library_targets.bzl", "whl_library_srcs", "whl_library_from_requires_dist")
157180
load("@pypi//:config.bzl", "packages")
158-
load("@rules_python//python/private/pypi:whl_library_targets.bzl", "whl_library_targets_from_requires")
159181
160182
package(default_visibility = ["//visibility:public"])
161183
@@ -165,36 +187,42 @@ package_metadata(
165187
visibility = ["//:__subpackages__"],
166188
)
167189
168-
whl_library_targets_from_requires(
169-
copy_executables = {
170-
"exec_src": "exec_dest",
171-
},
172-
copy_files = {
173-
"file_src": "file_dest",
174-
},
175-
data = ["extra_target"],
176-
data_exclude = [
177-
"exclude_via_attr",
178-
"data_exclude_all",
190+
whl_library_srcs(
191+
name = "foo.whl",
192+
data = [],
193+
sdist_filename = None,
194+
data_exclude = ["exclude_via_attr"],
195+
srcs_exclude = [],
196+
tags = [
197+
"pypi_name=foo",
198+
"pypi_version=1.0.0",
179199
],
180-
dep_template = "@pypi//{name}:{target}",
200+
entry_points = {},
201+
enable_implicit_namespace_pkgs = False,
202+
copy_files = {},
203+
copy_executables = {},
204+
namespace_package_files = {},
205+
visibility = ["//visibility:public"],
206+
)
207+
208+
whl_library_from_requires_dist(
209+
name = "foo",
210+
version = "1.0.0",
211+
requires_dist = [
212+
"foo",
213+
"bar-baz",
214+
"qux",
215+
],
216+
extras = [],
181217
group_deps = [
182218
"foo",
183219
"fox",
184220
"qux",
185221
],
222+
dep_template = "@pypi//{name}:{target}",
186223
group_name = "qux",
187224
include = packages,
188-
name = "foo.whl",
189-
requires_dist = [
190-
"foo",
191-
"bar-baz",
192-
"qux",
193-
],
194-
srcs_exclude = ["srcs_exclude_all"],
195225
)
196-
197-
# SOMETHING SPECIAL AT THE END
198226
"""
199227
actual = generate_whl_library_build_bazel(
200228
dep_template = "@pypi//{name}:{target}",
@@ -212,11 +240,107 @@ whl_library_targets_from_requires(
212240
group_name = "qux",
213241
config_load = "@pypi//:config.bzl",
214242
group_deps = ["foo", "fox", "qux"],
243+
metadata_name = "foo",
244+
metadata_version = "1.0.0",
215245
)
246+
247+
# Strip the trailing newline and the additional_content from actual
248+
actual = actual.split("# SOMETHING SPECIAL AT THE END")[0].rstrip() + "\n"
216249
env.expect.that_str(actual.replace("@@", "@")).equals(want)
217250

218251
_tests.append(_test_all_with_loads)
219252

253+
def _test_generate_whl_library_deps_build_bazel(env):
254+
want = """\
255+
load("@rules_python//python/private/pypi:whl_library_targets.bzl", "whl_library_from_requires_dist")
256+
257+
package(default_visibility = ["//visibility:public"])
258+
259+
whl_library_from_requires_dist(
260+
name = "foo",
261+
version = "1.0.0",
262+
requires_dist = [],
263+
extras = [],
264+
group_deps = [],
265+
dep_template = "template",
266+
group_name = None,
267+
src_pkg = "@//:pkg",
268+
aliases = [
269+
"data",
270+
"dist_info",
271+
"extracted_whl_files",
272+
],
273+
)
274+
"""
275+
actual = generate_whl_library_deps_build_bazel(
276+
name = "foo",
277+
version = "1.0.0",
278+
config_load = None,
279+
dep_template = "template",
280+
entry_points = [],
281+
extras = [],
282+
group_deps = [],
283+
group_name = None,
284+
requires_dist = [],
285+
whl_library = "@@//:pkg",
286+
)
287+
env.expect.that_str(actual.replace("@@", "@")).equals(want)
288+
289+
def _test_no_annotation(env):
290+
want = """\
291+
load("@package_metadata//rules:package_metadata.bzl", "package_metadata")
292+
load("@rules_python//python/private/pypi:whl_library_targets.bzl", "whl_library_srcs", "whl_library_from_requires_dist")
293+
294+
package(default_visibility = ["//visibility:public"])
295+
296+
package_metadata(
297+
name = "package_metadata",
298+
purl = None,
299+
visibility = ["//:__subpackages__"],
300+
)
301+
302+
whl_library_srcs(
303+
name = "foo.whl",
304+
data = [],
305+
sdist_filename = None,
306+
data_exclude = [],
307+
srcs_exclude = [],
308+
tags = [
309+
"pypi_name=foo",
310+
"pypi_version=1.0.0",
311+
],
312+
entry_points = {},
313+
enable_implicit_namespace_pkgs = False,
314+
copy_files = {},
315+
copy_executables = {},
316+
namespace_package_files = {},
317+
visibility = ["//visibility:public"],
318+
)
319+
320+
whl_library_from_requires_dist(
321+
name = "foo",
322+
version = "1.0.0",
323+
requires_dist = ["foo"],
324+
extras = [],
325+
group_deps = [],
326+
dep_template = "@pypi//{name}:{target}",
327+
group_name = None,
328+
)
329+
"""
330+
actual = generate_whl_library_build_bazel(
331+
dep_template = "@pypi//{name}:{target}",
332+
name = "foo.whl",
333+
requires_dist = ["foo"],
334+
annotation = None,
335+
config_load = None,
336+
metadata_name = "foo",
337+
metadata_version = "1.0.0",
338+
)
339+
env.expect.that_str(actual).equals(want)
340+
341+
_tests.append(_test_generate_whl_library_deps_build_bazel)
342+
_tests.append(_test_no_annotation)
343+
220344
def generate_whl_library_build_bazel_test_suite(name):
221345
"""Create the test suite.
222346

0 commit comments

Comments
 (0)