mirror of
https://github.com/python/cpython.git
synced 2025-11-03 19:34:08 +00:00
gh-106531: Apply changes from importlib_resources 6.3.2 (#117054)
Apply changes from importlib_resources 6.3.2.
This commit is contained in:
parent
31a4fb3c74
commit
8d63c8d47b
16 changed files with 231 additions and 146 deletions
30
Lib/test/test_importlib/resources/zip.py
Executable file
30
Lib/test/test_importlib/resources/zip.py
Executable file
|
|
@ -0,0 +1,30 @@
|
|||
"""
|
||||
Generate zip test data files.
|
||||
"""
|
||||
|
||||
import contextlib
|
||||
import os
|
||||
import pathlib
|
||||
import zipfile
|
||||
|
||||
|
||||
def make_zip_file(src, dst):
|
||||
"""
|
||||
Zip the files in src into a new zipfile at dst.
|
||||
"""
|
||||
with zipfile.ZipFile(dst, 'w') as zf:
|
||||
for src_path, rel in walk(src):
|
||||
dst_name = src.name / pathlib.PurePosixPath(rel.as_posix())
|
||||
zf.write(src_path, dst_name)
|
||||
zipfile._path.CompleteDirs.inject(zf)
|
||||
return dst
|
||||
|
||||
|
||||
def walk(datapath):
|
||||
for dirpath, dirnames, filenames in os.walk(datapath):
|
||||
with contextlib.suppress(ValueError):
|
||||
dirnames.remove('__pycache__')
|
||||
for filename in filenames:
|
||||
res = pathlib.Path(dirpath) / filename
|
||||
rel = res.relative_to(datapath)
|
||||
yield res, rel
|
||||
Loading…
Add table
Add a link
Reference in a new issue