Skip to content

Commit 46487e1

Browse files
authored
Merge branch 'master' into doc/linking-and-entities
2 parents 95c89c6 + 90834f1 commit 46487e1

3 files changed

Lines changed: 16 additions & 17 deletions

File tree

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
8383
and tweak wording a bit.
8484
- Update documentation for linking-related construction variables.
8585
Add a few more live links.
86+
- zip tool now uses zipfile module's "from_file" method to populate
87+
ZipInfo records, rather than doing manually.
8688

8789

8890
RELEASE 4.10.1 - Sun, 16 Nov 2025 10:51:57 -0700

RELEASE.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ long function signature lines, and some linting-insipired cleanups.
8181

8282
- Test suite: end to end tests don't use assert in result checks
8383

84+
- zip tool now uses zipfile module's "from_file" method to populate ZipInfo
85+
records, rather than doing manually.
86+
8487

8588
PACKAGING
8689
---------

SCons/Tool/zip.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,41 +29,36 @@
2929
There normally shouldn't be any need to import this module directly.
3030
It will usually be imported through the generic SCons.Tool.Tool()
3131
selection method.
32-
3332
"""
3433

3534
import os
3635

36+
import SCons.Action
3737
import SCons.Builder
3838
import SCons.Defaults
3939
import SCons.Node.FS
4040
import SCons.Util
4141

42-
import time
4342
import zipfile
4443

4544

4645
zip_compression = zipfile.ZIP_DEFLATED
4746

4847

49-
def _create_zipinfo_for_file(fname, arcname, date_time, compression):
50-
st = os.stat(fname)
51-
if not date_time:
52-
mtime = time.localtime(st.st_mtime)
53-
date_time = mtime[0:6]
54-
zinfo = zipfile.ZipInfo(filename=arcname, date_time=date_time)
55-
zinfo.external_attr = (st.st_mode & 0xFFFF) << 16 # Unix attributes
48+
def _create_zipinfo_for_file(fname: str, arcname: str, date_time: tuple, compression: int) -> zipfile.ZipInfo:
49+
zinfo = zipfile.ZipInfo.from_file(fname, arcname)
50+
if date_time:
51+
zinfo.date_time = date_time
5652
zinfo.compress_type = compression
57-
zinfo.file_size = st.st_size
5853
return zinfo
5954

6055

6156
def zip_builder(target, source, env) -> None:
62-
compression = env.get('ZIPCOMPRESSION', zipfile.ZIP_STORED)
63-
zip_root = str(env.get('ZIPROOT', ''))
64-
date_time = env.get('ZIP_OVERRIDE_TIMESTAMP')
57+
compression: int = env.get('ZIPCOMPRESSION', zipfile.ZIP_STORED)
58+
zip_root: str = str(env.get('ZIPROOT', ''))
59+
date_time: tuple = env.get('ZIP_OVERRIDE_TIMESTAMP')
6560

66-
files = []
61+
files: list[str] = []
6762
for s in source:
6863
if s.isdir():
6964
for dirpath, dirnames, filenames in os.walk(str(s)):
@@ -74,10 +69,9 @@ def zip_builder(target, source, env) -> None:
7469
else:
7570
files.append(str(s))
7671

77-
with zipfile.ZipFile(str(target[0]), 'w', compression) as zf:
72+
with zipfile.ZipFile(str(target[0]), mode='w', compression=compression) as zf:
7873
for fname in files:
7974
arcname = os.path.relpath(fname, zip_root)
80-
# TODO: Switch to ZipInfo.from_file when 3.6 becomes the base python version
8175
zinfo = _create_zipinfo_for_file(fname, arcname, date_time, compression)
8276
with open(fname, "rb") as f:
8377
zf.writestr(zinfo, f.read())
@@ -92,7 +86,7 @@ def zip_builder(target, source, env) -> None:
9286
source_factory=SCons.Node.FS.Entry,
9387
source_scanner=SCons.Defaults.DirScanner,
9488
suffix='$ZIPSUFFIX',
95-
multi=1)
89+
multi=True)
9690

9791

9892
def generate(env) -> None:

0 commit comments

Comments
 (0)