2424 ":labels.bzl" ,
2525 "DATA_LABEL" ,
2626 "DIST_INFO_LABEL" ,
27+ "EXTRACTED_WHEEL_FILES" ,
2728 "PY_LIBRARY_IMPL_LABEL" ,
2829 "PY_LIBRARY_PUBLIC_LABEL" ,
2930 "WHEEL_ENTRY_POINT_PREFIX" ,
3334load (":namespace_pkgs.bzl" , _create_inits = "create_inits" )
3435load (":pep508_deps.bzl" , "deps" )
3536
37+ # Files that are special to the Bazel processing of things.
38+ _BAZEL_REPO_FILE_GLOBS = [
39+ "BUILD" ,
40+ "BUILD.bazel" ,
41+ "REPO.bazel" ,
42+ "WORKSPACE" ,
43+ "WORKSPACE" ,
44+ "WORKSPACE.bazel" ,
45+ ]
46+
3647def whl_library_targets_from_requires (
3748 * ,
3849 name ,
@@ -97,14 +108,12 @@ def whl_library_targets(
97108 * ,
98109 name ,
99110 dep_template ,
111+ sdist_filename = None ,
100112 data_exclude = [],
101113 srcs_exclude = [],
102114 tags = [],
103- filegroups = {
104- DIST_INFO_LABEL : ["site-packages/*.dist-info/**" ],
105- DATA_LABEL : ["data/**" ],
106- },
107115 dependencies = [],
116+ filegroups = None ,
108117 dependencies_by_platform = {},
109118 dependencies_with_markers = {},
110119 group_deps = [],
@@ -129,14 +138,16 @@ def whl_library_targets(
129138 filegroup. This may be also parsed to generate extra metadata.
130139 dep_template: {type}`str` The dep_template to use for dependency
131140 interpolation.
141+ sdist_filename: {type}`str | None` If the wheel was built from an sdist,
142+ the filename of the sdist.
132143 tags: {type}`list[str]` The tags set on the `py_library`.
133144 dependencies: {type}`list[str]` A list of dependencies.
134145 dependencies_by_platform: {type}`dict[str, list[str]]` A list of
135146 dependencies by platform key.
136147 dependencies_with_markers: {type}`dict[str, str]` A marker to evaluate
137148 in order for the dep to be included.
138- filegroups: {type}`dict[str, list[str]]` A dictionary of the target
139- names and the glob matches.
149+ filegroups: {type}`dict[str, list[str]] | None ` A dictionary of the target
150+ names and the glob matches. If `None`, defaults will be used.
140151 group_name: {type}`str` name of the dependency group (if any) which
141152 contains this library. If set, this library will behave as a shim
142153 to group implementation rules which will provide simultaneously
@@ -169,10 +180,28 @@ def whl_library_targets(
169180 tags = sorted (tags )
170181 data = [] + data
171182
172- for filegroup_name , glob in filegroups .items ():
183+ if filegroups == None :
184+ filegroups = {
185+ EXTRACTED_WHEEL_FILES : dict (
186+ include = ["**" ],
187+ exclude = (
188+ _BAZEL_REPO_FILE_GLOBS +
189+ [sdist_filename ] if sdist_filename else []
190+ ),
191+ ),
192+ DIST_INFO_LABEL : dict (
193+ include = ["site-packages/*.dist-info/**" ],
194+ ),
195+ DATA_LABEL : dict (
196+ include = ["data/**" ],
197+ ),
198+ }
199+
200+ for filegroup_name , glob_kwargs in filegroups .items ():
201+ glob_kwargs = {"allow_empty" : True } | glob_kwargs
173202 native .filegroup (
174203 name = filegroup_name ,
175- srcs = native .glob (glob , allow_empty = True ),
204+ srcs = native .glob (** glob_kwargs ),
176205 visibility = ["//visibility:public" ],
177206 )
178207
0 commit comments