Skip to content

Commit

Permalink
make automatic zip files (by giving .zip extension) reproducible
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Jan 8, 2025
1 parent a53c747 commit 9ddf5c3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pyglossary/compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,17 @@ def compressionOpen(

def zipFileOrDir(filename: str) -> None:
import shutil
import zipfile
from os.path import (
isdir,
isfile,
split,
)

from pyglossary.repro_zipfile import ReproducibleZipFile as ZipFile

from .os_utils import indir

def _zipFileAdd(zf: zipfile.ZipFile, filename: str) -> None:
def _zipFileAdd(zf: ZipFile, filename: str) -> None:
if isfile(filename):
zf.write(filename)
return
Expand All @@ -93,7 +94,7 @@ def _zipFileAdd(zf: zipfile.ZipFile, filename: str) -> None:
for subFname in os.listdir(filename):
_zipFileAdd(zf, join(filename, subFname))

with zipfile.ZipFile(f"{filename}.zip", mode="w") as zf:
with ZipFile(f"{filename}.zip", mode="w") as zf:
if isdir(filename):
dirn, name = split(filename)
with indir(filename):
Expand Down

0 comments on commit 9ddf5c3

Please sign in to comment.