Skip to content

Commit ecdd24d

Browse files
committed
Docs, tests, changelog
1 parent 5683ee9 commit ecdd24d

4 files changed

Lines changed: 68 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ Other changes:
8787
{obj}`experimental_index_url` which should speed up consecutive initializations and should no
8888
longer require the network access if the cache is hydrated.
8989
Implements [#2731](https://github.com/bazel-contrib/rules_python/issues/2731).
90+
* (wheel) Specifying a path ending in `/` as a destination in `data_files`
91+
will now install file(s) to a folder, preserving their basename.
9092

9193
{#v1-9-0}
9294
## [1.9.0] - 2026-02-21

examples/wheel/BUILD.bazel

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,29 @@ py_wheel(
401401
version = "0.0.1",
402402
)
403403

404+
filegroup(
405+
name = "data_files_test_group",
406+
# Re-using some files already checked into the repo.
407+
srcs = [
408+
"README.md",
409+
"//examples/wheel:NOTICE",
410+
],
411+
)
412+
413+
py_wheel(
414+
name = "data_files_installed_in_folder",
415+
testonly = True, # Set this to verify the generated .dist target doesn't break things
416+
# Re-using some files already checked into the repo.
417+
data_files = {
418+
# Single file
419+
"//examples/wheel:NOTICE": "scripts/",
420+
# Filegroup
421+
":data_files_test_group": "data/",
422+
},
423+
distribution = "data_files_installed_in_folder",
424+
version = "0.0.1",
425+
)
426+
404427
py_test(
405428
name = "wheel_test",
406429
srcs = ["wheel_test.py"],
@@ -409,6 +432,7 @@ py_test(
409432
":custom_package_root_multi_prefix",
410433
":custom_package_root_multi_prefix_reverse_order",
411434
":customized",
435+
":data_files_installed_in_folder",
412436
":empty_requires_files",
413437
":extra_requires",
414438
":filename_escaping",

examples/wheel/wheel_test.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,9 @@ def test_extra_requires(self):
566566
)
567567

568568
def test_requires_dist_depends_on_extras(self):
569-
filename = self._get_path("requires_dist_depends_on_extras-0.0.1-py3-none-any.whl")
569+
filename = self._get_path(
570+
"requires_dist_depends_on_extras-0.0.1-py3-none-any.whl"
571+
)
570572

571573
with zipfile.ZipFile(filename) as zf:
572574
self.assertAllEntriesHasReproducibleMetadata(zf)
@@ -591,7 +593,9 @@ def test_requires_dist_depends_on_extras(self):
591593
)
592594

593595
def test_requires_dist_depends_on_extras_file(self):
594-
filename = self._get_path("requires_dist_depends_on_extras_using_file-0.0.1-py3-none-any.whl")
596+
filename = self._get_path(
597+
"requires_dist_depends_on_extras_using_file-0.0.1-py3-none-any.whl"
598+
)
595599

596600
with zipfile.ZipFile(filename) as zf:
597601
self.assertAllEntriesHasReproducibleMetadata(zf)
@@ -615,6 +619,25 @@ def test_requires_dist_depends_on_extras_file(self):
615619
requires,
616620
)
617621

622+
def test_data_files_installed_in_folder(self):
623+
filename = self._get_path(
624+
"data_files_installed_in_folder-0.0.1-py3-none-any.whl"
625+
)
626+
627+
with zipfile.ZipFile(filename) as zf:
628+
self.assertAllEntriesHasReproducibleMetadata(zf)
629+
self.assertEqual(
630+
zf.namelist(),
631+
[
632+
"data_files_installed_in_folder-0.0.1.dist-info/WHEEL",
633+
"data_files_installed_in_folder-0.0.1.dist-info/METADATA",
634+
"data_files_installed_in_folder-0.0.1.data/data/NOTICE",
635+
"data_files_installed_in_folder-0.0.1.data/data/README.md",
636+
"data_files_installed_in_folder-0.0.1.data/scripts/NOTICE",
637+
"data_files_installed_in_folder-0.0.1.dist-info/RECORD",
638+
],
639+
)
640+
618641

619642
if __name__ == "__main__":
620643
unittest.main()

python/private/py_wheel.bzl

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,23 @@ _other_attrs = {
182182
doc = "A list of strings describing the categories for the package. For valid classifiers see https://pypi.org/classifiers",
183183
),
184184
"data_files": attr.label_keyed_string_dict(
185-
doc = ("Any file that is not normally installed inside site-packages goes into the .data directory, named " +
186-
"as the .dist-info directory but with the .data/ extension. Allowed paths: {prefixes}".format(prefixes = ALLOWED_DATA_FILE_PREFIX)),
185+
doc = ("""
186+
Any file that is not normally installed inside site-packages goes into the .data directory, named
187+
as the .dist-info directory but with the .data/ extension. If the destination of a file or group of files ends
188+
in a `/`, the destination is a folder and files are placed with their existing basenames under that folder.
189+
190+
For example:
191+
`
192+
":file1.txt": "data/file1.txt", # Destination: <wheelname>.data/data/file1.txt
193+
":file1.txt": "data/", # Destination: <wheelname>.data/data/file1.txt
194+
":file1.txt": "data/special.txt", # Destination: <wheelname>.data/data/special.txt
195+
196+
filegroup(name = "files", srcs = [":file1.txt", ":file2.txt"])
197+
":files": "data/", # Destinations: <wheelname>.data/data/file1.txt, <wheelname>.data/data/file2.txt
198+
`
199+
200+
Allowed paths: {prefixes}
201+
""".format(prefixes = ALLOWED_DATA_FILE_PREFIX)),
187202
allow_files = True,
188203
),
189204
"description_content_type": attr.string(

0 commit comments

Comments
 (0)