[Python-checkins] bpo-31292: Fixed distutils check --restructuredtext for include directives (GH-10605)

Miss Islington (bot) webhook-mailer at python.org
Wed Mar 27 18:23:23 EDT 2019


https://github.com/python/cpython/commit/600aca47f085a06579e7af4c6423ea7e907b4bb4
commit: 600aca47f085a06579e7af4c6423ea7e907b4bb4
branch: 2.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-03-27T15:23:19-07:00
summary:

bpo-31292: Fixed distutils check --restructuredtext for include directives (GH-10605)

(cherry picked from commit d5a5a33f12b60129d57f9b423b77d2fcba506834)

Co-authored-by: Philipp A <flying-sheep at web.de>

files:
A Lib/distutils/tests/includetest.rst
A Misc/NEWS.d/next/Library/2017-08-30-20-27-00.bpo-31292.dKIaZb.rst
M Lib/distutils/command/check.py
M Lib/distutils/tests/test_check.py

diff --git a/Lib/distutils/command/check.py b/Lib/distutils/command/check.py
index 4ea03d303490..fc7db527b97a 100644
--- a/Lib/distutils/command/check.py
+++ b/Lib/distutils/command/check.py
@@ -124,7 +124,8 @@ def check_restructuredtext(self):
 
     def _check_rst_data(self, data):
         """Returns warnings when the provided data doesn't compile."""
-        source_path = StringIO()
+        # the include and csv_table directives need this to be a path
+        source_path = self.distribution.script_name or 'setup.py'
         parser = Parser()
         settings = frontend.OptionParser(components=(Parser,)).get_default_values()
         settings.tab_width = 4
diff --git a/Lib/distutils/tests/includetest.rst b/Lib/distutils/tests/includetest.rst
new file mode 100644
index 000000000000..d7b4ae38b09d
--- /dev/null
+++ b/Lib/distutils/tests/includetest.rst
@@ -0,0 +1 @@
+This should be included.
diff --git a/Lib/distutils/tests/test_check.py b/Lib/distutils/tests/test_check.py
index e94647ffa4a7..2e2cf131e076 100644
--- a/Lib/distutils/tests/test_check.py
+++ b/Lib/distutils/tests/test_check.py
@@ -1,5 +1,6 @@
 # -*- encoding: utf8 -*-
 """Tests for distutils.command.check."""
+import os
 import textwrap
 import unittest
 from test.test_support import run_unittest
@@ -14,13 +15,19 @@
     pygments = None
 
 
+HERE = os.path.dirname(__file__)
+
+
 class CheckTestCase(support.LoggingSilencer,
                     support.TempdirManager,
                     unittest.TestCase):
 
-    def _run(self, metadata=None, **options):
+    def _run(self, metadata=None, cwd=None, **options):
         if metadata is None:
             metadata = {}
+        if cwd is not None:
+            old_dir = os.getcwd()
+            os.chdir(cwd)
         pkg_info, dist = self.create_dist(**metadata)
         cmd = check(dist)
         cmd.initialize_options()
@@ -28,6 +35,8 @@ def _run(self, metadata=None, **options):
             setattr(cmd, name, value)
         cmd.ensure_finalized()
         cmd.run()
+        if cwd is not None:
+            os.chdir(old_dir)
         return cmd
 
     def test_check_metadata(self):
@@ -100,6 +109,11 @@ def test_check_restructuredtext(self):
         cmd = self._run(metadata, strict=1, restructuredtext=1)
         self.assertEqual(cmd._warnings, 0)
 
+        # check that includes work to test #31292
+        metadata['long_description'] = 'title\n=====\n\n.. include:: includetest.rst'
+        cmd = self._run(metadata, cwd=HERE, 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
diff --git a/Misc/NEWS.d/next/Library/2017-08-30-20-27-00.bpo-31292.dKIaZb.rst b/Misc/NEWS.d/next/Library/2017-08-30-20-27-00.bpo-31292.dKIaZb.rst
new file mode 100644
index 000000000000..b62eee3c5ee4
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2017-08-30-20-27-00.bpo-31292.dKIaZb.rst
@@ -0,0 +1,2 @@
+Fix ``setup.py check --restructuredtext`` for
+files containing ``include`` directives.



More information about the Python-checkins mailing list