Skip to content

Commit

Permalink
feat: Add support for python-wheel data directory
Browse files Browse the repository at this point in the history
This feature addes  attribute to the py_wheel rule and
makes a related change to the wheelmaker tool.

Fixes bazelbuild#1777
  • Loading branch information
BradHolmes committed Mar 12, 2024
1 parent 37455a1 commit 9469321
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion python/private/repack_whl.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ def main(sys_argv):
logging.debug(f"Found dist-info dir: {distinfo_dir}")
record_path = distinfo_dir / "RECORD"
record_contents = record_path.read_text() if record_path.exists() else ""
distribution_prefix = distinfo_dir.with_suffix("").name

with _WhlFile(args.output, mode="w", distinfo_dir=distinfo_dir) as out:
with _WhlFile(args.output, mode="w", distribution_prefix=distribution_prefix) as out:
for p in _files_to_pack(patched_wheel_dir, record_contents):
rel_path = p.relative_to(patched_wheel_dir)
out.add_file(str(rel_path), p)
Expand Down
25 changes: 25 additions & 0 deletions tests/py_wheel/py_wheel_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,31 @@ def _test_metadata_impl(env, target):

_tests.append(_test_metadata)

def _test_data(name):
rt_util.helper_target(
py_wheel,
name = name + "_data",
distribution = "mydist_" + name,
version = "0.0.0",
data_files = {
"source_name": "wheel_name",
},
)
analysis_test(
name = name,
impl = _test_data_impl,
target = name + "_data",
)

def _test_data_impl(env, target):
action = env.expect.that_target(target).action_named(
"PyWheel",
)
action.contains_at_least_args(["--data_files", "wheel_name;tests/py_wheel/source_name"])
action.contains_at_least_inputs(["tests/py_wheel/source_name"])

_tests.append(_test_data)

def _test_content_type_from_attr(name):
rt_util.helper_target(
py_wheel,
Expand Down
2 changes: 1 addition & 1 deletion tools/wheelmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def __init__(
filename,
*,
mode,
distribution_prefix: str | Path,
distribution_prefix: str,
strip_path_prefixes=None,
compression=zipfile.ZIP_DEFLATED,
**kwargs,
Expand Down

0 comments on commit 9469321

Please sign in to comment.