Skip to content

Commit 90be7ed

Browse files
committed
fix python3.6 compresslevel arg of zipfile
1 parent 2fb6d1c commit 90be7ed

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

zipapps/main.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def __init__(
117117

118118
self._tmp_dir: tempfile.TemporaryDirectory = None
119119
self._build_success = False
120+
self._is_greater_than_python_37 = sys.version_info.minor >= 7 and sys.version_info.major >= 3
120121

121122
def ensure_args(self):
122123
if not self.unzip:
@@ -188,15 +189,15 @@ def create_archive_layer(self):
188189
else:
189190
compression = ZIP_DEFLATED
190191
compresslevel = 0
191-
with ZipFile(str(self._output_path),
192-
mode='w',
193-
compression=compression,
194-
compresslevel=compresslevel) as zf:
192+
_kwargs = dict(mode='w', compression=compression)
193+
if self._is_greater_than_python_37:
194+
_kwargs['compresslevel'] = compresslevel
195+
with ZipFile(str(self._output_path), **_kwargs) as zf:
195196
for f in self._cache_path.glob('**/*'):
196197
zf.write(f, str(f.relative_to(self._cache_path)))
197198

198199
def create_archive(self):
199-
if sys.version_info.minor >= 7:
200+
if self._is_greater_than_python_37:
200201
zipapp.create_archive(source=self._cache_path,
201202
target=str(self._output_path.absolute()),
202203
interpreter=self.interpreter,

0 commit comments

Comments
 (0)