Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: zipinfo regular file #220

Merged
merged 3 commits into from Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/scikit_build_core/build/_wheelfile.py
Expand Up @@ -158,6 +158,7 @@ def write(self, filename: str, arcname: str | None = None) -> None:
st = os.fstat(f.fileno())
data = f.read()
zinfo = ZipInfo(arcname or str(filename), date_time=self.timestamp(st.st_mtime))
zinfo.compress_type = zipfile.ZIP_DEFLATED
zinfo.external_attr = (stat.S_IMODE(st.st_mode) | stat.S_IFMT(st.st_mode)) << 16
self.writestr(zinfo, data)

Expand All @@ -169,7 +170,8 @@ def writestr(self, zinfo_or_arcname: str | ZipInfo, data: bytes) -> None:
zinfo = zinfo_or_arcname
else:
zinfo = zipfile.ZipInfo(zinfo_or_arcname, date_time=self.timestamp())
zinfo.external_attr = 0o664 << 16
zinfo.compress_type = zipfile.ZIP_DEFLATED
zinfo.external_attr = (0o664 | stat.S_IFREG) << 16
self.zipfile.writestr(zinfo, data)

def __enter__(self) -> Self:
Expand All @@ -192,8 +194,6 @@ def __exit__(self, *args: object) -> None:
sha = _b64encode(hashlib.sha256(member_data).digest()).decode("ascii")
writer.writerow((member.filename, f"sha256={sha}", member.file_size))
writer.writerow((record, "", ""))
zi = zipfile.ZipInfo(record, date_time=self.timestamp())
zi.external_attr = 0o664 << 16
self.zipfile.writestr(zi, data.getvalue().encode("utf-8"))
self.writestr(record, data.getvalue().encode("utf-8"))
self.zipfile.close()
self.zipfile = None
5 changes: 5 additions & 0 deletions tests/test_wheelfile_utils.py
@@ -1,3 +1,4 @@
import stat
import zipfile

from packaging.tags import Tag
Expand Down Expand Up @@ -67,3 +68,7 @@ def test_wheel_writer_simple(tmp_path, monkeypatch):
zf.read("something-1.2.3.dist-info/entry_points.txt")
== dist_info["entry_points.txt"]
)

for info in zf.infolist():
assert info.external_attr == (0o664 | stat.S_IFREG) << 16
assert info.compress_type == zipfile.ZIP_DEFLATED