77
77
import os
78
78
import sys
79
79
from pathlib import Path
80
+ from functools import partial
80
81
81
82
import sphinx .ext .intersphinx
82
83
@@ -156,20 +157,20 @@ def help_examples(s=""):
156
157
return s
157
158
158
159
159
- def help_documents ():
160
+ def help_documents (parser , args ):
160
161
"""
161
162
Append and return a tabular list of documents, including a
162
163
shortcut 'all' for all documents, available to the Sage
163
164
documentation builder.
164
165
"""
165
- docs = get_documents ()
166
+ args .source_dir = preprocess_source_dir (parser , args .source_dir )
167
+ docs = [str (p ) for p in get_all_documents (args .source_dir )]
166
168
s = "DOCUMENTs:\n "
167
169
s += format_columns (docs )
168
170
s += "\n "
169
- if 'reference' in docs :
170
- s += "Other valid document names take the form 'reference/DIR', where\n "
171
- s += "DIR is a subdirectory of src/doc/en/reference/.\n "
172
- s += "This builds just the specified part of the reference manual.\n "
171
+ s += "Other valid document names take the form 'en/reference/DIR', where\n "
172
+ s += "DIR is a subdirectory of src/doc/en/reference/.\n "
173
+ s += "This builds just the specified part of the reference manual.\n "
173
174
s += "DOCUMENT may also have the form 'file=/path/to/FILE', which builds\n "
174
175
s += "the documentation for the specified file.\n "
175
176
return s
@@ -220,7 +221,7 @@ class help_message_long(argparse.Action):
220
221
and exits.
221
222
"""
222
223
def __call__ (self , parser , namespace , values , option_string = None ):
223
- help_funcs = [help_usage , help_description , help_documents ,
224
+ help_funcs = [help_usage , help_description , functools . partial ( help_documents , parser , namespace ) ,
224
225
help_formats , help_commands ]
225
226
for f in help_funcs :
226
227
print (f ())
@@ -253,7 +254,7 @@ class help_wrapper(argparse.Action):
253
254
"""
254
255
def __call__ (self , parser , namespace , values , option_string = None ):
255
256
if option_string in ['-D' , '--documents' ]:
256
- print (help_documents (), end = "" )
257
+ print (help_documents (parser , namespace ), end = "" )
257
258
if option_string in ['-F' , '--formats' ]:
258
259
print (help_formats (), end = "" )
259
260
if self .dest == 'commands' :
@@ -262,6 +263,15 @@ def __call__(self, parser, namespace, values, option_string=None):
262
263
sys .exit (0 )
263
264
264
265
266
+ def preprocess_source_dir (parser , val ):
267
+ if val is None :
268
+ val = Path (os .environ .get ('SAGE_DOC_SRC' , 'src/doc' ))
269
+ p = val .absolute ()
270
+ if not p .is_dir ():
271
+ parser .error (f"Source directory { p } does not exist." )
272
+ return p
273
+
274
+
265
275
def setup_parser ():
266
276
"""
267
277
Set up and return a command-line ArgumentParser instance for the
@@ -453,13 +463,6 @@ def main():
453
463
parser = setup_parser ()
454
464
args : BuildOptions = parser .parse_args () # type: ignore
455
465
456
- # Check that the docs source directory exists
457
- if args .source_dir is None :
458
- args .source_dir = Path (os .environ .get ('SAGE_DOC_SRC' , 'src/doc' ))
459
- args .source_dir = args .source_dir .absolute ()
460
- if not args .source_dir .is_dir ():
461
- parser .error (f"Source directory { args .source_dir } does not exist." )
462
-
463
466
if args .all_documents :
464
467
if args .all_documents == 'reference' :
465
468
docs = get_all_reference_documents (args .source_dir / 'en' )
0 commit comments