diff --git a/Lib/distutils/command/check.py b/Lib/distutils/command/check.py index 7ebe707cff4963..ff2074902461d2 100644 --- a/Lib/distutils/command/check.py +++ b/Lib/distutils/command/check.py @@ -120,7 +120,7 @@ def check_restructuredtext(self): def _check_rst_data(self, data): """Returns warnings when the provided data doesn't compile.""" - source_path = StringIO() + source_path = self.distribution.script_name or 'setup.py' parser = Parser() settings = frontend.OptionParser(components=(Parser,)).get_default_values() settings.tab_width = 4 @@ -135,6 +135,7 @@ def _check_rst_data(self, data): error_handler=settings.error_encoding_error_handler) document = nodes.document(settings, reporter, source=source_path) + # the include and csv_table directives need this to be a path document.note_source(source_path, -1) try: parser.parse(data, document) diff --git a/Lib/distutils/tests/includetest.rst b/Lib/distutils/tests/includetest.rst new file mode 100644 index 00000000000000..d7b4ae38b09d86 --- /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 3d22868e313be7..7bafd0ed14144d 100644 --- a/Lib/distutils/tests/test_check.py +++ b/Lib/distutils/tests/test_check.py @@ -1,6 +1,7 @@ """Tests for distutils.command.check.""" import textwrap import unittest +from pathlib import Path from test.support import run_unittest from distutils.command.check import check, HAS_DOCUTILS @@ -13,6 +14,10 @@ pygments = None +HERE = Path(__file__).parent +INCLUDE_TEST_PATH = (HERE / 'includetest.rst').relative_to(Path.cwd()) + + class CheckTestCase(support.LoggingSilencer, support.TempdirManager, unittest.TestCase): @@ -99,6 +104,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:: {}'.format(INCLUDE_TEST_PATH) + 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 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 00000000000000..60c232af449de5 --- /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.