Skip to content

Commit 8e1815f

Browse files
Make pip_library zip safety end-to-end tests self-contained (#256)
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.
1 parent 7f230ab commit 8e1815f

File tree

9 files changed

+78
-19
lines changed

9 files changed

+78
-19
lines changed

.plzconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[Please]
2-
Version = >=17.12.2
2+
Version = >=17.19.1
33

44
[Build]
55
hashcheckers = sha256
@@ -18,6 +18,7 @@ Target = //plugins:shell
1818

1919
[Plugin "e2e"]
2020
Target = //plugins:e2e
21+
DefaultPlugin = //test:python-rules
2122

2223
[PluginDefinition]
2324
name = python

BUILD

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@ remote_file(
1111
url = f"https://get.please.build/{CONFIG.OS}_{CONFIG.ARCH}/{v}/please_{v}",
1212
visibility = ["PUBLIC"],
1313
)
14+
15+
export_file(
16+
name = "plzconfig",
17+
src = ".plzconfig",
18+
test_only = True,
19+
visibility = [
20+
"//test:python-rules",
21+
],
22+
)

plugins/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ plugin_repo(
1111
plugin_repo(
1212
name = "e2e",
1313
plugin = "plugin-integration-testing",
14-
revision = "v1.0.3",
14+
revision = "v1.1.0",
1515
)

test/BUILD

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ package(
1717
},
1818
)
1919

20+
e2e_test_plugin(
21+
name = "python-rules",
22+
srcs = [
23+
"//build_defs:archs",
24+
"//build_defs:python",
25+
"//build_defs:version",
26+
"//tools:please_pex",
27+
"//:plzconfig",
28+
],
29+
visibility = [
30+
"//test/...",
31+
],
32+
)
33+
2034
python_binary(
2135
name = "strip_source",
2236
main = "strip_source.py",
@@ -132,18 +146,19 @@ python_test(
132146
deps = ["//third_party/python:cx_oracle"],
133147
)
134148

135-
plz_e2e_test(
136-
name = "correct_labels_on_pip_libary_non_zip_safe",
137-
cmd = "plz query print -f labels //third_party/python:pyyaml",
138-
expected_output = "expected_labels_on_pyyaml.txt",
139-
deps = ["//third_party/python:pyyaml"],
140-
)
141-
142-
plz_e2e_test(
143-
name = "correct_labels_on_pip_libary_zip_safe",
144-
cmd = "plz query print -f labels //third_party/python:grpcio",
145-
expected_output = "expected_labels_on_grpcio.txt",
146-
deps = ["//third_party/python:grpcio"],
149+
plugin_e2e_test(
150+
name = "pip_libary_zip_safe_label_test",
151+
repo = "zip_safe_label_repo",
152+
test_cmd = [
153+
"plz query print -f labels //third_party/python:safe > safe",
154+
"plz query print -f labels //third_party/python:safe_implicit > safe_implicit",
155+
"plz query print -f labels //third_party/python:unsafe > unsafe",
156+
],
157+
expected_output = {
158+
"safe": "py\npip:safe==1.0.0",
159+
"safe_implicit": "py\npip:safe_implicit==1.0.0",
160+
"unsafe": "py\npip:unsafe==1.0.0\npy:zip-unsafe",
161+
},
147162
)
148163

149164
# Test that python_wheel targets can have name_scheme as a list or a string

test/expected_labels_on_grpcio.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

test/expected_labels_on_pyyaml.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Plugin "python"]
2+
Target = //plugins:python
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
plugin_repo(
2+
name = "python",
3+
revision = "e2e",
4+
)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
subinclude("///python//build_defs:python")
2+
3+
package(
4+
# The pip_library targets below aren't real Python modules, and don't need to be downloaded in
5+
# order for this test to run - make sure we don't accidentally look for them on PyPI.
6+
python = {
7+
"default_pip_repo": "https://nonexistent.example",
8+
"use_pypi": False,
9+
},
10+
)
11+
12+
# This target is explicitly zip-safe:
13+
pip_library(
14+
name = "safe",
15+
licences = ["MIT"],
16+
version = "1.0.0",
17+
zip_safe = True,
18+
)
19+
20+
# This target is implicitly zip-safe, because it specifies no value for zip_safe:
21+
pip_library(
22+
name = "safe_implicit",
23+
licences = ["MIT"],
24+
version = "1.0.0",
25+
)
26+
27+
# This target is explicitly zip-unsafe:
28+
pip_library(
29+
name = "unsafe",
30+
licences = ["MIT"],
31+
version = "1.0.0",
32+
zip_safe = False,
33+
)

0 commit comments

Comments
 (0)