]> granicus.if.org Git - python/commitdiff
fix parsing reST with code or code-block directives (closes #23063)
authorBenjamin Peterson <benjamin@python.org>
Thu, 15 Jan 2015 04:56:35 +0000 (23:56 -0500)
committerBenjamin Peterson <benjamin@python.org>
Thu, 15 Jan 2015 04:56:35 +0000 (23:56 -0500)
Patch by Marc Abramowitz.

Lib/distutils/command/check.py
Lib/distutils/tests/test_check.py
Misc/NEWS

index 152bf0de98bf705261dc5b7a3ab9f5ed4ad82652..4ea03d303490753cd231871cb6985776679821fd 100644 (file)
@@ -126,7 +126,7 @@ class check(Command):
         """Returns warnings when the provided data doesn't compile."""
         source_path = StringIO()
         parser = Parser()
-        settings = frontend.OptionParser().get_default_values()
+        settings = frontend.OptionParser(components=(Parser,)).get_default_values()
         settings.tab_width = 4
         settings.pep_references = None
         settings.rfc_references = None
@@ -142,8 +142,8 @@ class check(Command):
         document.note_source(source_path, -1)
         try:
             parser.parse(data, document)
-        except AttributeError:
-            reporter.messages.append((-1, 'Could not finish the parsing.',
-                                      '', {}))
+        except AttributeError as e:
+            reporter.messages.append(
+                (-1, 'Could not finish the parsing: %s.' % e, '', {}))
 
         return reporter.messages
index f86f1292fc59116cbc163425e51fd45c7e9d1e31..81058b1911ee2109042edc8878e02c6a44cd8ec8 100644 (file)
@@ -1,5 +1,6 @@
 # -*- encoding: utf8 -*-
 """Tests for distutils.command.check."""
+import textwrap
 import unittest
 from test.test_support import run_unittest
 
@@ -93,6 +94,36 @@ class CheckTestCase(support.LoggingSilencer,
         cmd = self._run(metadata, strict=1, restructuredtext=1)
         self.assertEqual(cmd._warnings, 0)
 
+    @unittest.skipUnless(HAS_DOCUTILS, "won't test without docutils")
+    def test_check_restructuredtext_with_syntax_highlight(self):
+        # Don't fail if there is a `code` or `code-block` directive
+
+        example_rst_docs = []
+        example_rst_docs.append(textwrap.dedent("""\
+            Here's some code:
+
+            .. code:: python
+
+                def foo():
+                    pass
+            """))
+        example_rst_docs.append(textwrap.dedent("""\
+            Here's some code:
+
+            .. code-block:: python
+
+                def foo():
+                    pass
+            """))
+
+        for rest_with_code in example_rst_docs:
+            pkg_info, dist = self.create_dist(long_description=rest_with_code)
+            cmd = check(dist)
+            cmd.check_restructuredtext()
+            self.assertEqual(cmd._warnings, 0)
+            msgs = cmd._check_rst_data(rest_with_code)
+            self.assertEqual(len(msgs), 0)
+
     def test_check_all(self):
 
         metadata = {'url': 'xxx', 'author': 'xxx'}
index cb90d13c2ec45a0694fa77827060fc3a902096dd..b34d4178ad1a6928c0b52da2a85e53b6090938ea 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -15,6 +15,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #23063: In the disutils' check command, fix parsing of reST with code or
+  code-block directives.
+
 - Issue #21356: Make ssl.RAND_egd() optional to support LibreSSL. The
   availability of the function is checked during the compilation. Patch written
   by Bernard Spil.