Skip to content

Commit e63c3f5

Browse files
committed
Improve markup in documentation
1 parent 56d7e10 commit e63c3f5

10 files changed

+257
-193
lines changed

README.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@
2222
:target: https://opensource.org/licenses/MIT
2323
:alt: MIT
2424

25-
A sphinx extension that automatically documents argparse commands and options.
25+
A Sphinx extension to automatically document argparse_ commands and options.
2626

2727
For installation and usage details see the documentation_.
2828
The changelog is also `found there`_.
2929

30-
This project used to live at `alex-rudakov/sphinx-argparse`_,
31-
and has been revived and moved to this new home.
32-
30+
.. _argparse: https://docs.python.org/3/library/argparse.html
3331
.. _documentation: https://sphinx-argparse.readthedocs.org/
3432
.. _found there: https://sphinx-argparse.readthedocs.org/en/latest/changelog.html
35-
.. _alex-rudakov/sphinx-argparse: https://github.com/alex-rudakov/sphinx-argparse/
33+
34+
.. note::
35+
This project used to live at `alex-rudakov/sphinx-argparse`_,
36+
and has been revived and moved to this `new home`_.
37+
38+
.. _alex-rudakov/sphinx-argparse: https://github.com/alex-rudakov/sphinx-argparse/
39+
.. _new home: https://github.com/sphinx-doc/sphinx-argparse/

docs/changelog.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ Change log
6868
0.2.3
6969
#####
7070

71-
* Fixed a variety of issues, such as with `@replace` (issue #99). Thanks to @evgeni
72-
* You can now skip sections with `@skip`. Thanks to @evgeni
71+
* Fixed a variety of issues, such as with ``@replace`` (issue #99). Thanks to @evgeni
72+
* You can now skip sections with ``@skip``. Thanks to @evgeni
7373
* Fixed handling of the epilog
7474

7575
0.2.2
@@ -80,16 +80,16 @@ Change log
8080
0.2.1
8181
#####
8282

83-
* Stopped importing `sphinx.util.compat`, which was causing issues like that seen in `#65 <https://github.com/alex-rudakov/sphinx-argparse/issues/65>`_
83+
* Stopped importing ``sphinx.util.compat``, which was causing issues like that seen in `#65 <https://github.com/alex-rudakov/sphinx-argparse/issues/65>`_
8484

8585
0.2.0
8686
#####
8787

88-
* Section titles can now be used in tables of contents and linked to. The title itself is also used as the anchor. In the case of repeated names `_replicateX`, where `X` is a number, is prepended to ensure that all titles are uniquely linkable. This was bug `#46 <https://github.com/alex-rudakov/sphinx-argparse/issues/46>`_.
88+
* Section titles can now be used in tables of contents and linked to. The title itself is also used as the anchor. In the case of repeated names ``_replicateX``, where ``X`` is a number, is prepended to ensure that all titles are uniquely linkable. This was bug `#46 <https://github.com/alex-rudakov/sphinx-argparse/issues/46>`_.
8989
* The positional (aka required) and named (aka optional) option sections are now named "Positional Arguments" and "Named Arguments", for the sake of clarity (e.g., named arguments can be required). This was issue `#58 <https://github.com/alex-rudakov/sphinx-argparse/issues/58>`_.
9090
* Fixed quoting of default strings (issue `#59 <https://github.com/alex-rudakov/sphinx-argparse/issues/59>`_).
91-
* Added the `:noepilog:` and `:nodescription:` options, thanks to @arewm.
92-
* Added the `:nosubcommand:` option, thanks to @arewm.
91+
* Added the ``:noepilog:`` and ``:nodescription:`` options, thanks to @arewm.
92+
* Added the ``:nosubcommand:`` option, thanks to @arewm.
9393

9494
0.1.17
9595
######
@@ -99,9 +99,9 @@ Change log
9999
0.1.16
100100
######
101101

102-
* Added a `:nodefaultconst:` directive, which is similar to the `:nodefault:` directive, but applies only to `store_true`, `store_false`, and `store_const` (e.g., it will hide the "=True" part in the output, since that can be misleading to users).
102+
* Added a ``:nodefaultconst:`` directive, which is similar to the ``:nodefault:`` directive, but applies only to ``store_true``, ``store_false``, and ``store_const`` (e.g., it will hide the "=True" part in the output, since that can be misleading to users).
103103
* Fixed various typos (thanks to users mikeantonacci, brondsem, and tony)
104-
* Format specifiers (e.g., `%(prog)s` and `%(default)s`) are now filled in (if possible) in help sections. If there's a missing keyword, then nothing will be filled in. This was issue #27.
104+
* Format specifiers (e.g., ``%(prog)s`` and ``%(default)s``) are now filled in (if possible) in help sections. If there's a missing keyword, then nothing will be filled in. This was issue #27.
105105
* The package is now a bit more robust to incorrectly spelling module names (#39, courtesy of Gabriel Falcão)
106106
* Added support for argparse groups (thanks to Fidel Ramirez)
107107

@@ -117,7 +117,7 @@ Change log
117117
* Support for aliasing arguments #22 (Campbell Barton)
118118
* Support for nested arguments #23 (Campbell Barton)
119119
* Support for subcommand descriptions #24 (Campbell Barton)
120-
* Improved parsing of content of `epilog` and `description` #25 (Louis - https://github.com/paternal)
120+
* Improved parsing of content of ``epilog`` and ``description`` #25 (Louis - https://github.com/paternal)
121121
* Added 'passparser' option (David Hoese)
122122

123123
0.1.13

docs/contrib.rst

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@ Any help is welcome!
55

66
Most wanted:
77

8-
* Additional features
9-
* Bug fixes
10-
* Examples
8+
* Additional features
9+
* Bug fixes
10+
* Examples
1111

12-
Contributions are gratefully accepted through `github <https://github.com/sphinx-doc/sphinx-argparse>`_ pull-request. Please report bugs as issues on github.
12+
Contributions are gratefully accepted through `GitHub pull requests`_.
13+
Please report any bugs as issues on GitHub.
1314

14-
Don't forget to run tests before committing::
15+
.. _GitHub pull requests: https://github.com/sphinx-doc/sphinx-argparse/
1516

16-
py.test
17+
Don't forget to run tests before committing:
18+
19+
.. code:: shell
20+
21+
pytest

docs/extend.rst

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,78 @@
1-
Extending results of `argparse` directives
2-
==========================================
1+
Extending results of ``argparse`` directives
2+
============================================
33

4-
You can add extra content or even replace some parts of the documentation generated by the `argparse` directive. For example, any content you put inside directives (you must follow ReStructuredText identation rules) will be inserted just before the argument and option list::
4+
You can add extra content or even replace some parts of the documentation generated by the ``argparse`` directive.
5+
For example, any content you put inside directives (you must follow ReStructuredText identation rules) will be inserted just before the argument and option list:
6+
7+
.. code:: rst
58
69
.. argparse::
7-
:module: my.module
8-
:func: my_func_that_return_parser
9-
:prog: fancytool
10+
:module: my.module
11+
:func: my_func_that_return_parser
12+
:prog: fancytool
1013
1114
My content here that will be inserted right before the argument list.
1215
1316
Also any valid markup...
1417
*************************
1518
16-
... may `be` *applied* here
19+
... may ``be`` *applied* here
1720
1821
including::
1922
2023
any directives you usually use.
2124
2225
23-
Also, there is an option to insert custom content into a specific argument/option/subcommand/argument-group description. Just create a name:definition pair, where the name is an argument/option/subcommand/argument-group name and the definition is any reStructured markup. Changes to options/arguments appearing in multiple action groups can either be targeted (i.e., only one instance of the argument is changed) or general (i.e., all instances are modified).::
26+
Also, there is an option to insert custom content into a specific argument/option/subcommand/argument-group description.
27+
Just create a name:definition pair, where the name is an argument/option/subcommand/argument-group name and the definition is any reStructured markup.
28+
Changes to options/arguments appearing in multiple action groups can either be targeted (i.e., only one instance of the argument is changed) or general (i.e., all instances are modified).
29+
30+
.. code:: rst
2431
2532
.. argparse::
26-
:module: my.module
27-
:func: my_func_that_return_parser
28-
:prog: fancytool
33+
:module: my.module
34+
:func: my_func_that_return_parser
35+
:prog: fancytool
2936
30-
My content here that will be inserted right before the argument list.
37+
My content here that will be inserted right before the argument list.
38+
39+
foo
40+
This text will go right after the "foo" positional argument help.
3141
32-
foo
33-
This text will go right after the "foo" positional argument help.
42+
install
43+
This text will go right after the "install" subcommand help and before its arguments.
3444
35-
install
36-
This text will go right after the "install" subcommand help and before its arguments.
45+
--upgrade -u
46+
This text will go after the upgrade option of the install subcommand. Nesting is unlimited.
47+
Note the space between --upgrade and -u, which differs from the comma that would normally
48+
be used.
3749
38-
--upgrade -u
39-
This text will go after the upgrade option of the install subcommand. Nesting is unlimited.
40-
Note the space between --upgrade and -u, which differs from the comma that would normally
41-
be used.
50+
--output -o
51+
Content appended to the --output option, regardless of the argument group.
4252
43-
--output -o
44-
Content appended to the --output option, regardless of the argument group.
4553
54+
You can also add classifiers, which will change how these definitions are incorporated:
4655

47-
You can also add classifiers, which will change how these definitions are incorporated::
56+
.. code:: rst
4857
4958
.. argparse::
50-
:module: my.module
51-
:func: my_func_that_return_parser
52-
:prog: fancytool
59+
:module: my.module
60+
:func: my_func_that_return_parser
61+
:prog: fancytool
5362
54-
My content that will be inserted right before the argument list.
63+
My content that will be inserted right before the argument list.
5564
56-
foo : @before
57-
This text will go before the "foo" positional argument help.
65+
foo : @before
66+
This text will go before the "foo" positional argument help.
5867
59-
install : @replace
60-
This text will replace the "install" subcommand help/description.
68+
install : @replace
69+
This text will replace the "install" subcommand help/description.
6170
62-
--upgrade : @after
63-
The after directive is the default, so you needn't specify it.
71+
--upgrade : @after
72+
The after directive is the default, so you needn't specify it.
6473
65-
advanced arguments : @skip
66-
skip advanced arguments
74+
advanced arguments : @skip
75+
skip advanced arguments
6776
6877
6978
@before

docs/index.rst

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
`sphinx-argparse`
2-
=================
3-
4-
`sphinx-argparse` is an extension for sphinx that allows for easy generation of documentation for command line tools using the python argparse library.
1+
``sphinx-argparse``
2+
===================
53

4+
`sphinx-argparse` is an extension for Sphinx_ that allows for
5+
easy generation of documentation for command line tools using
6+
Python's argparse_ library.
67

8+
.. _Sphinx: https://www.sphinx-doc.org/
9+
.. _argparse: https://docs.python.org/3/library/argparse.html
710

811
.. toctree::
9-
:maxdepth: 2
12+
:hidden:
13+
:maxdepth: 1
1014

1115
usage
1216
extend
@@ -22,15 +26,21 @@ Installation
2226

2327
This extension works with Python 3.10 or later and Sphinx 5.1 or later.
2428

25-
The package is available in the `Python Package Index`_::
29+
The package is available in the `Python Package Index`_:
30+
31+
.. code:: shell
32+
33+
pip install sphinx-argparse
2634
27-
pip install sphinx-argparse
35+
And also in `conda-forge`_:
2836

29-
And also in `conda-forge`_::
37+
.. code:: shell
3038
31-
mamba -c conda-forge install sphinx-argparse
39+
mamba -c conda-forge install sphinx-argparse
3240
33-
Enable the extension in your sphinx config::
41+
Enable the extension in your sphinx config:
42+
43+
.. code:: python
3444
3545
extensions = [
3646
...,
@@ -41,10 +51,8 @@ Enable the extension in your sphinx config::
4151
.. _conda-forge: https:://github.com/conda-forge/sphinx-argparse-feedstock/
4252

4353

44-
References
45-
==========
46-
4754
Similar projects
4855
-------------------
4956

50-
* https://pythonhosted.org/sphinxcontrib-autoprogram/ (See for comparison: https://github.com/ribozz/sphinx-argparse/issues/16)
57+
* https://pypi.org/project/sphinxcontrib-autoprogram/
58+
(See a comparison: https://github.com/sphinx-doc/sphinx-argparse/issues/16)

docs/markdown.rst

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
Markdown
22
========
33

4-
As of version 0.2.0, markdown (rather than only reStructuredText) can be included inside directives as nested content. While markdown is much easier to write, please note that it is also less powerful. An example is below::
4+
As of version 0.2.0, markdown (rather than only reStructuredText) can be included inside directives as nested content.
5+
While markdown is much easier to write, please note that it is also less powerful.
6+
An example is below:
7+
8+
.. code:: rst
59
610
.. argparse::
7-
:filename: ../test/sample.py
8-
:func: parser
9-
:prog: sample
10-
:markdown:
11+
:filename: ../test/sample.py
12+
:func: parser
13+
:prog: sample
14+
:markdown:
1115
12-
Header 1
13-
========
16+
Header 1
17+
========
1418
15-
[I'm a link to google](http://www.google.com)
19+
[I'm a link to google](http://www.google.com)
1620
17-
## Sub-heading
21+
## Sub-heading
1822
19-
```
20-
This
21-
is
22-
a
23-
fenced
24-
code
25-
block
26-
```
23+
```
24+
This
25+
is
26+
a
27+
fenced
28+
code
29+
block
30+
```
2731
2832
The above example renders as follows:
2933

@@ -51,42 +55,51 @@ The above example renders as follows:
5155
block
5256
```
5357

54-
The `CommonMark-py <https://github.com/rtfd/CommonMark-py>`__ is used internally to parse Markdown. Consequently, only Markdown supported by CommonMark-py will be rendered.
58+
The `CommonMark-py <https://github.com/rtfd/CommonMark-py>`__ is used internally to parse Markdown.
59+
Consequently, only Markdown supported by CommonMark-py will be rendered.
5560

56-
You must explicitly use the `:markdown:` flag, otherwise all content inside directives will be parsed as reStructuredText.
61+
You must explicitly use the ``:markdown:`` flag, otherwise all content inside directives will be parsed as reStructuredText.
5762

5863
A note on headers
5964
-----------------
6065

61-
If the Markdown you nest includes headings, then the first one **MUST** be level 1. Subsequent headings can be at `lower levels <http://daringfireball.net/projects/markdown/syntax#header>`__ and then rendered correctly.
66+
If the Markdown you nest includes headings, then the first one **MUST** be level 1.
67+
Subsequent headings can be at `lower levels <http://daringfireball.net/projects/markdown/syntax#header>`__ and then rendered correctly.
6268

6369
Hard line breaks
6470
----------------
6571

66-
Sphinx strips white-space from the end of lines prior to handing it to this package. Because of that, hard line breaks can not currently be rendered.
72+
Sphinx strips white-space from the end of lines prior to handing it to this package.
73+
Because of that, hard line breaks can not currently be rendered.
6774

6875
Replacing/appending/prepending content
6976
--------------------------------------
7077

71-
When markdown is used as nested content, it's not possible to create dictionary entries like in reStructuredText to `modify program option descriptions <extend.html>`__. This is because CommonMark-py does not support dictionary entries.
78+
When markdown is used as nested content, it's not possible to create dictionary entries like in reStructuredText to `modify program option descriptions <extend.html>`__.
79+
This is because CommonMark-py does not support dictionary entries.
7280

7381
MarkDown in program descriptions and option help
7482
------------------------------------------------
7583

76-
In addition to using MarkDown in nested content, one can also use MarkDown directly in program descriptions and option help messages. For example::
84+
In addition to using MarkDown in nested content, one can also use MarkDown directly in program descriptions and option help messages.
85+
For example:
86+
87+
.. code:: python
88+
89+
import argparse
7790
78-
import argparse
91+
def blah():
92+
parser = argparse.ArgumentParser(description="""
93+
### Example of MarkDown inside programs
7994
80-
def blah():
81-
parser = argparse.ArgumentParser(description="""
82-
### Example of MarkDown inside programs
95+
[I'm a link](http://www.google.com)
96+
""")
97+
parser.add_argument('cmd', help='execute a `command`')
98+
return parser
8399
84-
[I'm a link](http://www.google.com)
85-
""")
86-
parser.add_argument('cmd', help='execute a `command`')
87-
return parser
100+
To render this as MarkDown rather than reStructuredText, use the ``:markdownhelp:`` option:
88101

89-
To render this as MarkDown rather than reStructuredText, use the `markdownhelp` option::
102+
.. code:: rst
90103
91104
.. argparse::
92105
:filename: ../test/sample2.py

0 commit comments

Comments
 (0)