Skip to content

Commit 7f73d37

Browse files
committed
Various fixes for Sphinx doc builds
1 parent d5ccdb4 commit 7f73d37

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

setup.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,25 +130,23 @@ def run(self):
130130
class _StringPrefixFixer(_OutputChecker):
131131

132132
def check_output(self, want, got, optionflags):
133-
if sys.version_info[0] >= 3:
134-
# The docstrings are written with python 2.x in mind.
135-
# To make the doctests pass in python 3 we have to
136-
# strip the 'u' prefix from the expected results. The
137-
# actual results won't have that prefix.
138-
want = re.sub(_u_literal_re, r'\1\2', want)
139-
# We also have to strip the 'b' prefix from the actual
140-
# results since python 2.x expected results won't have
141-
# that prefix.
142-
got = re.sub(_b_literal_re, r'\1\2', got)
133+
# The docstrings are written with python 2.x in mind.
134+
# To make the doctests pass in python 3 we have to
135+
# strip the 'u' prefix from the expected results. The
136+
# actual results won't have that prefix.
137+
want = re.sub(_u_literal_re, r'\1\2', want)
138+
# We also have to strip the 'b' prefix from the actual
139+
# results since python 2.x expected results won't have
140+
# that prefix.
141+
got = re.sub(_b_literal_re, r'\1\2', got)
143142
return super(
144143
_StringPrefixFixer, self).check_output(
145144
want, got, optionflags)
146145

147146
def output_difference(self, example, got, optionflags):
148-
if sys.version_info[0] >= 3:
149-
example.want = re.sub(
150-
_u_literal_re, r'\1\2', example.want)
151-
got = re.sub(_b_literal_re, r'\1\2', got)
147+
example.want = re.sub(
148+
_u_literal_re, r'\1\2', example.want)
149+
got = re.sub(_b_literal_re, r'\1\2', got)
152150
return super(
153151
_StringPrefixFixer, self).output_difference(
154152
example, got, optionflags)
@@ -159,18 +157,28 @@ def output_difference(self, example, got, optionflags):
159157
build_py.run(self)
160158

161159
if self.test:
162-
path = "doc/_build/doctest"
160+
path = os.path.join(
161+
os.path.abspath('.'), "doc", "_build", "doctest")
163162
mode = "doctest"
164163
else:
165-
path = "doc/_build/%s" % version
164+
path = os.path.join(
165+
os.path.abspath('.'), "doc", "_build", version)
166166
mode = "html"
167167

168168
try:
169169
os.makedirs(path)
170170
except:
171171
pass
172172

173-
status = sphinx.main(["-E", "-b", mode, "doc", path])
173+
sphinx_args = ["-E", "-b", mode, "doc", path]
174+
175+
# sphinx.main calls sys.exit when sphinx.build_main exists.
176+
# Call build_main directly so we can check status and print
177+
# the full path to the built docs.
178+
if hasattr(sphinx, 'build_main'):
179+
status = sphinx.build_main(sphinx_args)
180+
else:
181+
status = sphinx.main(sphinx_args)
174182

175183
if status:
176184
raise RuntimeError("documentation step '%s' failed" % (mode,))

0 commit comments

Comments
 (0)