From c230d98ed10c81c42f8b30fb5ef61bec9a42d80e Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 17 Sep 2023 10:52:33 -0400 Subject: [PATCH] Add CompleteDirs.inject classmethod for use elsewhere --- newsfragments/+0dd97633.feature.rst | 1 + tests/test_path.py | 12 +----------- zipp/__init__.py | 10 ++++++++++ 3 files changed, 12 insertions(+), 11 deletions(-) create mode 100644 newsfragments/+0dd97633.feature.rst diff --git a/newsfragments/+0dd97633.feature.rst b/newsfragments/+0dd97633.feature.rst new file mode 100644 index 0000000..fecd3c3 --- /dev/null +++ b/newsfragments/+0dd97633.feature.rst @@ -0,0 +1 @@ +Added ``CompleteDirs.inject`` classmethod to make available for use elsewhere. \ No newline at end of file diff --git a/tests/test_path.py b/tests/test_path.py index 1e27ccc..a77a5de 100644 --- a/tests/test_path.py +++ b/tests/test_path.py @@ -17,16 +17,6 @@ from ._test_params import parameterize, Invoked -def add_dirs(zf): - """ - Given a writable zip file zf, inject directory entries for - any directories implied by the presence of children. - """ - for name in zipp.CompleteDirs._implied_dirs(zf.namelist()): - zf.writestr(name, b"") - return zf - - def build_alpharep_fixture(): """ Create a zip file with this structure: @@ -82,7 +72,7 @@ def temp_dir(): alpharep_generators = [ Invoked.wrap(build_alpharep_fixture), - Invoked.wrap(compose(add_dirs, build_alpharep_fixture)), + Invoked.wrap(compose(zipp.CompleteDirs.inject, build_alpharep_fixture)), ] pass_alpharep = parameterize(['alpharep'], alpharep_generators) diff --git a/zipp/__init__.py b/zipp/__init__.py index 5f0c105..becd010 100644 --- a/zipp/__init__.py +++ b/zipp/__init__.py @@ -148,6 +148,16 @@ def make(cls, source): source.__class__ = cls return source + @classmethod + def inject(cls, zf: zipfile.ZipFile) -> zipfile.ZipFile: + """ + Given a writable zip file zf, inject directory entries for + any directories implied by the presence of children. + """ + for name in cls._implied_dirs(zf.namelist()): + zf.writestr(name, b"") + return zf + class FastLookup(CompleteDirs): """