]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Warn instead of crashing because of invalid path in MANIFEST.in (#8286).
authorÉric Araujo <merwok@netwok.org>
Fri, 2 Sep 2011 22:47:07 +0000 (00:47 +0200)
committerÉric Araujo <merwok@netwok.org>
Fri, 2 Sep 2011 22:47:07 +0000 (00:47 +0200)
sdist used to crash with a full traceback dump instead of printing a
nice warning with the faulty line number.

Lib/distutils/command/sdist.py
Lib/distutils/tests/test_sdist.py
Misc/NEWS

index 75950f3d1874699347b59b299e6300571d38c8cf..d30de10673c9e024c26c3c0450377e32a7c93462 100644 (file)
@@ -320,7 +320,10 @@ class sdist(Command):
 
                 try:
                     self.filelist.process_template_line(line)
-                except DistutilsTemplateError, msg:
+                # the call above can raise a DistutilsTemplateError for
+                # malformed lines, or a ValueError from the lower-level
+                # convert_path function
+                except (DistutilsTemplateError, ValueError) as msg:
                     self.warn("%s, line %d: %s" % (template.filename,
                                                    template.current_line,
                                                    msg))
index 5134e6aba254f5ff1074e8ba7ac216dd36ca7f2d..33f6ee69a901a94c5eee48d37a31a3afe5ae030a 100644 (file)
@@ -29,6 +29,7 @@ from distutils.tests.test_config import PyPIRCCommandTestCase
 from distutils.errors import DistutilsOptionError
 from distutils.spawn import find_executable
 from distutils.log import WARN
+from distutils.filelist import FileList
 from distutils.archive_util import ARCHIVE_FORMATS
 
 SETUP_PY = """
@@ -272,7 +273,6 @@ class SDistTestCase(PyPIRCCommandTestCase):
         self.assertEqual(len(output), num_formats)
 
     def test_finalize_options(self):
-
         dist, cmd = self.get_cmd()
         cmd.finalize_options()
 
@@ -342,6 +342,32 @@ class SDistTestCase(PyPIRCCommandTestCase):
         finally:
             archive.close()
 
+    # the following tests make sure there is a nice error message instead
+    # of a traceback when parsing an invalid manifest template
+
+    def _test_template(self, content):
+        dist, cmd = self.get_cmd()
+        os.chdir(self.tmp_dir)
+        self.write_file('MANIFEST.in', content)
+        cmd.ensure_finalized()
+        cmd.filelist = FileList()
+        cmd.read_template()
+        warnings = self.get_logs(WARN)
+        self.assertEqual(len(warnings), 1)
+
+    def test_invalid_template_unknown_command(self):
+        self._test_template('taunt knights *')
+
+    def test_invalid_template_wrong_arguments(self):
+        # this manifest command takes one argument
+        self._test_template('prune')
+
+    @unittest.skipIf(os.name != 'nt', 'test relevant for Windows only')
+    def test_invalid_template_wrong_path(self):
+        # on Windows, trailing slashes are not allowed
+        # this used to crash instead of raising a warning: #8286
+        self._test_template('include examples/')
+
     @unittest.skipUnless(zlib, "requires zlib")
     def test_get_file_list(self):
         # make sure MANIFEST is recalculated
index 8c77c9f91fb88a4aeb2f80472fadd2be200f0ce7..0778cad15fe6684726c83ca15b1746d3ca78f3c2 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -40,6 +40,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #8286: The distutils command sdist will print a warning message instead
+  of crashing when an invalid path is given in the manifest template.
+
 - Issue #10946: The distutils commands bdist_dumb, bdist_wininst and bdist_msi
   now respect a --skip-build option given to bdist.