Skip to content

Commit 1e8a354

Browse files
committed
ENH: Implement sphinx quickstart subcommand
`sphinx quickstart` is now equivalent to `sphinx-quickstart` A first step towards #5618.
1 parent de745a9 commit 1e8a354

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

sphinx/_cli/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class _SubcommandModule(Protocol):
5252

5353

5454
# Map of command name to import path.
55-
_COMMANDS: dict[str, str] = {}
55+
_COMMANDS: dict[str, str] = {'quickstart': 'sphinx.cmd._quickstart'}
5656

5757

5858
def _load_subcommand_descriptions() -> Iterator[tuple[str, str]]:

sphinx/cmd/_quickstart.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
The module implementing the subcommand ``sphinx quickstart``.
3+
4+
This delegates everything to the module :mod:`sphinx.cmd.quickstart`, which
5+
is the implementation for the historic standalone ``sphinx-quickstart`` command.
6+
"""
7+
8+
import argparse
9+
10+
from . import quickstart
11+
12+
13+
parser_description = quickstart.COMMAND_DESCRIPTION.lstrip()
14+
15+
16+
def set_up_parser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:
17+
return quickstart.set_up_parser(parser)
18+
19+
20+
def run(args: argparse.Namespace) -> int:
21+
return quickstart.run(args)

sphinx/cmd/quickstart.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@
4848
else:
4949
readline.parse_and_bind('tab: complete')
5050

51+
COMMAND_DESCRIPTION = __(
52+
'\n'
53+
'Generate required files for a Sphinx project.\n'
54+
'\n'
55+
'sphinx-quickstart is an interactive tool that asks some questions about your\n'
56+
'project and then generates a complete documentation directory and sample\n'
57+
'Makefile to be used with sphinx-build.\n',
58+
)
59+
5160
EXTENSIONS = {
5261
'autodoc': __('automatically insert docstrings from modules'),
5362
'doctest': __('automatically test code snippets in doctest blocks'),
@@ -569,20 +578,15 @@ def valid_dir(d: dict[str, Any]) -> bool:
569578

570579

571580
def get_parser() -> argparse.ArgumentParser:
572-
description = __(
573-
'\n'
574-
'Generate required files for a Sphinx project.\n'
575-
'\n'
576-
'sphinx-quickstart is an interactive tool that asks some questions about your\n'
577-
'project and then generates a complete documentation directory and sample\n'
578-
'Makefile to be used with sphinx-build.\n',
579-
)
580581
parser = argparse.ArgumentParser(
581582
usage='%(prog)s [OPTIONS] <PROJECT_DIR>',
582583
epilog=__('For more information, visit <https://www.sphinx-doc.org/>.'),
583-
description=description,
584+
description=str(COMMAND_DESCRIPTION), # str() for resolving TranslationProxy
584585
)
586+
return set_up_parser(parser)
585587

588+
589+
def set_up_parser(parser: argparse.ArgumentParser) -> None:
586590
parser.add_argument(
587591
'-q',
588592
'--quiet',
@@ -748,6 +752,10 @@ def main(argv: Sequence[str] = (), /) -> int:
748752
except SystemExit as err:
749753
return err.code # type: ignore[return-value]
750754

755+
return run(args)
756+
757+
758+
def run(args: Namespace) -> int:
751759
d = vars(args)
752760
# delete None or False value
753761
d = {k: v for k, v in d.items() if v is not None}

0 commit comments

Comments
 (0)