Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d5a5a33

Browse files
flying-sheepcsabella
authored andcommitted
bpo-31292: Fixed distutils check --restructuredtext for include directives (GH-10605)
1 parent a694f23 commit d5a5a33

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
@@ -120,7 +120,8 @@ def check_restructuredtext(self):
120120

121121
def _check_rst_data(self, data):
122122
"""Returns warnings when the provided data doesn't compile."""
123-
source_path = StringIO()
123+
# the include and csv_table directives need this to be a path
124+
source_path = self.distribution.script_name or 'setup.py'
124125
parser = Parser()
125126
settings = frontend.OptionParser(components=(Parser,)).get_default_values()
126127
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,4 +1,5 @@
11
"""Tests for distutils.command.check."""
2+
import os
23
import textwrap
34
import unittest
45
from test.support import run_unittest
@@ -13,20 +14,28 @@
1314
pygments = None
1415

1516

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

20-
def _run(self, metadata=None, **options):
24+
def _run(self, metadata=None, cwd=None, **options):
2125
if metadata is None:
2226
metadata = {}
27+
if cwd is not None:
28+
old_dir = os.getcwd()
29+
os.chdir(cwd)
2330
pkg_info, dist = self.create_dist(**metadata)
2431
cmd = check(dist)
2532
cmd.initialize_options()
2633
for name, value in options.items():
2734
setattr(cmd, name, value)
2835
cmd.ensure_finalized()
2936
cmd.run()
37+
if cwd is not None:
38+
os.chdir(old_dir)
3039
return cmd
3140

3241
def test_check_metadata(self):
@@ -99,6 +108,11 @@ def test_check_restructuredtext(self):
99108
cmd = self._run(metadata, strict=1, restructuredtext=1)
100109
self.assertEqual(cmd._warnings, 0)
101110

111+
# check that includes work to test #31292
112+
metadata['long_description'] = 'title\n=====\n\n.. include:: includetest.rst'
113+
cmd = self._run(metadata, cwd=HERE, strict=1, restructuredtext=1)
114+
self.assertEqual(cmd._warnings, 0)
115+
102116
@unittest.skipUnless(HAS_DOCUTILS, "won't test without docutils")
103117
def test_check_restructuredtext_with_syntax_highlight(self):
104118
# 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)