Skip to content

Commit e452977

Browse files
committed
Fix sage --docbuild -D
1 parent 94fe540 commit e452977

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

src/sage/tests/cmdline.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@
153153
sage: out.find("regular expression search through the Sage") >= 0 # optional - sage_spkg
154154
True
155155
156+
sage: (out, err, ret) = check_executable(["sage", "--docbuild", "-D"])
157+
sage: "DOCUMENTs:" in out
158+
True
159+
156160
Basic information about the Sage installation::
157161
158162
sage: (out, err, ret) = check_executable(["sage", "-v"])

src/sage_docbuild/__main__.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import os
7878
import sys
7979
from pathlib import Path
80+
from functools import partial
8081

8182
import sphinx.ext.intersphinx
8283

@@ -156,20 +157,20 @@ def help_examples(s=""):
156157
return s
157158

158159

159-
def help_documents():
160+
def help_documents(parser, args):
160161
"""
161162
Append and return a tabular list of documents, including a
162163
shortcut 'all' for all documents, available to the Sage
163164
documentation builder.
164165
"""
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)]
166168
s = "DOCUMENTs:\n"
167169
s += format_columns(docs)
168170
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"
173174
s += "DOCUMENT may also have the form 'file=/path/to/FILE', which builds\n"
174175
s += "the documentation for the specified file.\n"
175176
return s
@@ -220,7 +221,7 @@ class help_message_long(argparse.Action):
220221
and exits.
221222
"""
222223
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),
224225
help_formats, help_commands]
225226
for f in help_funcs:
226227
print(f())
@@ -253,7 +254,7 @@ class help_wrapper(argparse.Action):
253254
"""
254255
def __call__(self, parser, namespace, values, option_string=None):
255256
if option_string in ['-D', '--documents']:
256-
print(help_documents(), end="")
257+
print(help_documents(parser, namespace), end="")
257258
if option_string in ['-F', '--formats']:
258259
print(help_formats(), end="")
259260
if self.dest == 'commands':
@@ -262,6 +263,15 @@ def __call__(self, parser, namespace, values, option_string=None):
262263
sys.exit(0)
263264

264265

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+
265275
def setup_parser():
266276
"""
267277
Set up and return a command-line ArgumentParser instance for the
@@ -453,13 +463,6 @@ def main():
453463
parser = setup_parser()
454464
args: BuildOptions = parser.parse_args() # type: ignore
455465

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-
463466
if args.all_documents:
464467
if args.all_documents == 'reference':
465468
docs = get_all_reference_documents(args.source_dir / 'en')

0 commit comments

Comments
 (0)