Skip to content

Commit 913819a

Browse files
authored
Fix exploding zip-unsafe pexes (#231)
* Fix exploding zip-unsafe pexes * version * fine we have to skip it entirely for now
1 parent 635fc8b commit 913819a

File tree

7 files changed

+37
-8
lines changed

7 files changed

+37
-8
lines changed

test/BUILD

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,12 @@ python_test(
194194
"//third_party/python:six",
195195
],
196196
)
197+
198+
python_test(
199+
name = "zip_unsafe_test",
200+
srcs = ["zip_unsafe_test.py"],
201+
deps = [
202+
"//third_party/python:confluent-kafka",
203+
],
204+
labels = ["manual"],
205+
)

test/zip_unsafe_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import unittest
2+
3+
4+
class ZipUnsafeTest(unittest.TestCase):
5+
"""Test importing something that requires zip-unsafety and exploding the pex."""
6+
7+
def test_can_import(self):
8+
from third_party.python.confluent_kafka import cimpl
9+
self.assertIsNotNone(cimpl)

third_party/python/BUILD

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,3 +527,11 @@ python_wheel(
527527
version = "0.4.0",
528528
deps = [],
529529
)
530+
531+
pip_library(
532+
name = "confluent-kafka",
533+
licences = ["Apache-2.0"],
534+
version = "2.6.1",
535+
test_only = True,
536+
zip_safe = False,
537+
)

tools/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Version 1.6.1
2+
-------------
3+
* Fix exploding of zip-unsafe pexes (#231)
4+
15
Version 1.6.0
26
-------------
37
* Import hooks are now added in the `plz` module and are hence more usefully importable (#229)

tools/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.6.0
1+
1.6.1

tools/please_pex/pex/pex_main.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@
1919

2020
def add_module_dir_to_sys_path(dirname, zip_safe=True):
2121
"""Adds the given dirname to sys.path if it's nonempty."""
22-
# Add .bootstrap dir to path, after the initial pex entry
23-
sys.path = sys.path[:1] + [os.path.join(sys.path[0], '.bootstrap')] + sys.path[1:]
24-
# Now we have .bootstrap on the path, we can import our own hooks.
25-
import plz
22+
import plz # this needs to be imported after paths are set up
2623
if dirname:
27-
sys.path = sys.path[:1] + [os.path.join(sys.path[0], dirname)] + sys.path[1:]
24+
sys.path.insert(1, os.path.join(sys.path[0], dirname))
2825
sys.meta_path.insert(0, plz.ModuleDirImport(dirname))
2926
if zip_safe:
3027
sys.meta_path.append(plz.SoImport(MODULE_DIR))
@@ -82,10 +79,10 @@ def _explode_zip():
8279
os.makedirs(basepath, exist_ok=True)
8380
with pex_lockfile(basepath, uniquedir) as lockfile:
8481
if len(lockfile.read()) == 0:
85-
import compileall, zipfile
82+
import compileall, zipfile, plz
8683

8784
os.makedirs(PEX_PATH, exist_ok=True)
88-
with ZipFileWithPermissions(PEX, "r") as zf:
85+
with plz.ZipFileWithPermissions(PEX, "r") as zf:
8986
zf.extractall(PEX_PATH)
9087

9188
if not no_cache: # Don't bother optimizing; we're deleting this when we're done.

tools/please_pex/pex/pex_run.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
def run(explode=False):
2+
# Add .bootstrap dir to path, after the initial pex entry
3+
sys.path.insert(1, os.path.join(sys.path[0], '.bootstrap'))
24
if explode or not ZIP_SAFE:
35
with explode_zip()():
46
add_module_dir_to_sys_path(MODULE_DIR, zip_safe=False)

0 commit comments

Comments
 (0)