diff options
Diffstat (limited to 'Lib/zipapp.py')
-rw-r--r-- | Lib/zipapp.py | 12 |
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__': |