From 41beaf4f4e67fb784bde73c992dbfe845a0a95d2 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Wed, 30 Aug 2017 19:41:14 +0200 Subject: [PATCH 1/6] bpo-31292: Fixed distutils check --restructuredtext for include directives --- Lib/distutils/command/check.py | 4 ++-- Lib/distutils/tests/test_check.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Lib/distutils/command/check.py b/Lib/distutils/command/check.py index 7ebe707cff4963..744e5f282c91bd 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 'long_description' parser = Parser() settings = frontend.OptionParser(components=(Parser,)).get_default_values() settings.tab_width = 4 @@ -135,7 +135,7 @@ def _check_rst_data(self, data): error_handler=settings.error_encoding_error_handler) document = nodes.document(settings, reporter, source=source_path) - document.note_source(source_path, -1) + document.note_source(StringIO(), -1) try: parser.parse(data, document) except AttributeError as e: diff --git a/Lib/distutils/tests/test_check.py b/Lib/distutils/tests/test_check.py index 3d22868e313be7..a11c4ff9b173e1 100644 --- a/Lib/distutils/tests/test_check.py +++ b/Lib/distutils/tests/test_check.py @@ -1,4 +1,5 @@ """Tests for distutils.command.check.""" +import os import textwrap import unittest from test.support import run_unittest @@ -99,6 +100,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'] = f'title\n=====\n\n.. include:: {os.devnull}' + 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 From cb0c3e5e45646e8b308aba0c3e54f9b4552138c5 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Wed, 30 Aug 2017 20:07:12 +0200 Subject: [PATCH 2/6] switched away from f-literal --- Lib/distutils/tests/test_check.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/distutils/tests/test_check.py b/Lib/distutils/tests/test_check.py index a11c4ff9b173e1..9fa98ce285c325 100644 --- a/Lib/distutils/tests/test_check.py +++ b/Lib/distutils/tests/test_check.py @@ -101,7 +101,7 @@ def test_check_restructuredtext(self): self.assertEqual(cmd._warnings, 0) # check that includes work to test #31292 - metadata['long_description'] = f'title\n=====\n\n.. include:: {os.devnull}' + metadata['long_description'] = 'title\n=====\n\n.. include:: ' + os.devnull cmd = self._run(metadata, strict=1, restructuredtext=1) self.assertEqual(cmd._warnings, 0) From 9de80f5eb3df76a886141b7e4363be4851496420 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Wed, 30 Aug 2017 20:15:55 +0200 Subject: [PATCH 3/6] use source_path also for note_source() --- Lib/distutils/command/check.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/distutils/command/check.py b/Lib/distutils/command/check.py index 744e5f282c91bd..ba763c31ffe36c 100644 --- a/Lib/distutils/command/check.py +++ b/Lib/distutils/command/check.py @@ -135,7 +135,7 @@ def _check_rst_data(self, data): error_handler=settings.error_encoding_error_handler) document = nodes.document(settings, reporter, source=source_path) - document.note_source(StringIO(), -1) + document.note_source(source_path, -1) try: parser.parse(data, document) except AttributeError as e: From 51e34b5743f26113141d2c1f7b9f3fd3fa059c88 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Wed, 30 Aug 2017 20:19:42 +0200 Subject: [PATCH 4/6] Use consensus format for source_desc --- Lib/distutils/command/check.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/distutils/command/check.py b/Lib/distutils/command/check.py index ba763c31ffe36c..936d9dbffba671 100644 --- a/Lib/distutils/command/check.py +++ b/Lib/distutils/command/check.py @@ -120,13 +120,13 @@ def check_restructuredtext(self): def _check_rst_data(self, data): """Returns warnings when the provided data doesn't compile.""" - source_path = self.distribution.script_name or 'long_description' + source_desc = '{} (long_description)'.format(self.distribution.script_name or 'distutils') parser = Parser() settings = frontend.OptionParser(components=(Parser,)).get_default_values() settings.tab_width = 4 settings.pep_references = None settings.rfc_references = None - reporter = SilentReporter(source_path, + reporter = SilentReporter(source_desc, settings.report_level, settings.halt_level, stream=settings.warning_stream, @@ -134,8 +134,8 @@ def _check_rst_data(self, data): encoding=settings.error_encoding, error_handler=settings.error_encoding_error_handler) - document = nodes.document(settings, reporter, source=source_path) - document.note_source(source_path, -1) + document = nodes.document(settings, reporter, source=source_desc) + document.note_source(source_desc, -1) try: parser.parse(data, document) except AttributeError as e: From c011a69ae4956c38b128c8b13cb74625cbf1d594 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Wed, 30 Aug 2017 20:27:37 +0200 Subject: [PATCH 5/6] added news blurb --- .../next/Library/2017-08-30-20-27-00.bpo-31292.dKIaZb.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2017-08-30-20-27-00.bpo-31292.dKIaZb.rst 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. From 21a00dfadf3112728262f9ab83e707bd89aa4fa9 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Mon, 18 Sep 2017 11:33:36 +0200 Subject: [PATCH 6/6] it needs to be a path after all --- Lib/distutils/command/check.py | 9 +++++---- Lib/distutils/tests/includetest.rst | 1 + Lib/distutils/tests/test_check.py | 8 ++++++-- 3 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 Lib/distutils/tests/includetest.rst diff --git a/Lib/distutils/command/check.py b/Lib/distutils/command/check.py index 936d9dbffba671..ff2074902461d2 100644 --- a/Lib/distutils/command/check.py +++ b/Lib/distutils/command/check.py @@ -120,13 +120,13 @@ def check_restructuredtext(self): def _check_rst_data(self, data): """Returns warnings when the provided data doesn't compile.""" - source_desc = '{} (long_description)'.format(self.distribution.script_name or 'distutils') + source_path = self.distribution.script_name or 'setup.py' parser = Parser() settings = frontend.OptionParser(components=(Parser,)).get_default_values() settings.tab_width = 4 settings.pep_references = None settings.rfc_references = None - reporter = SilentReporter(source_desc, + reporter = SilentReporter(source_path, settings.report_level, settings.halt_level, stream=settings.warning_stream, @@ -134,8 +134,9 @@ def _check_rst_data(self, data): encoding=settings.error_encoding, error_handler=settings.error_encoding_error_handler) - document = nodes.document(settings, reporter, source=source_desc) - document.note_source(source_desc, -1) + 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) except AttributeError as e: 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 9fa98ce285c325..7bafd0ed14144d 100644 --- a/Lib/distutils/tests/test_check.py +++ b/Lib/distutils/tests/test_check.py @@ -1,7 +1,7 @@ """Tests for distutils.command.check.""" -import os import textwrap import unittest +from pathlib import Path from test.support import run_unittest from distutils.command.check import check, HAS_DOCUTILS @@ -14,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): @@ -101,7 +105,7 @@ def test_check_restructuredtext(self): self.assertEqual(cmd._warnings, 0) # check that includes work to test #31292 - metadata['long_description'] = 'title\n=====\n\n.. include:: ' + os.devnull + 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)