From f61b4cfff5ffe2dc112230f6c3d82a7caad50dd5 Mon Sep 17 00:00:00 2001 From: Alex Trotta Date: Wed, 3 Sep 2025 00:54:27 -0400 Subject: [PATCH 1/2] Allow files in wheels to be installed to directories When specifying `data_files` in `py_wheel`, allow just the directory to be specified (with a trailing slash), in which case it will use the file's name. This avoids duplicating (potentially platform-specific) names. --- python/private/py_wheel.bzl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python/private/py_wheel.bzl b/python/private/py_wheel.bzl index 8202fa015a..90a505c33b 100644 --- a/python/private/py_wheel.bzl +++ b/python/private/py_wheel.bzl @@ -519,10 +519,13 @@ def _py_wheel_impl(ctx): filename, ), ) + + final_filename = filename + target_files[0].basename if filename.endswith("/") else filename + other_inputs.extend(target_files) args.add( "--data_files", - filename + ";" + target_files[0].path, + final_filename + ";" + target_files[0].path, ) ctx.actions.run( From c9f1b27861eac3362c3e0171d5751171b20e5a2b Mon Sep 17 00:00:00 2001 From: Ahajha Date: Wed, 19 Nov 2025 03:09:07 -0500 Subject: [PATCH 2/2] Allow files or groups of files to be installed to directories --- python/private/py_wheel.bzl | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/python/private/py_wheel.bzl b/python/private/py_wheel.bzl index 90a505c33b..deca637afb 100644 --- a/python/private/py_wheel.bzl +++ b/python/private/py_wheel.bzl @@ -505,9 +505,9 @@ def _py_wheel_impl(ctx): for target, filename in ctx.attr.data_files.items(): target_files = target[DefaultInfo].files.to_list() - if len(target_files) != 1: + if len(target_files) != 1 and not filename.endswith("/"): fail( - "Multi-file target listed in data_files %s", + "Multi-file target listed in data_files %s, this is only supported when specifying a folder path (i.e. a path ending in '/')", filename, ) @@ -520,13 +520,14 @@ def _py_wheel_impl(ctx): ), ) - final_filename = filename + target_files[0].basename if filename.endswith("/") else filename + for file in target_files: + final_filename = filename + file.basename if filename.endswith("/") else filename - other_inputs.extend(target_files) - args.add( - "--data_files", - final_filename + ";" + target_files[0].path, - ) + other_inputs.extend(target_files) + args.add( + "--data_files", + final_filename + ";" + file.path, + ) ctx.actions.run( mnemonic = "PyWheel",