diff options
author | Jeffrey Rackauckas <jeffreyrack@gmail.com> | 2017-08-09 13:37:17 (GMT) |
---|---|---|
committer | Paul Moore <p.f.moore@gmail.com> | 2017-08-09 13:37:17 (GMT) |
commit | b811d664defed085d16951088afb579fb649c58d (patch) | |
tree | 8d440084c8a7fc1b4cef670cb8c9b772b5a2236a /Lib/zipapp.py | |
parent | 9b0d1d647e3d2ec9d299e5c9f49b02fbbb810a5a (diff) | |
download | cpython-b811d664defed085d16951088afb579fb649c58d.zip cpython-b811d664defed085d16951088afb579fb649c58d.tar.gz cpython-b811d664defed085d16951088afb579fb649c58d.tar.bz2 |
bpo-31072: Add filter to zipapp (#3021)
bpo-31072: Add a filter argument to zipapp.create_archive (GH-3021)
* Add an include_file argument to allow callers to decide which files to include
* Document the new argument
Diffstat (limited to 'Lib/zipapp.py')
-rw-r--r-- | Lib/zipapp.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/zipapp.py b/Lib/zipapp.py index c23b788..bf15b68 100644 --- a/Lib/zipapp.py +++ b/Lib/zipapp.py @@ -73,7 +73,8 @@ def _copy_archive(archive, new_archive, interpreter=None): os.chmod(new_archive, os.stat(new_archive).st_mode | stat.S_IEXEC) -def create_archive(source, target=None, interpreter=None, main=None): +def create_archive(source, target=None, interpreter=None, main=None, + include_file=None): """Create an application archive from SOURCE. The SOURCE can be the name of a directory, or a filename or a file-like @@ -135,7 +136,8 @@ def create_archive(source, target=None, interpreter=None, main=None): with zipfile.ZipFile(fd, 'w') as z: for child in source.rglob('*'): arcname = child.relative_to(source).as_posix() - z.write(child, arcname) + if include_file is None or include_file(pathlib.Path(arcname)): + z.write(child, arcname) if main_py: z.writestr('__main__.py', main_py.encode('utf-8')) |