• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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""
16
17load("@rules_testing//lib:test_suite.bzl", "test_suite")
18load("//python/private/pypi:generate_whl_library_build_bazel.bzl", "generate_whl_library_build_bazel")  # buildifier: disable=bzl-visibility
19
20_tests = []
21
22def _test_all(env):
23    want = """\
24load("@rules_python//python/private/pypi:whl_library_targets.bzl", "whl_library_targets")
25
26package(default_visibility = ["//visibility:public"])
27
28whl_library_targets(
29    copy_executables = {
30        "exec_src": "exec_dest",
31    },
32    copy_files = {
33        "file_src": "file_dest",
34    },
35    data = ["extra_target"],
36    data_exclude = [
37        "exclude_via_attr",
38        "data_exclude_all",
39    ],
40    dep_template = "@pypi//{name}:{target}",
41    dependencies = [
42        "foo",
43        "bar-baz",
44        "qux",
45    ],
46    dependencies_by_platform = {
47        "linux_x86_64": [
48            "box",
49            "box-amd64",
50        ],
51        "windows_x86_64": ["fox"],
52        "@platforms//os:linux": ["box"],
53    },
54    entry_points = {
55        "foo": "bar.py",
56    },
57    group_deps = [
58        "foo",
59        "fox",
60        "qux",
61    ],
62    group_name = "qux",
63    name = "foo.whl",
64    srcs_exclude = ["srcs_exclude_all"],
65    tags = [
66        "tag2",
67        "tag1",
68    ],
69)
70
71# SOMETHING SPECIAL AT THE END
72"""
73    actual = generate_whl_library_build_bazel(
74        dep_template = "@pypi//{name}:{target}",
75        name = "foo.whl",
76        dependencies = ["foo", "bar-baz", "qux"],
77        dependencies_by_platform = {
78            "linux_x86_64": ["box", "box-amd64"],
79            "windows_x86_64": ["fox"],
80            "@platforms//os:linux": ["box"],  # buildifier: disable=unsorted-dict-items to check that we sort inside the test
81        },
82        tags = ["tag2", "tag1"],
83        entry_points = {
84            "foo": "bar.py",
85        },
86        data_exclude = ["exclude_via_attr"],
87        annotation = struct(
88            copy_files = {"file_src": "file_dest"},
89            copy_executables = {"exec_src": "exec_dest"},
90            data = ["extra_target"],
91            data_exclude_glob = ["data_exclude_all"],
92            srcs_exclude_glob = ["srcs_exclude_all"],
93            additive_build_content = """# SOMETHING SPECIAL AT THE END""",
94        ),
95        group_name = "qux",
96        group_deps = ["foo", "fox", "qux"],
97    )
98    env.expect.that_str(actual.replace("@@", "@")).equals(want)
99
100_tests.append(_test_all)
101
102def generate_whl_library_build_bazel_test_suite(name):
103    """Create the test suite.
104
105    Args:
106        name: the name of the test suite
107    """
108    test_suite(name = name, basic_tests = _tests)
109