Skip to content

Commit b2742ba

Browse files
[2.7] bpo-34738: Add directory entries in ZIP files created by distutils. (GH-9419). (GH-10950)
(cherry picked from commit 67a93b3)
1 parent abe74fe commit b2742ba

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

Lib/distutils/archive_util.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,15 @@ def make_zipfile(base_name, base_dir, verbose=0, dry_run=0):
162162
zip = zipfile.ZipFile(zip_filename, "w",
163163
compression=zipfile.ZIP_DEFLATED)
164164

165+
if base_dir != os.curdir:
166+
path = os.path.normpath(os.path.join(base_dir, ''))
167+
zip.write(path, path)
168+
log.info("adding '%s'", path)
165169
for dirpath, dirnames, filenames in os.walk(base_dir):
170+
for name in dirnames:
171+
path = os.path.normpath(os.path.join(dirpath, name, ''))
172+
zip.write(path, path)
173+
log.info("adding '%s'", path)
166174
for name in filenames:
167175
path = os.path.normpath(os.path.join(dirpath, name))
168176
if os.path.isfile(path):

Lib/distutils/tests/test_archive_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def _tarinfo(self, path):
9898
try:
9999
names = tar.getnames()
100100
names.sort()
101-
return tuple(names)
101+
return names
102102
finally:
103103
tar.close()
104104

Lib/distutils/tests/test_bdist_dumb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def test_simple_built(self):
8686
finally:
8787
fp.close()
8888

89-
contents = sorted(os.path.basename(fn) for fn in contents)
89+
contents = sorted(filter(None, map(os.path.basename, contents)))
9090
wanted = ['foo-0.1-py%s.%s.egg-info' % sys.version_info[:2], 'foo.py']
9191
if not sys.dont_write_bytecode:
9292
wanted.append('foo.pyc')

Lib/distutils/tests/test_sdist.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ def test_prune_file_list(self):
130130
zip_file.close()
131131

132132
# making sure everything has been pruned correctly
133-
self.assertEqual(len(content), 4)
133+
expected = ['', 'PKG-INFO', 'README', 'setup.py',
134+
'somecode/', 'somecode/__init__.py']
135+
self.assertEqual(sorted(content), ['fake-1.0/' + x for x in expected])
134136

135137
@unittest.skipUnless(zlib, "requires zlib")
136138
def test_make_distribution(self):
@@ -246,7 +248,13 @@ def test_add_defaults(self):
246248
zip_file.close()
247249

248250
# making sure everything was added
249-
self.assertEqual(len(content), 12)
251+
expected = ['', 'PKG-INFO', 'README', 'buildout.cfg',
252+
'data/', 'data/data.dt', 'inroot.txt',
253+
'scripts/', 'scripts/script.py', 'setup.py',
254+
'some/', 'some/file.txt', 'some/other_file.txt',
255+
'somecode/', 'somecode/__init__.py', 'somecode/doc.dat',
256+
'somecode/doc.txt']
257+
self.assertEqual(sorted(content), ['fake-1.0/' + x for x in expected])
250258

251259
# checking the MANIFEST
252260
f = open(join(self.tmp_dir, 'MANIFEST'))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ZIP files created by :mod:`distutils` will now include entries for
2+
directories.

0 commit comments

Comments
 (0)