Skip to content

Commit 600aca4

Browse files
bpo-31292: Fixed distutils check --restructuredtext for include directives (GH-10605)
(cherry picked from commit d5a5a33) Co-authored-by: Philipp A <flying-sheep@web.de>
1 parent 6cbb4c0 commit 600aca4

4 files changed

Lines changed: 20 additions & 2 deletions

File tree

Lib/distutils/command/check.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ def check_restructuredtext(self):
124124

125125
def _check_rst_data(self, data):
126126
"""Returns warnings when the provided data doesn't compile."""
127-
source_path = StringIO()
127+
# the include and csv_table directives need this to be a path
128+
source_path = self.distribution.script_name or 'setup.py'
128129
parser = Parser()
129130
settings = frontend.OptionParser(components=(Parser,)).get_default_values()
130131
settings.tab_width = 4
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This should be included.

Lib/distutils/tests/test_check.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- encoding: utf8 -*-
22
"""Tests for distutils.command.check."""
3+
import os
34
import textwrap
45
import unittest
56
from test.test_support import run_unittest
@@ -14,20 +15,28 @@
1415
pygments = None
1516

1617

18+
HERE = os.path.dirname(__file__)
19+
20+
1721
class CheckTestCase(support.LoggingSilencer,
1822
support.TempdirManager,
1923
unittest.TestCase):
2024

21-
def _run(self, metadata=None, **options):
25+
def _run(self, metadata=None, cwd=None, **options):
2226
if metadata is None:
2327
metadata = {}
28+
if cwd is not None:
29+
old_dir = os.getcwd()
30+
os.chdir(cwd)
2431
pkg_info, dist = self.create_dist(**metadata)
2532
cmd = check(dist)
2633
cmd.initialize_options()
2734
for name, value in options.items():
2835
setattr(cmd, name, value)
2936
cmd.ensure_finalized()
3037
cmd.run()
38+
if cwd is not None:
39+
os.chdir(old_dir)
3140
return cmd
3241

3342
def test_check_metadata(self):
@@ -100,6 +109,11 @@ def test_check_restructuredtext(self):
100109
cmd = self._run(metadata, strict=1, restructuredtext=1)
101110
self.assertEqual(cmd._warnings, 0)
102111

112+
# check that includes work to test #31292
113+
metadata['long_description'] = 'title\n=====\n\n.. include:: includetest.rst'
114+
cmd = self._run(metadata, cwd=HERE, strict=1, restructuredtext=1)
115+
self.assertEqual(cmd._warnings, 0)
116+
103117
@unittest.skipUnless(HAS_DOCUTILS, "won't test without docutils")
104118
def test_check_restructuredtext_with_syntax_highlight(self):
105119
# Don't fail if there is a `code` or `code-block` directive
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix ``setup.py check --restructuredtext`` for
2+
files containing ``include`` directives.

0 commit comments

Comments
 (0)