8000 bpo-46951: Order contents of zipapps (GH-31713) · coderanger/cpython@47e68d4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 47e68d4

Browse files
authored
bpo-46951: Order contents of zipapps (pythonGH-31713)
So that builds are more reproducible.
1 parent bbcf424 commit 47e68d4

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

Lib/test/test_zipapp.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@ def test_create_archive_with_subdirs(self):
5454
self.assertIn('foo/', z.namelist())
5555
self.assertIn('bar/', z.namelist())
5656

57+
def test_create_sorted_archive(self):
58+
# Test that zipapps order their files by name
59+
source = self.tmpdir / 'source'
60+
source.mkdir()
61+
(source / 'zed.py').touch()
62+
(source / 'bin').mkdir()
63+
(source / 'bin' / 'qux').touch()
64+
(source / 'bin' / 'baz').touch()
65+
(source / '__main__.py').touch()
66+
target = io.BytesIO()
67+
zipapp.create_archive(str(source), target)
68+
target.seek(0)
69+
with zipfile.ZipFile(target, 'r') as zf:
70+
self.assertEqual(zf.namelist(),
71+
["__main__.py", "bin/", "bin/baz", "bin/qux", "zed.py"])
72+
5773
def test_create_archive_with_filter(self):
5874
# Test packing a directory and using filter to specify
5975
# which files to include.

Lib/zipapp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def create_archive(source, target=None, interpreter=None, main=None,
136136
compression = (zipfile.ZIP_DEFLATED if compressed else
137137
zipfile.ZIP_STORED)
138138
with zipfile.ZipFile(fd, 'w', compression=compression) as z:
139-
for child in source.rglob('*'):
139+
for child in sorted(source.rglob('*')):
140140
arcname = child.relative_to(source)
141141
if filter is None or filter(arcname):
142142
z.write(child, arcname.as_posix())
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Order the contents of zipapp archives, to make builds more reproducible.

0 commit comments

Comments
 (0)
0