sphinx-argparse-neo¶
Modern Sphinx extension for documenting argparse CLIs. The base package
registers the argparse directive plus renderer config values; the
sphinx_argparse_neo.exemplar layer adds example extraction, lexers, and CLI
inline roles.
$ pip install sphinx-argparse-neo
Downstream conf.py¶
extensions = [
"sphinx_argparse_neo",
"sphinx_argparse_neo.exemplar",
]
argparse_examples_section_title = "Examples"
argparse_reorder_usage_before_examples = True
Live directive demos¶
Base parser rendering¶
Example CLI showing how sphinx-argparse-neo renders parsers.
Usage¶
usage: myapp [-h] [--verbose] [--config PATH] {mysubcommand,myothersubcommand} ...
Options¶
Subcommand rendering¶
Drill into a single subcommand with :path::
Execute the primary task with configurable output.
Usage¶
usage: myapp mysubcommand [-h] [--output DIR] [--format {text,json}] [--clean]
Options¶
Inline roles¶
The exemplar layer also registers live inline roles for CLI prose:
myapp, --verbose, json,
DIR, and text.
Configuration values¶
Base extension¶
Config Value Index
Name |
Type |
Default |
Rebuild |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- argparse_group_title_prefix¶
- Type:
str- Default:
''
Prefix for argument group titles
Registered by
sphinx_argparse_neo.setup().Rebuild:
html.
- argparse_show_defaults¶
- Type:
bool- Default:
True
Show default values in argument docs
Registered by
sphinx_argparse_neo.setup().Rebuild:
html.
- argparse_show_choices¶
- Type:
bool- Default:
True
Show choice constraints
Registered by
sphinx_argparse_neo.setup().Rebuild:
html.
- argparse_show_types¶
- Type:
bool- Default:
True
Show type information
Registered by
sphinx_argparse_neo.setup().Rebuild:
html.
Exemplar layer¶
Config Value Index
Name |
Type |
Default |
Rebuild |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- argparse_examples_term_suffix¶
- Type:
str- Default:
'examples'
Term suffix for detecting example definition lists
Registered by
sphinx_argparse_neo.exemplar.setup().Rebuild:
html.
- argparse_examples_base_term¶
- Type:
str- Default:
'examples'
Base term for matching example sections
Registered by
sphinx_argparse_neo.exemplar.setup().Rebuild:
html.
- argparse_examples_section_title¶
- Type:
str- Default:
'Examples'
Section title for extracted examples
Registered by
sphinx_argparse_neo.exemplar.setup().Rebuild:
html.
- argparse_usage_pattern¶
- Type:
str- Default:
'usage:'
Pattern to detect usage blocks in epilog text
Registered by
sphinx_argparse_neo.exemplar.setup().Rebuild:
html.
- argparse_examples_command_prefix¶
- Type:
str- Default:
'$ '
Prefix for example commands in code blocks
Registered by
sphinx_argparse_neo.exemplar.setup().Rebuild:
html.
- argparse_examples_code_language¶
- Type:
str- Default:
'console'
Language for example code blocks
Registered by
sphinx_argparse_neo.exemplar.setup().Rebuild:
html.
- argparse_examples_code_classes¶
- Type:
list- Default:
['highlight-console']
CSS classes for example code blocks
Registered by
sphinx_argparse_neo.exemplar.setup().Rebuild:
html.
- argparse_usage_code_language¶
- Type:
str- Default:
'cli-usage'
Language for usage code blocks
Registered by
sphinx_argparse_neo.exemplar.setup().Rebuild:
html.
- argparse_reorder_usage_before_examples¶
- Type:
bool- Default:
True
Move usage sections before examples sections
Registered by
sphinx_argparse_neo.exemplar.setup().Rebuild:
html.
Registered directives and roles¶
Base argparse directive¶
- .. argparse::
Sphinx directive for documenting argparse-based CLI tools.
Python path:
sphinx_argparse_neo.directive.ArgparseDirectiveRequired arguments:
0Optional arguments:
0Final argument whitespace:
FalseHas content:
TrueOptions:
- :func:
Validator:
unchanged_required.
- :mock-modules:
Validator:
unchanged.
- :module:
Validator:
unchanged_required.
- :no-choices:
Validator:
flag.
- :no-defaults:
Validator:
flag.
- :no-description:
Validator:
flag.
- :no-epilog:
Validator:
flag.
- :no-types:
Validator:
flag.
- :nodefault:
Validator:
flag.
- :nodescription:
Validator:
flag.
- :noepilog:
Validator:
flag.
- :nosubcommands:
Validator:
flag.
- :path:
Validator:
unchanged.
- :prog:
Validator:
unchanged.
Exemplar override¶
- .. cleanargparse::¶
ArgParse directive that strips ANSI codes and formats examples.
Python path:
sphinx_argparse_neo.exemplar.CleanArgParseDirectiveRequired arguments:
0Optional arguments:
0Final argument whitespace:
FalseHas content:
TrueOptions:
- :func:¶
Validator:
unchanged_required.
- :mock-modules:¶
Validator:
unchanged.
- :module:¶
Validator:
unchanged_required.
- :no-choices:¶
Validator:
flag.
- :no-defaults:¶
Validator:
flag.
- :no-description:¶
Validator:
flag.
- :no-epilog:¶
Validator:
flag.
- :no-types:¶
Validator:
flag.
- :nodefault:¶
Validator:
flag.
- :nodescription:¶
Validator:
flag.
- :noepilog:¶
Validator:
flag.
- :nosubcommands:¶
Validator:
flag.
- :path:¶
Validator:
unchanged.
- :prog:¶
Validator:
unchanged.
CLI role callables¶
Role Index
Name |
Python path |
Summary |
|---|---|---|
|
|
Role for CLI choice values like json or yaml. |
|
|
Role for CLI command names like sync or add. |
|
|
Role for CLI default values like None or “default”. |
|
|
Role for CLI metavar placeholders like FILE or PATH. |
|
|
Role for CLI options like –foo or -h. |
- :cli-choice:¶
Role for CLI choice values like json or yaml.
Python path:
sphinx_argparse_neo.roles.cli_choice_roleOptions:
class:class_option
- :cli-command:¶
Role for CLI command names like sync or add.
Python path:
sphinx_argparse_neo.roles.cli_command_roleOptions:
class:class_option
- :cli-default:¶
Role for CLI default values like None or “default”.
Python path:
sphinx_argparse_neo.roles.cli_default_roleOptions:
class:class_option
- :cli-metavar:¶
Role for CLI metavar placeholders like FILE or PATH.
Python path:
sphinx_argparse_neo.roles.cli_metavar_roleOptions:
class:class_option
- :cli-option:¶
Role for CLI options like –foo or -h.
Python path:
sphinx_argparse_neo.roles.cli_option_roleOptions:
class:class_option
Downstream usage snippets¶
Use native MyST directives in Markdown:
```{argparse}
:module: myproject.cli
:func: create_parser
:prog: myproject
```
Or reStructuredText:
.. argparse::
:module: myproject.cli
:func: create_parser
:prog: myproject
Copyable config snippet
extensions = [
"sphinx_argparse_neo",
"sphinx_argparse_neo.exemplar",
]
Package metadata
Source on GitHub: sphinx-argparse-neo
PyPI: sphinx-argparse-neo
Maturity:
Beta
Registered Surface
sphinx_argparse_neo
Config values
Name |
Default |
Rebuild |
Types |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Directives
Name |
Kind |
Callable |
Summary |
|---|---|---|---|
|
directive |
Sphinx directive for documenting argparse-based CLI tools. |
argparse options
Option |
|
|---|---|
|
Registered option |
|
Registered option |
|
Registered option |
|
Registered option |
|
Registered option |
|
Registered option |
|
Registered option |
|
Registered option |
|
Registered option |
|
Registered option |
|
Registered option |
|
Registered option |
|
Registered option |
|
Registered option |
sphinx_argparse_neo.exemplar
Config values
Name |
Default |
Rebuild |
Types |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Directives
Name |
Kind |
Callable |
Summary |
|---|---|---|---|
|
directive |
ArgParse directive that strips ANSI codes and formats examples. |
argparse options
Option |
|
|---|---|
|
Registered option |
|
Registered option |
|
Registered option |
|
Registered option |
|
Registered option |
|
Registered option |
|
Registered option |
|
Registered option |
|
Registered option |
|
Registered option |
|
Registered option |
|
Registered option |
|
Registered option |
|
Registered option |
Roles
Name |
Kind |
Callable |
Summary |
|---|---|---|---|
|
docutils role |
Role for CLI options like –foo or -h. |
|
|
docutils role |
Role for CLI metavar placeholders like FILE or PATH. |
|
|
docutils role |
Role for CLI command names like sync or add. |
|
|
docutils role |
Role for CLI default values like None or “default”. |
|
|
docutils role |
Role for CLI choice values like json or yaml. |
Lexers
Name |
Callable |
|---|---|
|
|
|
|
|
|
|