Skip to content

Commit

Permalink
Mark generated files as regular files (#511)
Browse files Browse the repository at this point in the history
Fixes #506.
  • Loading branch information
agronholm committed Mar 13, 2023
1 parent 472e54e commit 9fb33cb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Release Notes

- Updated vendored ``packaging`` to 23.0
- Fixed spaces in platform names not being converted to underscores (PR by David Tucker)
- Fixed ``RECORD`` files in generated wheels missing the regular file attribute
- Fixed ``DeprecationWarning`` about the use of the deprecated ``pkg_resources`` API
(PR by Thomas Grainger)

Expand Down
12 changes: 8 additions & 4 deletions src/wheel/wheelfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ def write(self, filename, arcname=None, compress_type=None):
self.writestr(zinfo, data, compress_type)

def writestr(self, zinfo_or_arcname, data, compress_type=None):
if isinstance(zinfo_or_arcname, str):
zinfo_or_arcname = ZipInfo(
zinfo_or_arcname, date_time=get_zipinfo_datetime()
)
zinfo_or_arcname.compress_type = self.compression
zinfo_or_arcname.external_attr = (0o664 | stat.S_IFREG) << 16

if isinstance(data, str):
data = data.encode("utf-8")

Expand Down Expand Up @@ -183,9 +190,6 @@ def close(self):
)
)
writer.writerow((format(self.record_path), "", ""))
zinfo = ZipInfo(self.record_path, date_time=get_zipinfo_datetime())
zinfo.compress_type = self.compression
zinfo.external_attr = 0o664 << 16
self.writestr(zinfo, data.getvalue())
self.writestr(self.record_path, data.getvalue())

ZipFile.close(self)
6 changes: 3 additions & 3 deletions tests/test_wheelfile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import stat
import sys
from zipfile import ZIP_DEFLATED, ZipFile

Expand Down Expand Up @@ -185,9 +186,8 @@ def test_attributes(tmp_path_factory, wheel_path):
with ZipFile(wheel_path, "r") as zf:
for filename, mode in files:
info = zf.getinfo(filename)
assert info.external_attr == (mode | 0o100000) << 16
assert info.external_attr == (mode | stat.S_IFREG) << 16
assert info.compress_type == ZIP_DEFLATED

info = zf.getinfo("test-1.0.dist-info/RECORD")
permissions = (info.external_attr >> 16) & 0o777
assert permissions == 0o664
assert info.external_attr == (0o664 | stat.S_IFREG) << 16

0 comments on commit 9fb33cb

Please sign in to comment.