diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-03-25 11:05:23 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-25 11:05:23 (GMT) |
commit | 4aec9a8be2f2574f249008eb8be76c070fea37eb (patch) | |
tree | 109e24fae63d38d6e566c791d73df2c3609d4d4d /Lib/zipapp.py | |
parent | 3c749fc867f69deac75f866d5c1ba0f60e54c1fa (diff) | |
download | cpython-4aec9a8be2f2574f249008eb8be76c070fea37eb.zip cpython-4aec9a8be2f2574f249008eb8be76c070fea37eb.tar.gz cpython-4aec9a8be2f2574f249008eb8be76c070fea37eb.tar.bz2 |
bpo-29901: Improve support of path-like objects in zipapp. (#815)
Now general path-like objects are supported, not just pathlib.Path.
Diffstat (limited to 'Lib/zipapp.py')
-rw-r--r-- | Lib/zipapp.py | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/Lib/zipapp.py b/Lib/zipapp.py index eceb91d..c23b788 100644 --- a/Lib/zipapp.py +++ b/Lib/zipapp.py @@ -36,9 +36,7 @@ class ZipAppError(ValueError): @contextlib.contextmanager def _maybe_open(archive, mode): - if isinstance(archive, pathlib.Path): - archive = str(archive) - if isinstance(archive, str): + if isinstance(archive, (str, os.PathLike)): with open(archive, mode) as f: yield f else: @@ -135,10 +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: - root = pathlib.Path(source) - for child in root.rglob('*'): - arcname = str(child.relative_to(root)) - z.write(str(child), arcname) + for child in source.rglob('*'): + arcname = child.relative_to(source).as_posix() + z.write(child, arcname) if main_py: z.writestr('__main__.py', main_py.encode('utf-8')) |