Skip to content

Commit

Permalink
Add CompleteDirs.inject classmethod for use elsewhere
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Sep 17, 2023
1 parent c331584 commit c230d98
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions newsfragments/+0dd97633.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added ``CompleteDirs.inject`` classmethod to make available for use elsewhere.
12 changes: 1 addition & 11 deletions tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions zipp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit c230d98

Please sign in to comment.