diff options
author | Alex Grönholm <alex.gronholm@nextday.fi> | 2023-03-13 16:57:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-13 16:57:38 +0200 |
commit | 9fb33cb818ab51e9bd5a409354024be183f9b8ce (patch) | |
tree | 6b23782c7864b3b23fbbc04994675eadbac42eee | |
parent | 472e54eadb37ec9ae66a49711c3eb4c311c014e1 (diff) | |
download | wheel-git-9fb33cb818ab51e9bd5a409354024be183f9b8ce.tar.gz |
Mark generated files as regular files (#511)
Fixes #506.
-rw-r--r-- | docs/news.rst | 1 | ||||
-rw-r--r-- | src/wheel/wheelfile.py | 12 | ||||
-rw-r--r-- | tests/test_wheelfile.py | 6 |
3 files changed, 12 insertions, 7 deletions
diff --git a/docs/news.rst b/docs/news.rst index 7b58034..4961729 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -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) diff --git a/src/wheel/wheelfile.py b/src/wheel/wheelfile.py index 8ae9733..25129ce 100644 --- a/src/wheel/wheelfile.py +++ b/src/wheel/wheelfile.py @@ -153,6 +153,13 @@ class WheelFile(ZipFile): 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") @@ -183,9 +190,6 @@ class WheelFile(ZipFile): ) ) 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) diff --git a/tests/test_wheelfile.py b/tests/test_wheelfile.py index ab286a6..b587821 100644 --- a/tests/test_wheelfile.py +++ b/tests/test_wheelfile.py @@ -1,5 +1,6 @@ from __future__ import annotations +import stat import sys from zipfile import ZIP_DEFLATED, ZipFile @@ -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 |