From 10cf4b59268b173bec9ff7be491d6fb2393b2d2c Mon Sep 17 00:00:00 2001 From: Philipp A Date: Wed, 30 Aug 2017 19:41:14 +0200 Subject: [PATCH 01/10] bpo-31292: Fixed distutils check --restructuredtext for include directives --- Lib/distutils/command/check.py | 3 ++- Lib/distutils/tests/includetest.rst | 1 + Lib/distutils/tests/test_check.py | 10 ++++++++++ .../Library/2017-08-30-20-27-00.bpo-31292.dKIaZb.rst | 2 ++ 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 Lib/distutils/tests/includetest.rst create mode 100644 Misc/NEWS.d/next/Library/2017-08-30-20-27-00.bpo-31292.dKIaZb.rst diff --git a/Lib/distutils/command/check.py b/Lib/distutils/command/check.py index 7ebe707cff4963d..ff2074902461d23 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 000000000000000..d7b4ae38b09d868 --- /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 3d22868e313be78..7bafd0ed14144d3 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 000000000000000..60c232af449de5a --- /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 47c5024e1a9f61f3422f725b3d9e185ca09171d8 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Wed, 21 Nov 2018 14:51:03 +0100 Subject: [PATCH 02/10] Move comment up --- 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 ff2074902461d23..04c2f9642d7334f 100644 --- a/Lib/distutils/command/check.py +++ b/Lib/distutils/command/check.py @@ -120,6 +120,7 @@ def check_restructuredtext(self): def _check_rst_data(self, data): """Returns warnings when the provided data doesn't compile.""" + # 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() @@ -135,7 +136,6 @@ 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) From 8460861b42068c60b11da395d851d92fc2ada9a0 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Wed, 21 Nov 2018 14:58:51 +0100 Subject: [PATCH 03/10] go to right directory --- Lib/distutils/tests/test_check.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/distutils/tests/test_check.py b/Lib/distutils/tests/test_check.py index 7bafd0ed14144d3..c82eb16799e69c7 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 pathlib import Path @@ -15,7 +16,6 @@ HERE = Path(__file__).parent -INCLUDE_TEST_PATH = (HERE / 'includetest.rst').relative_to(Path.cwd()) class CheckTestCase(support.LoggingSilencer, @@ -105,7 +105,8 @@ 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:: {}'.format(INCLUDE_TEST_PATH) + os.chdir(HERE) + metadata['long_description'] = 'title\n=====\n\n.. include:: includetest.rst' cmd = self._run(metadata, strict=1, restructuredtext=1) self.assertEqual(cmd._warnings, 0) From 3892dee74ba0c8cf15601d2cc969b2666078fb36 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Wed, 21 Nov 2018 15:00:42 +0100 Subject: [PATCH 04/10] Use os.path in test --- Lib/distutils/tests/test_check.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/distutils/tests/test_check.py b/Lib/distutils/tests/test_check.py index c82eb16799e69c7..9b2955ae950cfe4 100644 --- a/Lib/distutils/tests/test_check.py +++ b/Lib/distutils/tests/test_check.py @@ -1,8 +1,8 @@ """Tests for distutils.command.check.""" import os +import os.path import textwrap import unittest -from pathlib import Path from test.support import run_unittest from distutils.command.check import check, HAS_DOCUTILS @@ -15,7 +15,7 @@ pygments = None -HERE = Path(__file__).parent +HERE = os.path.dirname(__file__) class CheckTestCase(support.LoggingSilencer, From 38f2187063ad551a943a03d80af5288417706b4c Mon Sep 17 00:00:00 2001 From: Philipp A Date: Wed, 21 Nov 2018 16:06:42 +0100 Subject: [PATCH 05/10] Handle cwd in run --- Lib/distutils/tests/test_check.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Lib/distutils/tests/test_check.py b/Lib/distutils/tests/test_check.py index 9b2955ae950cfe4..e12fa35bf90acc9 100644 --- a/Lib/distutils/tests/test_check.py +++ b/Lib/distutils/tests/test_check.py @@ -22,9 +22,12 @@ 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() @@ -32,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): @@ -105,9 +110,8 @@ def test_check_restructuredtext(self): self.assertEqual(cmd._warnings, 0) # check that includes work to test #31292 - os.chdir(HERE) metadata['long_description'] = 'title\n=====\n\n.. include:: includetest.rst' - cmd = self._run(metadata, strict=1, restructuredtext=1) + cmd = self._run(metadata, cwd=HERE, strict=1, restructuredtext=1) self.assertEqual(cmd._warnings, 0) @unittest.skipUnless(HAS_DOCUTILS, "won't test without docutils") From a398115819c6b162ad1b068191d015c1b6d141a2 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Fri, 11 Jan 2019 10:42:24 +0100 Subject: [PATCH 06/10] =?UTF-8?q?don=E2=80=99t=20import=20os=20separately?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lib/distutils/tests/test_check.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/distutils/tests/test_check.py b/Lib/distutils/tests/test_check.py index e12fa35bf90acc9..89ecba10c29faee 100644 --- a/Lib/distutils/tests/test_check.py +++ b/Lib/distutils/tests/test_check.py @@ -1,5 +1,4 @@ """Tests for distutils.command.check.""" -import os import os.path import textwrap import unittest From 6ad033e5e702a9a9f08a6e1f873e8d456e4ae2e6 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Sat, 12 Jan 2019 13:11:52 +0100 Subject: [PATCH 07/10] Ignore mention of include in NEWS --- Doc/tools/susp-ignored.csv | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/tools/susp-ignored.csv b/Doc/tools/susp-ignored.csv index 3c23dc12e3ad6ed..c5edf1eed4c4b8f 100644 --- a/Doc/tools/susp-ignored.csv +++ b/Doc/tools/susp-ignored.csv @@ -349,3 +349,4 @@ whatsnew/3.7,,::,error::BytesWarning whatsnew/changelog,,::,error::BytesWarning whatsnew/changelog,,::,default::BytesWarning whatsnew/changelog,,::,default::DeprecationWarning +whatsnew/changelog,,.. include:,.. include:: From fe0f1cac7e4ec71108e4c28f08882faeaf5ea850 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Mon, 14 Jan 2019 09:56:42 +0000 Subject: [PATCH 08/10] Go for the other option pt1 --- Doc/tools/susp-ignored.csv | 1 - 1 file changed, 1 deletion(-) diff --git a/Doc/tools/susp-ignored.csv b/Doc/tools/susp-ignored.csv index c5edf1eed4c4b8f..3c23dc12e3ad6ed 100644 --- a/Doc/tools/susp-ignored.csv +++ b/Doc/tools/susp-ignored.csv @@ -349,4 +349,3 @@ whatsnew/3.7,,::,error::BytesWarning whatsnew/changelog,,::,error::BytesWarning whatsnew/changelog,,::,default::BytesWarning whatsnew/changelog,,::,default::DeprecationWarning -whatsnew/changelog,,.. include:,.. include:: From df66fd3dd4e1674288271d7004ae9c747ba5e92f Mon Sep 17 00:00:00 2001 From: Philipp A Date: Mon, 14 Jan 2019 09:57:18 +0000 Subject: [PATCH 09/10] Go for the other option pt2 --- .../next/Library/2017-08-30-20-27-00.bpo-31292.dKIaZb.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 60c232af449de5a..b62eee3c5ee494b 100644 --- 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 @@ -1,2 +1,2 @@ Fix ``setup.py check --restructuredtext`` for -files containing ``.. include::`` directives. +files containing ``include`` directives. From a5fa856adf6c95bf36f9ee03b986ec0acd848acd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Tue, 15 Jan 2019 10:13:46 -0500 Subject: [PATCH 10/10] minor --- 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 89ecba10c29faee..e534aca1d47637c 100644 --- a/Lib/distutils/tests/test_check.py +++ b/Lib/distutils/tests/test_check.py @@ -1,5 +1,5 @@ """Tests for distutils.command.check.""" -import os.path +import os import textwrap import unittest from test.support import run_unittest