[Python-checkins] [2.7] bpo-34738: Add directory entries in ZIP files created by distutils. (GH-9419). (GH-10950)
Serhiy Storchaka
webhook-mailer at python.org
Wed Dec 5 17:02:16 EST 2018
https://github.com/python/cpython/commit/b2742ba5f9ce8a6108202e0645662f2b58da423b
commit: b2742ba5f9ce8a6108202e0645662f2b58da423b
branch: 2.7
author: Serhiy Storchaka <storchaka at gmail.com>
committer: GitHub <noreply at github.com>
date: 2018-12-06T00:02:10+02:00
summary:
[2.7] bpo-34738: Add directory entries in ZIP files created by distutils. (GH-9419). (GH-10950)
(cherry picked from commit 67a93b3a0b3814e97ef9d077b21325fc8ce351b2)
files:
A Misc/NEWS.d/next/Library/2018-09-19-16-51-04.bpo-34738.Pr3-iG.rst
M Lib/distutils/archive_util.py
M Lib/distutils/tests/test_archive_util.py
M Lib/distutils/tests/test_bdist_dumb.py
M Lib/distutils/tests/test_sdist.py
diff --git a/Lib/distutils/archive_util.py b/Lib/distutils/archive_util.py
index 834b722ed3f1..19a3bc466894 100644
--- a/Lib/distutils/archive_util.py
+++ b/Lib/distutils/archive_util.py
@@ -162,7 +162,15 @@ def make_zipfile(base_name, base_dir, verbose=0, dry_run=0):
zip = zipfile.ZipFile(zip_filename, "w",
compression=zipfile.ZIP_DEFLATED)
+ if base_dir != os.curdir:
+ path = os.path.normpath(os.path.join(base_dir, ''))
+ zip.write(path, path)
+ log.info("adding '%s'", path)
for dirpath, dirnames, filenames in os.walk(base_dir):
+ for name in dirnames:
+ path = os.path.normpath(os.path.join(dirpath, name, ''))
+ zip.write(path, path)
+ log.info("adding '%s'", path)
for name in filenames:
path = os.path.normpath(os.path.join(dirpath, name))
if os.path.isfile(path):
diff --git a/Lib/distutils/tests/test_archive_util.py b/Lib/distutils/tests/test_archive_util.py
index ed7c2cea69cb..137100cca83d 100644
--- a/Lib/distutils/tests/test_archive_util.py
+++ b/Lib/distutils/tests/test_archive_util.py
@@ -98,7 +98,7 @@ def _tarinfo(self, path):
try:
names = tar.getnames()
names.sort()
- return tuple(names)
+ return names
finally:
tar.close()
diff --git a/Lib/distutils/tests/test_bdist_dumb.py b/Lib/distutils/tests/test_bdist_dumb.py
index 5db3a850f8e4..ef9e68131b1a 100644
--- a/Lib/distutils/tests/test_bdist_dumb.py
+++ b/Lib/distutils/tests/test_bdist_dumb.py
@@ -86,7 +86,7 @@ def test_simple_built(self):
finally:
fp.close()
- contents = sorted(os.path.basename(fn) for fn in contents)
+ contents = sorted(filter(None, map(os.path.basename, contents)))
wanted = ['foo-0.1-py%s.%s.egg-info' % sys.version_info[:2], 'foo.py']
if not sys.dont_write_bytecode:
wanted.append('foo.pyc')
diff --git a/Lib/distutils/tests/test_sdist.py b/Lib/distutils/tests/test_sdist.py
index 02c1d12e20cc..c503bd62b7a4 100644
--- a/Lib/distutils/tests/test_sdist.py
+++ b/Lib/distutils/tests/test_sdist.py
@@ -130,7 +130,9 @@ def test_prune_file_list(self):
zip_file.close()
# making sure everything has been pruned correctly
- self.assertEqual(len(content), 4)
+ expected = ['', 'PKG-INFO', 'README', 'setup.py',
+ 'somecode/', 'somecode/__init__.py']
+ self.assertEqual(sorted(content), ['fake-1.0/' + x for x in expected])
@unittest.skipUnless(zlib, "requires zlib")
def test_make_distribution(self):
@@ -246,7 +248,13 @@ def test_add_defaults(self):
zip_file.close()
# making sure everything was added
- self.assertEqual(len(content), 12)
+ expected = ['', 'PKG-INFO', 'README', 'buildout.cfg',
+ 'data/', 'data/data.dt', 'inroot.txt',
+ 'scripts/', 'scripts/script.py', 'setup.py',
+ 'some/', 'some/file.txt', 'some/other_file.txt',
+ 'somecode/', 'somecode/__init__.py', 'somecode/doc.dat',
+ 'somecode/doc.txt']
+ self.assertEqual(sorted(content), ['fake-1.0/' + x for x in expected])
# checking the MANIFEST
f = open(join(self.tmp_dir, 'MANIFEST'))
diff --git a/Misc/NEWS.d/next/Library/2018-09-19-16-51-04.bpo-34738.Pr3-iG.rst b/Misc/NEWS.d/next/Library/2018-09-19-16-51-04.bpo-34738.Pr3-iG.rst
new file mode 100644
index 000000000000..c3f402d39ae0
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-09-19-16-51-04.bpo-34738.Pr3-iG.rst
@@ -0,0 +1,2 @@
+ZIP files created by :mod:`distutils` will now include entries for
+directories.
More information about the Python-checkins
mailing list