aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Rackauckas <jeffreyrack@gmail.com>2017-08-09 06:37:17 -0700
committerPaul Moore <p.f.moore@gmail.com>2017-08-09 14:37:17 +0100
commitb811d664defed085d16951088afb579fb649c58d (patch)
tree8d440084c8a7fc1b4cef670cb8c9b772b5a2236a /Lib/zipapp.py
parentbpo-31070: Fix a race condition in importlib _get_module_lock(). (#3033) (diff)
downloadcpython-b811d664defed085d16951088afb579fb649c58d.tar.gz
cpython-b811d664defed085d16951088afb579fb649c58d.tar.bz2
cpython-b811d664defed085d16951088afb579fb649c58d.zip
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.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/zipapp.py b/Lib/zipapp.py
index c23b788d1c9..bf15b6806dd 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'))