Skip to content

Commit a99b7fb

Browse files
authored
Merge pull request #1767 from jonrebm/sphinx_autoprogram
Generate CLI documentation using sphinx with autoprogram
2 parents 70f6150 + 6e0f173 commit a99b7fb

23 files changed

+1786
-1005
lines changed

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Did you test the change locally? If yes, best to mention how you did it in the d
3333
--->
3434
- [ ] PR has been tested
3535
<!---
36-
If your PR touched the man pages they have to be regenerated by calling make in the man subdirectory of the project
36+
If your PR touched the man pages in doc/man, or an argparse struct from which manpages are generated, they have to be regenerated by calling make in the man subdirectory of the project. sphinx with our themes and extensions is required for this, see the README for more information,
3737
--->
3838
- [ ] Man pages have been regenerated
3939

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ Tests can now run via:
135135
136136
venv $ python -m pytest --lg-env <config>
137137
138+
To install sphinx and the dependencies needed for generating man pages and documentation run:
139+
140+
.. code-block:: bash
141+
142+
venv $ pip install '.[doc]'
138143
139144
.. |license| image:: https://img.shields.io/badge/license-LGPLv2.1-blue.svg
140145
:alt: LGPLv2.1

doc/conf.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import sys
2222
sys.path.insert(0, os.path.abspath('..'))
2323

24-
from importlib.metadata import version
24+
from importlib import metadata
2525

2626
# Import read_the_docs theme
2727
import sphinx_rtd_theme
@@ -40,6 +40,7 @@
4040
'sphinx.ext.napoleon',
4141
'sphinx.ext.coverage',
4242
'sphinx.ext.viewcode',
43+
'sphinxcontrib.autoprogram',
4344
'sphinx.ext.autosectionlabel',
4445
'sphinx_rtd_theme']
4546

@@ -65,7 +66,7 @@
6566
# built documents.
6667
#
6768
# The full version, including alpha/beta/rc tags.
68-
release = version('labgrid')
69+
release = metadata.version('labgrid')
6970
# The short X.Y version.
7071
version = '.'.join(release.split('.')[:2])
7172

@@ -156,7 +157,19 @@
156157
# (source start file, name, description, authors, manual section).
157158
man_pages = [
158159
(master_doc, 'labgrid', 'labgrid Documentation',
159-
[author], 1)
160+
[author], 1),
161+
('man/client', 'labgrid-client', 'labgrid\'s client interface to control boards',
162+
[author], 1),
163+
('man/coordinator', 'labgrid-coordinator', 'managing labgrid resources and places',
164+
[author], 1),
165+
('man/device-config', 'labgrid-device-config', 'test configuration files',
166+
[author], 5),
167+
('man/exporter', 'labgrid-exporter', 'interface to control boards',
168+
[author], 1),
169+
('man/pytest', 'labgrid-pytest', 'labgrid integration for pytest',
170+
[author], 7),
171+
('man/suggest', 'labgrid-suggest', 'generator for YAML config files',
172+
[author], 1),
160173
]
161174

162175

@@ -185,7 +198,11 @@
185198
autodoc_mock_imports = ['onewire',
186199
'gi',
187200
'gi.repository',
188-
'vxi11']
201+
'vxi11',
202+
'pysnmp',
203+
'kasa',
204+
'kasa.iot',
205+
]
189206

190207
# -- Options for autosection ----------------------------------------------
191208
autosectionlabel_prefix_document = True
@@ -203,6 +220,10 @@ def run_apidoc(app):
203220
main(cmd)
204221

205222
def setup(app):
223+
# Make version and date stable when generating manpages as they will be tracked in git
224+
if app.outdir.parts[-1] == "man":
225+
app.config.version = ""
226+
app.config.today_fmt = "%Y"
206227
app.connect('builder-inited', run_apidoc)
207228
app.connect('doctree-read', write_literal_blocks)
208229

doc/man.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ Manual Pages
22
============
33

44
.. toctree::
5+
:maxdepth: 2
6+
57
man/client
8+
man/coordinator
69
man/device-config
710
man/exporter
8-
man/coordinator
11+
man/suggest

doc/man/client.rst

Lines changed: 133 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,134 @@
11
.. _labgrid-client:
2-
.. include:: ../../man/labgrid-client.rst
2+
3+
labgrid-client CLI
4+
==================
5+
6+
Labgrid is a scalable infrastructure and test architecture for embedded (linux) systems.
7+
8+
This is the client to control a boards status and interface with it on remote machines.
9+
10+
.. currentmodule:: labgrid.remote.client
11+
12+
13+
.. autoprogram:: labgrid.remote.client:get_parser(auto_doc_mode=True)
14+
:prog: labgrid-client
15+
16+
Configuration File
17+
------------------
18+
The configuration file follows the description in ``labgrid-device-config``\(5).
19+
20+
Environment Variables
21+
---------------------
22+
Various labgrid-client commands use the following environment variable:
23+
24+
LG_PLACE
25+
~~~~~~~~
26+
This variable can be used to specify a place without using the ``-p`` option, the ``-p`` option overrides it.
27+
28+
LG_TOKEN
29+
~~~~~~~~
30+
This variable can be used to specify a reservation for the ``wait`` command and
31+
for the ``+`` place expansion.
32+
33+
LG_STATE
34+
~~~~~~~~
35+
This variable can be used to specify a state which the device transitions into
36+
before executing a command. Requires a configuration file and a Strategy
37+
specified for the device.
38+
39+
LG_INITIAL_STATE
40+
~~~~~~~~~~~~~~~~
41+
This variable can be used to specify an initial state the device is known to
42+
be in.
43+
This is useful during development. The Strategy used must implement the
44+
``force()`` method.
45+
A desired state must be set using ``LG_STATE`` or ``-s``/``--state``.
46+
47+
LG_ENV
48+
~~~~~~
49+
This variable can be used to specify the configuration file to use without
50+
using the ``--config`` option, the ``--config`` option overrides it.
51+
52+
LG_COORDINATOR
53+
~~~~~~~~~~~~~~
54+
This variable can be used to set the default coordinator in the format
55+
``HOST[:PORT]`` (instead of using the ``-x`` option).
56+
57+
LG_PROXY
58+
~~~~~~~~
59+
This variable can be used to specify a SSH proxy hostname which should be used
60+
to connect to the coordinator and any resources which are normally accessed
61+
directly.
62+
63+
LG_HOSTNAME
64+
~~~~~~~~~~~
65+
Override the hostname used when accessing a resource. Typically only useful for
66+
CI pipelines where the hostname may not be consistent between pipeline stages.
67+
68+
LG_USERNAME
69+
~~~~~~~~~~~
70+
Override the username used when accessing a resource. Typically only useful for
71+
CI pipelines where the username may not be consistent between pipeline stages.
72+
73+
LG_SSH_CONNECT_TIMEOUT
74+
~~~~~~~~~~~~~~~~~~~~~~
75+
Set the connection timeout when using SSH (The ``ConnectTimeout`` option). If
76+
unspecified, defaults to 30 seconds.
77+
78+
LG_AGENT_PREFIX
79+
~~~~~~~~~~~~~~~~~~~~~~
80+
Add a prefix to ``.labgrid_agent_{agent_hash}.py`` allowing specification for
81+
where on the exporter it should be uploaded to.
82+
83+
Matches
84+
-------
85+
Match patterns are used to assign a resource to a specific place. The format is:
86+
exporter/group/cls/name, exporter is the name of the exporting machine, group is
87+
a name defined within the exporter, cls is the class of the exported resource
88+
and name is its name. Wild cards in match patterns are explicitly allowed, *
89+
matches anything.
90+
91+
Adding Named Resources
92+
----------------------
93+
If a target contains multiple Resources of the same type, named matches need to
94+
be used to address the individual resources. In addition to the *match* taken by
95+
``add-match``, ``add-named-match`` also takes a name for the resource. The other
96+
client commands support the name as an optional parameter and will inform the
97+
user that a name is required if multiple resources are found, but no name is
98+
given.
99+
100+
If one of the resources should be used by default when no resource name is
101+
explicitly specified, it can be named ``default``.
102+
103+
Examples
104+
--------
105+
106+
To retrieve a list of places run:
107+
108+
.. code-block:: bash
109+
110+
$ labgrid-client places
111+
112+
To access a place, it needs to be acquired first, this can be done by running
113+
the ``acquire command`` and passing the placename as a -p parameter:
114+
115+
.. code-block:: bash
116+
117+
$ labgrid-client -p <placename> acquire
118+
119+
Open a console to the acquired place:
120+
121+
.. code-block:: bash
122+
123+
$ labgrid-client -p <placename> console
124+
125+
Add all resources with the group "example-group" to the place example-place:
126+
127+
.. code-block:: bash
128+
129+
$ labgrid-client -p example-place add-match */example-group/*/*
130+
131+
See Also
132+
--------
133+
134+
``labgrid-exporter``\(1)

doc/man/coordinator.rst

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,34 @@
1-
.. _labgrid-coordinator:
2-
.. include:: ../../man/labgrid-coordinator.rst
1+
=====================
2+
labgrid-coordinator
3+
=====================
4+
5+
labgrid-coordinator managing labgrid resources and places
6+
=========================================================
7+
8+
SYNOPSIS
9+
--------
10+
11+
``labgrid-coordinator`` ``--help``
12+
13+
DESCRIPTION
14+
-----------
15+
Labgrid is a scalable infrastructure and test architecture for embedded (linux)
16+
systems.
17+
18+
This is the man page for the coordinator. Clients and exporters connect to the
19+
coordinator to publish resources, manage place configuration and handle mutual
20+
exclusion.
21+
22+
OPTIONS
23+
-------
24+
-h, --help
25+
display command line help
26+
-l ADDRESS, --listen ADDRESS
27+
make coordinator listen on host and port
28+
-d, --debug
29+
enable debug mode
30+
31+
SEE ALSO
32+
--------
33+
34+
``labgrid-client``\(1), ``labgrid-exporter``\(1)

0 commit comments

Comments
 (0)