Sphinx and argparse - autodocumenting command line scripts?
I'm building a Python package, and using Sphinx to create the docs. Aside from my package code, I also include a lot of command line Python scripts, which use argparse. I was wondering if there is a way to get Sphinx to autodocument these scripts? The end goal would be a pretty-printed list of scripts, with the associated help print, arguments and options. And to be clear, I'm looking for a pre-existing way to do this, not a way to implement this myself.
This isn't as specific of a question as I usually ask on S.O., if there is a more appropriate S.E. site to post this question, please let me know. Thanks.
python documentation python-sphinx argparse
add a comment |
I'm building a Python package, and using Sphinx to create the docs. Aside from my package code, I also include a lot of command line Python scripts, which use argparse. I was wondering if there is a way to get Sphinx to autodocument these scripts? The end goal would be a pretty-printed list of scripts, with the associated help print, arguments and options. And to be clear, I'm looking for a pre-existing way to do this, not a way to implement this myself.
This isn't as specific of a question as I usually ask on S.O., if there is a more appropriate S.E. site to post this question, please let me know. Thanks.
python documentation python-sphinx argparse
Unrelated, but might be helpful. Check plac package on PyPI.
– Mikko Ohtamaa
Jun 4 '12 at 21:58
Don't think it helps me with this, but interesting, thanks for the heads-up.
– jeremiahbuddha
Jun 4 '12 at 22:55
add a comment |
I'm building a Python package, and using Sphinx to create the docs. Aside from my package code, I also include a lot of command line Python scripts, which use argparse. I was wondering if there is a way to get Sphinx to autodocument these scripts? The end goal would be a pretty-printed list of scripts, with the associated help print, arguments and options. And to be clear, I'm looking for a pre-existing way to do this, not a way to implement this myself.
This isn't as specific of a question as I usually ask on S.O., if there is a more appropriate S.E. site to post this question, please let me know. Thanks.
python documentation python-sphinx argparse
I'm building a Python package, and using Sphinx to create the docs. Aside from my package code, I also include a lot of command line Python scripts, which use argparse. I was wondering if there is a way to get Sphinx to autodocument these scripts? The end goal would be a pretty-printed list of scripts, with the associated help print, arguments and options. And to be clear, I'm looking for a pre-existing way to do this, not a way to implement this myself.
This isn't as specific of a question as I usually ask on S.O., if there is a more appropriate S.E. site to post this question, please let me know. Thanks.
python documentation python-sphinx argparse
python documentation python-sphinx argparse
edited Jun 6 '12 at 11:56
bmu
22.1k87693
22.1k87693
asked Jun 4 '12 at 19:08
jeremiahbuddhajeremiahbuddha
5,29921830
5,29921830
Unrelated, but might be helpful. Check plac package on PyPI.
– Mikko Ohtamaa
Jun 4 '12 at 21:58
Don't think it helps me with this, but interesting, thanks for the heads-up.
– jeremiahbuddha
Jun 4 '12 at 22:55
add a comment |
Unrelated, but might be helpful. Check plac package on PyPI.
– Mikko Ohtamaa
Jun 4 '12 at 21:58
Don't think it helps me with this, but interesting, thanks for the heads-up.
– jeremiahbuddha
Jun 4 '12 at 22:55
Unrelated, but might be helpful. Check plac package on PyPI.
– Mikko Ohtamaa
Jun 4 '12 at 21:58
Unrelated, but might be helpful. Check plac package on PyPI.
– Mikko Ohtamaa
Jun 4 '12 at 21:58
Don't think it helps me with this, but interesting, thanks for the heads-up.
– jeremiahbuddha
Jun 4 '12 at 22:55
Don't think it helps me with this, but interesting, thanks for the heads-up.
– jeremiahbuddha
Jun 4 '12 at 22:55
add a comment |
3 Answers
3
active
oldest
votes
You can use sphinxcontrib.programoutput
to include the help messages from the command line in your documentation.
This is not specific to argparse
but can be used to document any script printing help messages to the command line.
add a comment |
Use sphinx-argparse extension:
http://sphinx-argparse.readthedocs.org/en/latest/
1
Excellent. Is there a way to have the "usage" block treated differently? For me, having it as a literal block isn't quite right.
– orome
Jan 21 '14 at 21:43
1
And while I'm at it, it would be nice of the output for options matched what.. option::
produces: flags only (no default indicated), aligned all the way to the left with less indentation for the description, and changing the first letter to caps and adding a period at the end if one is not already there (since the idiom for--help
is to omit these and use all lowercase). Also perhaps flag entries that match the help help output more closely (e.g.-cols [COL [COL ...]]
rather than justcols
), since all the text is written in that context.
– orome
Jan 21 '14 at 22:26
Seems to have an error: pastebin.com/jXAz1qHw
– Martin Thoma
Oct 20 '14 at 15:34
add a comment |
You can use sphinxcontrib.autoprogram
. pip install sphinxcontrib-autoprogram
, then put
extensions += ['sphinxcontrib.autoprogram']
in your conf.py
. To document command cli.py
by importing cli
with the argparse parser
object parser
(which can be a Python expression, like a function get_parser()
), use
.. autoprogram:: cli:parser
:prog: cli.py
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f10886841%2fsphinx-and-argparse-autodocumenting-command-line-scripts%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use sphinxcontrib.programoutput
to include the help messages from the command line in your documentation.
This is not specific to argparse
but can be used to document any script printing help messages to the command line.
add a comment |
You can use sphinxcontrib.programoutput
to include the help messages from the command line in your documentation.
This is not specific to argparse
but can be used to document any script printing help messages to the command line.
add a comment |
You can use sphinxcontrib.programoutput
to include the help messages from the command line in your documentation.
This is not specific to argparse
but can be used to document any script printing help messages to the command line.
You can use sphinxcontrib.programoutput
to include the help messages from the command line in your documentation.
This is not specific to argparse
but can be used to document any script printing help messages to the command line.
edited Jun 6 '12 at 11:55
answered Jun 5 '12 at 8:19
bmubmu
22.1k87693
22.1k87693
add a comment |
add a comment |
Use sphinx-argparse extension:
http://sphinx-argparse.readthedocs.org/en/latest/
1
Excellent. Is there a way to have the "usage" block treated differently? For me, having it as a literal block isn't quite right.
– orome
Jan 21 '14 at 21:43
1
And while I'm at it, it would be nice of the output for options matched what.. option::
produces: flags only (no default indicated), aligned all the way to the left with less indentation for the description, and changing the first letter to caps and adding a period at the end if one is not already there (since the idiom for--help
is to omit these and use all lowercase). Also perhaps flag entries that match the help help output more closely (e.g.-cols [COL [COL ...]]
rather than justcols
), since all the text is written in that context.
– orome
Jan 21 '14 at 22:26
Seems to have an error: pastebin.com/jXAz1qHw
– Martin Thoma
Oct 20 '14 at 15:34
add a comment |
Use sphinx-argparse extension:
http://sphinx-argparse.readthedocs.org/en/latest/
1
Excellent. Is there a way to have the "usage" block treated differently? For me, having it as a literal block isn't quite right.
– orome
Jan 21 '14 at 21:43
1
And while I'm at it, it would be nice of the output for options matched what.. option::
produces: flags only (no default indicated), aligned all the way to the left with less indentation for the description, and changing the first letter to caps and adding a period at the end if one is not already there (since the idiom for--help
is to omit these and use all lowercase). Also perhaps flag entries that match the help help output more closely (e.g.-cols [COL [COL ...]]
rather than justcols
), since all the text is written in that context.
– orome
Jan 21 '14 at 22:26
Seems to have an error: pastebin.com/jXAz1qHw
– Martin Thoma
Oct 20 '14 at 15:34
add a comment |
Use sphinx-argparse extension:
http://sphinx-argparse.readthedocs.org/en/latest/
Use sphinx-argparse extension:
http://sphinx-argparse.readthedocs.org/en/latest/
answered Sep 5 '13 at 10:54
ribozzribozz
41647
41647
1
Excellent. Is there a way to have the "usage" block treated differently? For me, having it as a literal block isn't quite right.
– orome
Jan 21 '14 at 21:43
1
And while I'm at it, it would be nice of the output for options matched what.. option::
produces: flags only (no default indicated), aligned all the way to the left with less indentation for the description, and changing the first letter to caps and adding a period at the end if one is not already there (since the idiom for--help
is to omit these and use all lowercase). Also perhaps flag entries that match the help help output more closely (e.g.-cols [COL [COL ...]]
rather than justcols
), since all the text is written in that context.
– orome
Jan 21 '14 at 22:26
Seems to have an error: pastebin.com/jXAz1qHw
– Martin Thoma
Oct 20 '14 at 15:34
add a comment |
1
Excellent. Is there a way to have the "usage" block treated differently? For me, having it as a literal block isn't quite right.
– orome
Jan 21 '14 at 21:43
1
And while I'm at it, it would be nice of the output for options matched what.. option::
produces: flags only (no default indicated), aligned all the way to the left with less indentation for the description, and changing the first letter to caps and adding a period at the end if one is not already there (since the idiom for--help
is to omit these and use all lowercase). Also perhaps flag entries that match the help help output more closely (e.g.-cols [COL [COL ...]]
rather than justcols
), since all the text is written in that context.
– orome
Jan 21 '14 at 22:26
Seems to have an error: pastebin.com/jXAz1qHw
– Martin Thoma
Oct 20 '14 at 15:34
1
1
Excellent. Is there a way to have the "usage" block treated differently? For me, having it as a literal block isn't quite right.
– orome
Jan 21 '14 at 21:43
Excellent. Is there a way to have the "usage" block treated differently? For me, having it as a literal block isn't quite right.
– orome
Jan 21 '14 at 21:43
1
1
And while I'm at it, it would be nice of the output for options matched what
.. option::
produces: flags only (no default indicated), aligned all the way to the left with less indentation for the description, and changing the first letter to caps and adding a period at the end if one is not already there (since the idiom for --help
is to omit these and use all lowercase). Also perhaps flag entries that match the help help output more closely (e.g. -cols [COL [COL ...]]
rather than just cols
), since all the text is written in that context.– orome
Jan 21 '14 at 22:26
And while I'm at it, it would be nice of the output for options matched what
.. option::
produces: flags only (no default indicated), aligned all the way to the left with less indentation for the description, and changing the first letter to caps and adding a period at the end if one is not already there (since the idiom for --help
is to omit these and use all lowercase). Also perhaps flag entries that match the help help output more closely (e.g. -cols [COL [COL ...]]
rather than just cols
), since all the text is written in that context.– orome
Jan 21 '14 at 22:26
Seems to have an error: pastebin.com/jXAz1qHw
– Martin Thoma
Oct 20 '14 at 15:34
Seems to have an error: pastebin.com/jXAz1qHw
– Martin Thoma
Oct 20 '14 at 15:34
add a comment |
You can use sphinxcontrib.autoprogram
. pip install sphinxcontrib-autoprogram
, then put
extensions += ['sphinxcontrib.autoprogram']
in your conf.py
. To document command cli.py
by importing cli
with the argparse parser
object parser
(which can be a Python expression, like a function get_parser()
), use
.. autoprogram:: cli:parser
:prog: cli.py
add a comment |
You can use sphinxcontrib.autoprogram
. pip install sphinxcontrib-autoprogram
, then put
extensions += ['sphinxcontrib.autoprogram']
in your conf.py
. To document command cli.py
by importing cli
with the argparse parser
object parser
(which can be a Python expression, like a function get_parser()
), use
.. autoprogram:: cli:parser
:prog: cli.py
add a comment |
You can use sphinxcontrib.autoprogram
. pip install sphinxcontrib-autoprogram
, then put
extensions += ['sphinxcontrib.autoprogram']
in your conf.py
. To document command cli.py
by importing cli
with the argparse parser
object parser
(which can be a Python expression, like a function get_parser()
), use
.. autoprogram:: cli:parser
:prog: cli.py
You can use sphinxcontrib.autoprogram
. pip install sphinxcontrib-autoprogram
, then put
extensions += ['sphinxcontrib.autoprogram']
in your conf.py
. To document command cli.py
by importing cli
with the argparse parser
object parser
(which can be a Python expression, like a function get_parser()
), use
.. autoprogram:: cli:parser
:prog: cli.py
answered Aug 9 '16 at 2:37
asmeurerasmeurer
58.8k17113188
58.8k17113188
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f10886841%2fsphinx-and-argparse-autodocumenting-command-line-scripts%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Unrelated, but might be helpful. Check plac package on PyPI.
– Mikko Ohtamaa
Jun 4 '12 at 21:58
Don't think it helps me with this, but interesting, thanks for the heads-up.
– jeremiahbuddha
Jun 4 '12 at 22:55