From 0cd570e52939500065cca8e1c7baa895b4b43a4c Mon Sep 17 00:00:00 2001 From: David Burns Date: Tue, 26 Jan 2021 18:22:49 +0000 Subject: [PATCH 1/3] Check if input_file is directory and then add all files within that directory (#336) If in a dependency tree a directory is used as out this is passed as input_file to wheelmaker which then generates an unhandled error as it tries to write the directory as a file. Co-authored-by: Jonathon Belotti --- experimental/examples/wheel/BUILD | 31 +++++++++++++++++++++++ experimental/examples/wheel/wheel_test.py | 15 +++++++++++ experimental/tools/wheelmaker.py | 7 +++++ 3 files changed, 53 insertions(+) diff --git a/experimental/examples/wheel/BUILD b/experimental/examples/wheel/BUILD index 0613e6a74c..64f1d66047 100644 --- a/experimental/examples/wheel/BUILD +++ b/experimental/examples/wheel/BUILD @@ -31,6 +31,20 @@ py_library( ], ) +py_library( + name = "main_with_gen_data", + srcs = ["main.py"], + data = [ + ":gen_dir", + ], +) + +genrule( + name = "gen_dir", + outs = ["someDir"], + cmd = "mkdir -p $@ && touch $@/foo.py", +) + # Package just a specific py_libraries, without their dependencies py_wheel( name = "minimal_with_py_library", @@ -53,6 +67,12 @@ py_package( deps = [":main"], ) +py_package( + name = "example_pkg_with_data", + packages = ["experimental.examples.wheel"], + deps = [":main_with_gen_data"] +) + py_wheel( name = "minimal_with_py_package", # Package data. We're building "example_minimal_package-0.0.1-py3-none-any.whl" @@ -146,6 +166,16 @@ py_wheel( ], ) +py_wheel( + name = "use_genrule_with_dir_in_outs", + distribution = "use_genrule_with_dir_in_outs", + python_tag = "py3", + version = "0.0.1", + deps = [ + ":example_pkg_with_data" + ] +) + py_wheel( name = "python_abi3_binary_wheel", abi = "abi3", @@ -168,5 +198,6 @@ py_test( ":minimal_with_py_package", ":python_abi3_binary_wheel", ":python_requires_in_a_package", + ":use_genrule_with_dir_in_outs", ], ) diff --git a/experimental/examples/wheel/wheel_test.py b/experimental/examples/wheel/wheel_test.py index e461fa9dde..aa33d53e8d 100644 --- a/experimental/examples/wheel/wheel_test.py +++ b/experimental/examples/wheel/wheel_test.py @@ -219,6 +219,21 @@ def test_python_abi3_binary_wheel(self): """, ) + def test_genrule_creates_directory_and_is_included_in_wheel(self): + filename = os.path.join(os.environ['TEST_SRCDIR'], + 'rules_python', 'experimental', + 'examples', 'wheel', + 'use_genrule_with_dir_in_outs-0.0.1-py3-none-any.whl') + + with zipfile.ZipFile(filename) as zf: + self.assertEquals( + zf.namelist(), + ['experimental/examples/wheel/main.py', + 'experimental/examples/wheel/someDir/foo.py', + 'use_genrule_with_dir_in_outs-0.0.1.dist-info/WHEEL', + 'use_genrule_with_dir_in_outs-0.0.1.dist-info/METADATA', + 'use_genrule_with_dir_in_outs-0.0.1.dist-info/RECORD']) + if __name__ == '__main__': unittest.main() diff --git a/experimental/tools/wheelmaker.py b/experimental/tools/wheelmaker.py index 18e63573e9..418dfdbb1a 100644 --- a/experimental/tools/wheelmaker.py +++ b/experimental/tools/wheelmaker.py @@ -102,6 +102,13 @@ def arcname_from(name): return normalized_arcname + if os.path.isdir(real_filename): + directory_contents = os.listdir(real_filename) + for file_ in directory_contents: + self.add_file("{}/{}".format(package_filename, file_), + "{}/{}".format(real_filename, file_)) + return + arcname = arcname_from(package_filename) self._zipfile.write(real_filename, arcname=arcname) From 8537cea11d867333c07c465d536778c1b7560cde Mon Sep 17 00:00:00 2001 From: Jonathon Belotti Date: Thu, 28 Jan 2021 10:46:42 +1100 Subject: [PATCH 2/3] pip_repositories() is deprecated. remove directive to use it from README (#407) --- README.md | 7 ------- 1 file changed, 7 deletions(-) diff --git a/README.md b/README.md index a2592f4f3c..591c403554 100644 --- a/README.md +++ b/README.md @@ -66,13 +66,6 @@ http_archive( ) ``` -If you want to use the pip packaging rules, also add: - -```python -load("@rules_python//python:pip.bzl", "pip_repositories") -pip_repositories() -``` - To depend on a particular unreleased version (not recommended), you can do: ```python From c7e068d38e2fec1d899e1c150e372f205c220e27 Mon Sep 17 00:00:00 2001 From: Greg Roodt Date: Wed, 3 Feb 2021 09:16:45 +1100 Subject: [PATCH 3/3] pip: 20.3.3 -> 20.3.4 (#405) --- python/pip_install/repositories.bzl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/pip_install/repositories.bzl b/python/pip_install/repositories.bzl index 828ab5396c..835a21eb2d 100644 --- a/python/pip_install/repositories.bzl +++ b/python/pip_install/repositories.bzl @@ -6,8 +6,8 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") _RULE_DEPS = [ ( "pypi__pip", - "https://files.pythonhosted.org/packages/54/eb/4a3642e971f404d69d4f6fa3885559d67562801b99d7592487f1ecc4e017/pip-20.3.3-py2.py3-none-any.whl", - "fab098c8a1758295dd9f57413c199f23571e8fde6cc39c22c78c961b4ac6286d", + "https://files.pythonhosted.org/packages/27/79/8a850fe3496446ff0d584327ae44e7500daf6764ca1a382d2d02789accf7/pip-20.3.4-py2.py3-none-any.whl", + "217ae5161a0e08c0fb873858806e3478c9775caffce5168b50ec885e358c199d", ), ( "pypi__pkginfo", @@ -21,8 +21,8 @@ _RULE_DEPS = [ ), ( "pypi__wheel", - "https://files.pythonhosted.org/packages/c9/0b/e0fd299d93cd9331657f415085a4956422959897b333e3791dde40bd711d/wheel-0.36.1-py2.py3-none-any.whl", - "906864fb722c0ab5f2f9c35b2c65e3af3c009402c108a709c0aca27bc2c9187b", + "https://files.pythonhosted.org/packages/65/63/39d04c74222770ed1589c0eaba06c05891801219272420b40311cd60c880/wheel-0.36.2-py2.py3-none-any.whl", + "78b5b185f0e5763c26ca1e324373aadd49182ca90e825f7853f4b2509215dc0e", ), ]