Skip to content

Conversation

@jonrebm
Copy link
Contributor

@jonrebm jonrebm commented Nov 5, 2025

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.

@jonrebm jonrebm force-pushed the sphinx_autoprogram branch 2 times, most recently from 00247b5 to e590065 Compare November 5, 2025 11:21
@jonrebm
Copy link
Contributor Author

jonrebm commented Nov 5, 2025

Ready to merge as far as I can tell

@Emantor
Copy link
Member

Emantor commented Nov 5, 2025

I like this version a lot better than the previous argparse version, nice work.

@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

❌ Patch coverage is 15.25424% with 50 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.2%. Comparing base (f63dfd7) to head (45ae505).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
labgrid/remote/client.py 15.2% 50 Missing ⚠️
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     
Flag Coverage Δ
3.10 45.2% <15.2%> (-0.1%) ⬇️
3.11 45.2% <15.2%> (-0.1%) ⬇️
3.12 45.2% <15.2%> (-0.1%) ⬇️
3.13 45.2% <15.2%> (-0.1%) ⬇️
3.14 45.2% <15.2%> (-0.1%) ⬇️
3.9 45.3% <15.2%> (-0.1%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jonrebm
Copy link
Contributor Author

jonrebm commented Nov 5, 2025

Thank you, happy to hear @Emantor
Now that I have your attention. There is a little oddity that the manpages used to have different authorship and copyright texts compared to the sphinx doc. I assumed this to be circumstantial and made no attempts to keep this.
Hence, this:

.SH AUTHOR
Rouven Czerwinski <[email protected]>
Organization: Labgrid-Project
.SH COPYRIGHT
Copyright (C) 2016-2025 Pengutronix. This library is free software;
you can redistribute it and/or modify it under the terms of the GNU
Lesser General Public License as published by the Free Software
Foundation; either version 2.1 of the License, or (at your option)
any later version.

Changed into this:
.SH AUTHOR
Jan Luebbe, Rouven Czerwinski
.SH COPYRIGHT
2016-2025 Pengutronix, Jan Luebbe and Rouven Czerwinski

Due to this:

labgrid/doc/conf.py

Lines 59 to 61 in f63dfd7

project = 'labgrid'
copyright = '2016-2025 Pengutronix, Jan Luebbe and Rouven Czerwinski'
author = 'Jan Luebbe, Rouven Czerwinski'

Can it stay this way or should the LGPL be explicitly mentioned here?
Why no mention of "the labgrid contributers" by the way? 🙂

@Emantor
Copy link
Member

Emantor commented Nov 5, 2025

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".

@jonrebm
Copy link
Contributor Author

jonrebm commented Nov 5, 2025

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).

@Bastian-Krause
Copy link
Member

Bastian-Krause commented Nov 5, 2025

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.

@jonrebm
Copy link
Contributor Author

jonrebm commented Nov 5, 2025

Nice, this is so much better!

Happy to hear!

I haven't looked through this thoroughly, but I noticed that positional arguments are currently indistinguishable from sub commands in "usage", e.g.

* https://labgrid--1767.org.readthedocs.build/en/1767/man/client.html#labgrid-client-allow

* https://labgrid--1767.org.readthedocs.build/en/1767/man/client.html#labgrid-client-add-alias

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. labgrid-client allow -h. I'm not sure why argparse displays it this way but it's out of scope for this pr.

@jonrebm jonrebm force-pushed the sphinx_autoprogram branch from e590065 to 0999668 Compare November 5, 2025 16:03
Copy link
Member

@Bastian-Krause Bastian-Krause left a 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]>
@jonrebm
Copy link
Contributor Author

jonrebm commented Nov 6, 2025

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]>
@Bastian-Krause
Copy link
Member

Bastian-Krause commented Nov 7, 2025

Pushed changes (first as fixups, then squashed):

  • renamed for_manpage -> auto_doc_mode, switched 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
  • hide Debian-internal labgrid-pytest in documentation, but still generate man page (same behavior as before)

Edit: This change does not touch the generated man/HTML output, except for labgrid-pytest.

Bastian-Krause
Bastian-Krause previously approved these changes Nov 7, 2025
@Bastian-Krause
Copy link
Member

Yes, the manpage generation specific argparse code doesn't have test coverage, I hope we can make an exception here.

Don't worry, that check is not required.

@jonrebm
Copy link
Contributor Author

jonrebm commented Nov 7, 2025

Thank you and looks good to me

@jonrebm
Copy link
Contributor Author

jonrebm commented Nov 7, 2025

Taking a final look at the result, let's lower text width for usage texts to 80 after all.
I set it to 180 as I thought man and the html would wrap that themselves but the html doesn't, adding a horizontal scrollbar and for the manpages too it looks better and seems commonplace to wrap these to around 80

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]>
@jonrebm
Copy link
Contributor Author

jonrebm commented Nov 7, 2025

Yes looks much better with os.environ["COLUMNS"] = "80", and that's the only change I made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants