summaryrefslogtreecommitdiffstats
path: root/Lib/zipapp.py
diff options
context:
space:
mode:
authorZhiming Wang <zmwangx@gmail.com>2017-09-29 17:31:52 (GMT)
committerPaul Moore <p.f.moore@gmail.com>2017-09-29 17:31:52 (GMT)
commitd87b105ca794addf92addb28293c92a7ef4141e1 (patch)
tree65d69e9473d93bb612d4c3fedbfb714626d402f5 /Lib/zipapp.py
parent6fb0e4a6d085ffa4e4a6daaea042a1cc517fa8bc (diff)
downloadcpython-d87b105ca794addf92addb28293c92a7ef4141e1.zip
cpython-d87b105ca794addf92addb28293c92a7ef4141e1.tar.gz
cpython-d87b105ca794addf92addb28293c92a7ef4141e1.tar.bz2
bpo-31638: Add compression support to zipapp (GH-3819)
Add optional argument `compressed` to `zipapp.create_archive`, and add option `--compress` to the command line interface of `zipapp`.
Diffstat (limited to 'Lib/zipapp.py')
-rw-r--r--Lib/zipapp.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/Lib/zipapp.py b/Lib/zipapp.py
index 51d0290..ce77632 100644
--- a/Lib/zipapp.py
+++ b/Lib/zipapp.py
@@ -74,7 +74,7 @@ def _copy_archive(archive, new_archive, interpreter=None):
def create_archive(source, target=None, interpreter=None, main=None,
- filter=None):
+ filter=None, compressed=False):
"""Create an application archive from SOURCE.
The SOURCE can be the name of a directory, or a filename or a file-like
@@ -133,7 +133,9 @@ def create_archive(source, target=None, interpreter=None, main=None,
with _maybe_open(target, 'wb') as fd:
_write_file_prefix(fd, interpreter)
- with zipfile.ZipFile(fd, 'w') as z:
+ compression = (zipfile.ZIP_DEFLATED if compressed else
+ zipfile.ZIP_STORED)
+ with zipfile.ZipFile(fd, 'w', compression=compression) as z:
for child in source.rglob('*'):
arcname = child.relative_to(source)
if filter is None or filter(arcname):
@@ -170,6 +172,9 @@ def main(args=None):
parser.add_argument('--main', '-m', default=None,
help="The main function of the application "
"(default: use an existing __main__.py).")
+ parser.add_argument('--compress', '-c', action='store_true',
+ help="Compress files with the deflate method. "
+ "Files are stored uncompressed by default.")
parser.add_argument('--info', default=False, action='store_true',
help="Display the interpreter from the archive.")
parser.add_argument('source',
@@ -193,7 +198,8 @@ def main(args=None):
raise SystemExit("Cannot change the main function when copying")
create_archive(args.source, args.output,
- interpreter=args.python, main=args.main)
+ interpreter=args.python, main=args.main,
+ compressed=args.compress)
if __name__ == '__main__':