]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[2.7] bpo-34738: Add directory entries in ZIP files created by distutils. (GH-9419...
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 5 Dec 2018 22:02:10 +0000 (00:02 +0200)
committerGitHub <noreply@github.com>
Wed, 5 Dec 2018 22:02:10 +0000 (00:02 +0200)
(cherry picked from commit 67a93b3a0b3814e97ef9d077b21325fc8ce351b2)

Lib/distutils/archive_util.py
Lib/distutils/tests/test_archive_util.py
Lib/distutils/tests/test_bdist_dumb.py
Lib/distutils/tests/test_sdist.py
Misc/NEWS.d/next/Library/2018-09-19-16-51-04.bpo-34738.Pr3-iG.rst [new file with mode: 0644]

index 834b722ed3f140784e308231f667794c9c2a4b43..19a3bc466894a43acd2efbaade4f42bec1085945 100644 (file)
@@ -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):
index ed7c2cea69cbc75e8ee13c9c1b45223de8b50b72..137100cca83dfc34bb3547170bf0a2d9de729829 100644 (file)
@@ -98,7 +98,7 @@ class ArchiveUtilTestCase(support.TempdirManager,
         try:
             names = tar.getnames()
             names.sort()
-            return tuple(names)
+            return names
         finally:
             tar.close()
 
index 5db3a850f8e4cc2221ddce4c5ee9c3490d269083..ef9e68131b1a620f983c7d4255e90d26c76fa801 100644 (file)
@@ -86,7 +86,7 @@ class BuildDumbTestCase(support.TempdirManager,
         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')
index 02c1d12e20ccd6a0237ef80c7251c50c335680b9..c503bd62b7a44ab59adb16ec29fb40df164273bc 100644 (file)
@@ -130,7 +130,9 @@ class SDistTestCase(PyPIRCCommandTestCase):
             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 @@ class SDistTestCase(PyPIRCCommandTestCase):
             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 (file)
index 0000000..c3f402d
--- /dev/null
@@ -0,0 +1,2 @@
+ZIP files created by :mod:`distutils` will now include entries for
+directories.