-
Notifications
You must be signed in to change notification settings - Fork 229
Generate CLI documentation using sphinx with autoprogram #1767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
00247b5 to
e590065
Compare
Ready to merge as far as I can tell |
|
I like this version a lot better than the previous argparse version, nice work. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1767 +/- ##
========================================
- Coverage 45.3% 45.2% -0.1%
========================================
Files 172 172
Lines 13517 13556 +39
========================================
+ Hits 6130 6138 +8
- Misses 7387 7418 +31
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
|
Thank you, happy to hear @Emantor labgrid/man/labgrid-coordinator.1 Lines 59 to 68 in f63dfd7
Changed into this: labgrid/man/labgrid-coordinator.1 Lines 60 to 63 in 3bcbc26
Due to this: Lines 59 to 61 in f63dfd7
Can it stay this way or should the LGPL be explicitly mentioned here? |
|
I don't think an explicit mention of LGPL is necessary here and I am also fine if we extend the authors with "and contributors". |
|
Okay, thanks. Not ready for merge just yet. CI is using a different version of sphinx than what I used to generate them. This is most likely the reason why it outputs manpages with a slightly different formattingin some of the pipleines (and CI is configured to guarantee manpages are generated as tracked). |
|
Nice, this is so much better! I haven't looked through this thoroughly, but I noticed that positional arguments are currently indistinguishable from sub commands in "usage", e.g. |
Happy to hear!
autoprogram will exactly print the usage line as generated by argparse, we have (and had) the same ambiguity when usage is shown via e.g. |
e590065 to
0999668
Compare
Bastian-Krause
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work overall. The argparse autoprogram integration needs some work, but I think this is definetely the way forward. See comments below.
I don't think we should keep the "labgrid-pytest" man page: labgrid ships a pytest plugin, that's all. It is documented. The "labgrid-pytest" wrapper is merely a way to install a labgrid + pytest combination in labgrid's Debian integration. Most people will be confused about a "labgrid-pytest" script unavailable to them.
We should not import importlib.metadata.version as `version` because it clashes with sphinx config.version. import metadata and use metadata.version() for clarity. Signed-off-by: Jonas Rebmann <[email protected]>
0999668 to
b9f667a
Compare
|
Yes, the manpage generation specific argparse code doesn't have test coverage, I hope we can make an exception here. |
As sphinx supports generating manpages, use it to simplify the process and drop the dependency on rst2man. All manpages are now tracked in doc/man. The Makefile in man/ remains for forward compatibility. Keep tracking manpages themselves in troff format so sphinx is not required for packaging, slightly update Documentation to reflect the changes requirements for manpage generation. Signed-off-by: Jonas Rebmann <[email protected]> [bst: hide Debian-internal `labgrid-pytest` in documentation, but still generate man page (same behavior as before)] Signed-off-by: Bastian Krause <[email protected]>
This is an idiomatic way of setting up argument parsers and allows the parser to be re-used for manpage/documentation generation. Signed-off-by: Jonas Rebmann <[email protected]>
The old process was to manually duplicate information between the argparse struct in labgrid/remote/client.py and man/labgrid-client.rst which would then be translated to a manpage in man/labgrid-client.1 using rst2man and also tracked in version control. The man/labgrid-client.rst file was also sourced in doc/man/client.rst for sphinx to build html documentation of the labgrid-client cli documentation. Due to this duplication, labgrid-client command documentation was incomplete and inconsistend with argparse documentation accessible via the -h switch. Use the autoprogram sphinx extension to generate usage info from the argparse struct returned by get_parser() in labgrid/remote/client.py as part of doc/man/client.rst. Move documentation missing from the argparse struct from man/labgrid-client.1 to doc/man/client.rst. Generate both html cli documentation as well as the manpage from that. Future changes in subcommands and arguments of labgrid-client need only be documented in the argparse struct but more expansive documentation that includes markup can be added to the manpage, even to specific subcommands via the rst in doc/man. Signed-off-by: Jonas Rebmann <[email protected]>
Doesn't look good if every Arguments list of every subcommand of every command is listed here for the manpages generated from argparse. Signed-off-by: Jonas Rebmann <[email protected]>
7f54539 to
689f5e6
Compare
|
Pushed changes (first as fixups, then squashed):
Edit: This change does not touch the generated man/HTML output, except for |
Don't worry, that check is not required. |
|
Thank you and looks good to me |
|
Taking a final look at the result, let's lower text width for usage texts to 80 after all. |
Hide intentionally undocumented subcommands and overlong lists of choices. Work around shortcomings of autoprogram's subcommand handling: - Don't show the --help, -h option for each subparser - Display aliases as `command subcommand|alias --option` - Show the "help" message of the subparser - Don't show ranges in "choices" Signed-off-by: Jonas Rebmann <[email protected]> [bst: renamed for_manpage -> auto_doc_mode, switched its default to False, autoprogram now calls "labgrid.remote.client:get_parser(auto_doc_mode=True)", replaced monkey-patched _SubParsersAction.add_parser() with _ActionWrapper class, don't show `range` in `choices` generically, adjust commit message] Signed-off-by: Bastian Krause <[email protected]>
The subcommands descriptions for create, release-from and flashscript had some extra details in the old rst manpages, not available in the argparse/cli help. Migrate these descriptions into argparse. Signed-off-by: Jonas Rebmann <[email protected]>
689f5e6 to
45ae505
Compare
|
Yes looks much better with |
This is a second try after the formatting in #1707 using sphinx-argparse did not satisfy.
Manage the documentation with sphinx and auto-document labgrid-client arguments and subcommands from source using sphinx autoprogram.
Sections from the original man/labgrid-client.rst which are not obsoleted by the autogenerated reference are migrated into the argparse structure. Sphinx generates both the manpages as well as their html documentation counterpart.
I believe the result of this is much more useful than the current manpages we have that just don't sufficiently document usage of the subcommands.
See the readthedocs builds for results.