From 22685b0fa4c91ef2268ff8c3842aa929a41132c8 Mon Sep 17 00:00:00 2001 From: Chris Novakovic Date: Tue, 14 Oct 2025 17:11:54 +0100 Subject: [PATCH] Make `pip_library` zip safety end-to-end tests self-contained The end-to-end tests that check whether `pip_library` correctly applies the `py:zip-unsafe` label to a zip-unsafe target depend on two third-party Python modules, PyYAML and grpcio. The pre-built wheels on PyPI are architecture-specific, so their versions have to be kept in line with ones for which pre-built wheels are available on PyPI (otherwise pip will take > 10 minutes and a lot of resources to build them from source); even when a pre-built wheel is available for the SOABI in question, the download is disproportionately large for such a simple test (7-12MB for grpcio, depending on the SOABI). Replace the `pip_library` zip safety tests with a single, fully self-contained e2e test that occurs within an e2e-specific Please repo, requiring no downloads from PyPI. --- .plzconfig | 3 +- BUILD | 9 +++++ plugins/BUILD | 2 +- test/BUILD | 39 +++++++++++++------ test/expected_labels_on_grpcio.txt | 2 - test/expected_labels_on_pyyaml.txt | 3 -- test/zip_safe_label_repo/.plzconfig | 2 + test/zip_safe_label_repo/plugins/BUILD_FILE | 4 ++ .../third_party/python/BUILD_FILE | 33 ++++++++++++++++ 9 files changed, 78 insertions(+), 19 deletions(-) delete mode 100644 test/expected_labels_on_grpcio.txt delete mode 100644 test/expected_labels_on_pyyaml.txt create mode 100644 test/zip_safe_label_repo/.plzconfig create mode 100644 test/zip_safe_label_repo/plugins/BUILD_FILE create mode 100644 test/zip_safe_label_repo/third_party/python/BUILD_FILE diff --git a/.plzconfig b/.plzconfig index d3a6ce37..5f116107 100644 --- a/.plzconfig +++ b/.plzconfig @@ -1,5 +1,5 @@ [Please] -Version = >=17.12.2 +Version = >=17.19.1 [Build] hashcheckers = sha256 @@ -18,6 +18,7 @@ Target = //plugins:shell [Plugin "e2e"] Target = //plugins:e2e +DefaultPlugin = //test:python-rules [PluginDefinition] name = python diff --git a/BUILD b/BUILD index d4490a61..f5aacafe 100644 --- a/BUILD +++ b/BUILD @@ -11,3 +11,12 @@ remote_file( url = f"https://get.please.build/{CONFIG.OS}_{CONFIG.ARCH}/{v}/please_{v}", visibility = ["PUBLIC"], ) + +export_file( + name = "plzconfig", + src = ".plzconfig", + test_only = True, + visibility = [ + "//test:python-rules", + ], +) diff --git a/plugins/BUILD b/plugins/BUILD index 5f9a1301..03b61c80 100644 --- a/plugins/BUILD +++ b/plugins/BUILD @@ -11,5 +11,5 @@ plugin_repo( plugin_repo( name = "e2e", plugin = "plugin-integration-testing", - revision = "v1.0.3", + revision = "v1.1.0", ) diff --git a/test/BUILD b/test/BUILD index fd167dbc..216d6e21 100644 --- a/test/BUILD +++ b/test/BUILD @@ -17,6 +17,20 @@ package( }, ) +e2e_test_plugin( + name = "python-rules", + srcs = [ + "//build_defs:archs", + "//build_defs:python", + "//build_defs:version", + "//tools:please_pex", + "//:plzconfig", + ], + visibility = [ + "//test/...", + ], +) + python_binary( name = "strip_source", main = "strip_source.py", @@ -132,18 +146,19 @@ python_test( deps = ["//third_party/python:cx_oracle"], ) -plz_e2e_test( - name = "correct_labels_on_pip_libary_non_zip_safe", - cmd = "plz query print -f labels //third_party/python:pyyaml", - expected_output = "expected_labels_on_pyyaml.txt", - deps = ["//third_party/python:pyyaml"], -) - -plz_e2e_test( - name = "correct_labels_on_pip_libary_zip_safe", - cmd = "plz query print -f labels //third_party/python:grpcio", - expected_output = "expected_labels_on_grpcio.txt", - deps = ["//third_party/python:grpcio"], +plugin_e2e_test( + name = "pip_libary_zip_safe_label_test", + repo = "zip_safe_label_repo", + test_cmd = [ + "plz query print -f labels //third_party/python:safe > safe", + "plz query print -f labels //third_party/python:safe_implicit > safe_implicit", + "plz query print -f labels //third_party/python:unsafe > unsafe", + ], + expected_output = { + "safe": "py\npip:safe==1.0.0", + "safe_implicit": "py\npip:safe_implicit==1.0.0", + "unsafe": "py\npip:unsafe==1.0.0\npy:zip-unsafe", + }, ) # Test that python_wheel targets can have name_scheme as a list or a string diff --git a/test/expected_labels_on_grpcio.txt b/test/expected_labels_on_grpcio.txt deleted file mode 100644 index 4abfdd14..00000000 --- a/test/expected_labels_on_grpcio.txt +++ /dev/null @@ -1,2 +0,0 @@ -py -pip:grpcio==1.75.1 diff --git a/test/expected_labels_on_pyyaml.txt b/test/expected_labels_on_pyyaml.txt deleted file mode 100644 index eec3c79e..00000000 --- a/test/expected_labels_on_pyyaml.txt +++ /dev/null @@ -1,3 +0,0 @@ -py -pip:PyYAML==6.0.2 -py:zip-unsafe diff --git a/test/zip_safe_label_repo/.plzconfig b/test/zip_safe_label_repo/.plzconfig new file mode 100644 index 00000000..2ffad3a3 --- /dev/null +++ b/test/zip_safe_label_repo/.plzconfig @@ -0,0 +1,2 @@ +[Plugin "python"] +Target = //plugins:python diff --git a/test/zip_safe_label_repo/plugins/BUILD_FILE b/test/zip_safe_label_repo/plugins/BUILD_FILE new file mode 100644 index 00000000..bd8b3fd9 --- /dev/null +++ b/test/zip_safe_label_repo/plugins/BUILD_FILE @@ -0,0 +1,4 @@ +plugin_repo( + name = "python", + revision = "e2e", +) diff --git a/test/zip_safe_label_repo/third_party/python/BUILD_FILE b/test/zip_safe_label_repo/third_party/python/BUILD_FILE new file mode 100644 index 00000000..970152f7 --- /dev/null +++ b/test/zip_safe_label_repo/third_party/python/BUILD_FILE @@ -0,0 +1,33 @@ +subinclude("///python//build_defs:python") + +package( + # The pip_library targets below aren't real Python modules, and don't need to be downloaded in + # order for this test to run - make sure we don't accidentally look for them on PyPI. + python = { + "default_pip_repo": "https://nonexistent.example", + "use_pypi": False, + }, +) + +# This target is explicitly zip-safe: +pip_library( + name = "safe", + licences = ["MIT"], + version = "1.0.0", + zip_safe = True, +) + +# This target is implicitly zip-safe, because it specifies no value for zip_safe: +pip_library( + name = "safe_implicit", + licences = ["MIT"], + version = "1.0.0", +) + +# This target is explicitly zip-unsafe: +pip_library( + name = "unsafe", + licences = ["MIT"], + version = "1.0.0", + zip_safe = False, +)