Skip to content

Commit 049cdc9

Browse files
authored
Modified doc/make.py to run sphinx-build -b linkcheck
1 parent aa4922a commit 049cdc9

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

doc/make.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
"""
1414
import argparse
1515
import csv
16+
import docutils.frontend
17+
import docutils.nodes
1618
import importlib
1719
import os
1820
import shutil
@@ -21,6 +23,7 @@
2123
import webbrowser
2224

2325
import docutils
26+
import docutils.utils
2427
import docutils.parsers.rst
2528

2629
DOC_PATH = os.path.dirname(os.path.abspath(__file__))
@@ -288,9 +291,27 @@ def zip_html(self):
288291
os.chdir(dirname)
289292
self._run_os("zip", zip_fname, "-r", "-q", *fnames)
290293

294+
def _linkcheck(self):
295+
"""
296+
Check for broken links in the documentation.
297+
"""
298+
cmd = ["sphinx-build", "-b", "linkcheck"]
299+
if self.num_jobs:
300+
cmd += ["-j", self.num_jobs]
301+
if self.verbosity:
302+
cmd.append(f"-{'v' * self.verbosity}")
303+
cmd += [
304+
"-d",
305+
os.path.join(BUILD_PATH, "doctrees"),
306+
SOURCE_PATH,
307+
os.path.join(BUILD_PATH, "linkcheck"),
308+
]
309+
subprocess.call(cmd)
310+
291311

292312
def main():
293313
cmds = [method for method in dir(DocBuilder) if not method.startswith("_")]
314+
cmds.append("linkcheck") # Add linkcheck to the available commands
294315

295316
joined = ",".join(cmds)
296317
argparser = argparse.ArgumentParser(
@@ -349,6 +370,7 @@ def main():
349370
joined = ", ".join(cmds)
350371
raise ValueError(f"Unknown command {args.command}. Available options: {joined}")
351372

373+
352374
# Below we update both os.environ and sys.path. The former is used by
353375
# external libraries (namely Sphinx) to compile this module and resolve
354376
# the import of `python_path` correctly. The latter is used to resolve
@@ -369,8 +391,11 @@ def main():
369391
args.verbosity,
370392
args.warnings_are_errors,
371393
)
372-
return getattr(builder, args.command)()
373-
374394

395+
if args.command == "linkcheck":
396+
builder._linkcheck() # Call the linkcheck method
397+
else:
398+
return getattr(builder, args.command)()
399+
375400
if __name__ == "__main__":
376401
sys.exit(main())

0 commit comments

Comments
 (0)