From 690ef029c6327e3b0e8dca298a38812e0a752ff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Stradomski?= Date: Thu, 7 Apr 2022 21:44:55 +0200 Subject: [PATCH 1/2] Fix a bug where path prefix could be stripped from the distinfo directory name Fixes bug #682 --- examples/wheel/BUILD | 7 +++++-- examples/wheel/wheel_test.py | 9 +++++---- tools/wheelmaker.py | 4 ++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/examples/wheel/BUILD b/examples/wheel/BUILD index 0c24da8218..85062cb5e7 100644 --- a/examples/wheel/BUILD +++ b/examples/wheel/BUILD @@ -130,12 +130,15 @@ py_wheel( # An example of how to change the wheel package root directory using 'strip_path_prefixes'. py_wheel( name = "custom_package_root", - # Package data. We're building "custom_package_root-0.0.1-py3-none-any.whl" - distribution = "example_custom_package_root", + # Package data. We're building "examples_custom_package_root-0.0.1-py3-none-any.whl" + distribution = "examples_custom_package_root", python_tag = "py3", strip_path_prefixes = [ "examples", ], + entry_points = { + "console_scripts": ["main = foo.bar:baz"], + }, version = "0.0.1", deps = [ ":example_pkg", diff --git a/examples/wheel/wheel_test.py b/examples/wheel/wheel_test.py index ffdc6409e4..be74792a70 100644 --- a/examples/wheel/wheel_test.py +++ b/examples/wheel/wheel_test.py @@ -219,7 +219,7 @@ def test_custom_package_root_wheel(self): "rules_python", "examples", "wheel", - "example_custom_package_root-0.0.1-py3-none-any.whl", + "examples_custom_package_root-0.0.1-py3-none-any.whl", ) with zipfile.ZipFile(filename) as zf: @@ -230,9 +230,10 @@ def test_custom_package_root_wheel(self): "wheel/lib/module_with_data.py", "wheel/lib/simple_module.py", "wheel/main.py", - "example_custom_package_root-0.0.1.dist-info/WHEEL", - "example_custom_package_root-0.0.1.dist-info/METADATA", - "example_custom_package_root-0.0.1.dist-info/RECORD", + "examples_custom_package_root-0.0.1.dist-info/WHEEL", + "examples_custom_package_root-0.0.1.dist-info/METADATA", + "examples_custom_package_root-0.0.1.dist-info/entry_points.txt", + "examples_custom_package_root-0.0.1.dist-info/RECORD", ], ) diff --git a/tools/wheelmaker.py b/tools/wheelmaker.py index 4b87a596ab..0bd585f3bb 100644 --- a/tools/wheelmaker.py +++ b/tools/wheelmaker.py @@ -67,6 +67,7 @@ def __init__( + ".dist-info/" ) self._zipfile = None + # Entries for the RECORD file as (filename, hash, size) tuples. self._record = [] def __enter__(self): @@ -119,6 +120,9 @@ def add_file(self, package_filename, real_filename): def arcname_from(name): # Always use unix path separators. normalized_arcname = name.replace(os.path.sep, "/") + # Don't manipulate names filenames in the .distinfo directory. + if normalized_arcname.startswith(self._distinfo_dir): + return normalized_arcname for prefix in self._strip_path_prefixes: if normalized_arcname.startswith(prefix): return normalized_arcname[len(prefix) :] From 5ffe22ba6275f2e60f3e5a3fa8b04840a6390f2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Stradomski?= Date: Fri, 8 Apr 2022 00:10:50 +0200 Subject: [PATCH 2/2] Buildifier fixes. --- examples/wheel/BUILD | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/wheel/BUILD b/examples/wheel/BUILD index 85062cb5e7..151a9c94ec 100644 --- a/examples/wheel/BUILD +++ b/examples/wheel/BUILD @@ -132,13 +132,13 @@ py_wheel( name = "custom_package_root", # Package data. We're building "examples_custom_package_root-0.0.1-py3-none-any.whl" distribution = "examples_custom_package_root", + entry_points = { + "console_scripts": ["main = foo.bar:baz"], + }, python_tag = "py3", strip_path_prefixes = [ "examples", ], - entry_points = { - "console_scripts": ["main = foo.bar:baz"], - }, version = "0.0.1", deps = [ ":example_pkg",