13
13
"""
14
14
import argparse
15
15
import csv
16
+ import docutils .frontend
17
+ import docutils .nodes
16
18
import importlib
17
19
import os
18
20
import shutil
21
23
import webbrowser
22
24
23
25
import docutils
26
+ import docutils .utils
24
27
import docutils .parsers .rst
25
28
26
29
DOC_PATH = os .path .dirname (os .path .abspath (__file__ ))
@@ -288,9 +291,27 @@ def zip_html(self):
288
291
os .chdir (dirname )
289
292
self ._run_os ("zip" , zip_fname , "-r" , "-q" , * fnames )
290
293
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
+
291
311
292
312
def main ():
293
313
cmds = [method for method in dir (DocBuilder ) if not method .startswith ("_" )]
314
+ cmds .append ("linkcheck" ) # Add linkcheck to the available commands
294
315
295
316
joined = "," .join (cmds )
296
317
argparser = argparse .ArgumentParser (
@@ -349,6 +370,7 @@ def main():
349
370
joined = ", " .join (cmds )
350
371
raise ValueError (f"Unknown command { args .command } . Available options: { joined } " )
351
372
373
+
352
374
# Below we update both os.environ and sys.path. The former is used by
353
375
# external libraries (namely Sphinx) to compile this module and resolve
354
376
# the import of `python_path` correctly. The latter is used to resolve
@@ -369,8 +391,11 @@ def main():
369
391
args .verbosity ,
370
392
args .warnings_are_errors ,
371
393
)
372
- return getattr (builder , args .command )()
373
-
374
394
395
+ if args .command == "linkcheck" :
396
+ builder ._linkcheck () # Call the linkcheck method
397
+ else :
398
+ return getattr (builder , args .command )()
399
+
375
400
if __name__ == "__main__" :
376
401
sys .exit (main ())
0 commit comments