Skip to content

Commit c6e10a5

Browse files
committed
doc: add initial documentation
Add initial minimal documentation to setup a readthedocs instance for labgridhelper. Signed-off-by: Rouven Czerwinski <[email protected]>
1 parent 32a181b commit c6e10a5

File tree

7 files changed

+315
-0
lines changed

7 files changed

+315
-0
lines changed

doc-requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Sphinx==1.8.1
2+
sphinx_rtd_theme==0.4.1
3+
docutils==0.14

doc/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

doc/conf.py

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
#
4+
# labgrid documentation build configuration file, created by
5+
# sphinx-quickstart on Mon Feb 20 10:00:00 2017.
6+
#
7+
# This file is execfile()d with the current directory set to its
8+
# containing dir.
9+
#
10+
# Note that not all possible configuration values are present in this
11+
# autogenerated file.
12+
#
13+
# All configuration values have a default; values that are commented out
14+
# serve to show the default.
15+
16+
# If extensions (or modules to document with autodoc) are in another directory,
17+
# add these directories to sys.path here. If the directory is relative to the
18+
# documentation root, use os.path.abspath to make it absolute, like shown here.
19+
#
20+
import os
21+
import sys
22+
sys.path.insert(0, os.path.abspath('..'))
23+
24+
from pkg_resources import get_distribution
25+
26+
# Import read_the_docs theme
27+
import sphinx_rtd_theme
28+
29+
# -- General configuration ------------------------------------------------
30+
31+
# If your documentation needs a minimal Sphinx version, state it here.
32+
#
33+
# needs_sphinx = '1.0'
34+
35+
# Add any Sphinx extension module names here, as strings. They can be
36+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
37+
# ones.
38+
extensions = ['sphinx.ext.autodoc',
39+
'sphinx.ext.napoleon',
40+
'sphinx.ext.coverage',
41+
'sphinx.ext.viewcode',
42+
'sphinx.ext.autosectionlabel']
43+
44+
# Add any paths that contain templates here, relative to this directory.
45+
templates_path = ['.templates']
46+
47+
# The suffix(es) of source filenames.
48+
# You can specify multiple suffix as a list of string:
49+
#
50+
# source_suffix = ['.rst', '.md']
51+
source_suffix = '.rst'
52+
53+
# The master toctree document.
54+
master_doc = 'index'
55+
56+
# General information about the project.
57+
project = 'labgridhelper'
58+
copyright = '2019 Pengutronix, Jan Luebbe and Rouven Czerwinski'
59+
author = 'Rouven Czerwinski'
60+
61+
# The version info for the project you're documenting, acts as replacement for
62+
# |version| and |release|, also used in various other places throughout the
63+
# built documents.
64+
#
65+
# The full version, including alpha/beta/rc tags.
66+
release = get_distribution('labgridhelper').version
67+
# The short X.Y version.
68+
version = '.'.join(release.split('.')[:2])
69+
70+
# The language for content autogenerated by Sphinx. Refer to documentation
71+
# for a list of supported languages.
72+
#
73+
# This is also used if you do content translation via gettext catalogs.
74+
# Usually you set "language" from the command line for these cases.
75+
language = None
76+
77+
# List of patterns, relative to source directory, that match files and
78+
# directories to ignore when looking for source files.
79+
# This patterns also effect to html_static_path and html_extra_path
80+
exclude_patterns = ['.build', 'Thumbs.db', '.DS_Store']
81+
82+
# The name of the Pygments (syntax highlighting) style to use.
83+
pygments_style = 'sphinx'
84+
85+
# If true, `todo` and `todoList` produce output, else they produce nothing.
86+
todo_include_todos = False
87+
88+
89+
# -- Options for HTML output ----------------------------------------------
90+
91+
# The theme to use for HTML and HTML Help pages. See the documentation for
92+
# a list of builtin themes.
93+
#
94+
html_theme = 'sphinx_rtd_theme'
95+
96+
# Set correct html_path for rtd theme:
97+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
98+
99+
# Theme options are theme-specific and customize the look and feel of a theme
100+
# further. For a list of options available for each theme, see the
101+
# documentation.
102+
#
103+
# html_theme_options = {}
104+
105+
# Add any paths that contain custom static files (such as style sheets) here,
106+
# relative to this directory. They are copied after the builtin static files,
107+
# so a file named "default.css" will overwrite the builtin "default.css".
108+
html_static_path = []
109+
110+
111+
# -- Options for HTMLHelp output ------------------------------------------
112+
113+
# Output file base name for HTML help builder.
114+
htmlhelp_basename = 'labgriddoc'
115+
116+
117+
# -- Options for LaTeX output ---------------------------------------------
118+
119+
latex_elements = {
120+
# The paper size ('letterpaper' or 'a4paper').
121+
#
122+
# 'papersize': 'letterpaper',
123+
124+
# The font size ('10pt', '11pt' or '12pt').
125+
#
126+
# 'pointsize': '10pt',
127+
128+
# Additional stuff for the LaTeX preamble.
129+
#
130+
# 'preamble': '',
131+
132+
# Latex figure (float) alignment
133+
#
134+
# 'figure_align': 'htbp',
135+
}
136+
137+
# Grouping the document tree into LaTeX files. List of tuples
138+
# (source start file, target name, title,
139+
# author, documentclass [howto, manual, or own class]).
140+
latex_documents = [
141+
(master_doc, 'labgridhelper.tex', 'labgridhelper Documentation',
142+
author, 'manual'),
143+
]
144+
145+
146+
# -- Options for manual page output ---------------------------------------
147+
148+
# One entry per manual page. List of tuples
149+
# (source start file, name, description, authors, manual section).
150+
man_pages = [
151+
(master_doc, 'labgridhelper', 'labgridhelper Documentation',
152+
[author], 1)
153+
]
154+
155+
156+
# -- Options for Texinfo output -------------------------------------------
157+
158+
# Grouping the document tree into Texinfo files. List of tuples
159+
# (source start file, target name, title, author,
160+
# dir menu entry, description, category)
161+
texinfo_documents = [
162+
(master_doc, 'labgridhelper', 'labgridhelper Documentation',
163+
author, 'labgrid', 'Helper functions for the labgrid library',
164+
'Miscellaneous'),
165+
]
166+
167+
168+
# -- Options for autodoc --------------------------------------------------
169+
170+
autodoc_member_order = 'bysource'
171+
autodoc_default_flags = ['special-members']
172+
autodoc_mock_imports = ['labgrid',
173+
'labgrid.driver',
174+
'labgrid.protocol']
175+
176+
# -- Options for autosection ----------------------------------------------
177+
autosectionlabel_prefix_document = True
178+
179+
180+
from unittest.mock import Mock
181+
for mod in autodoc_mock_imports:
182+
sys.modules[mod] = Mock()
183+
184+
def run_apidoc(app):
185+
from sphinx.apidoc import main
186+
module = os.path.abspath(os.path.join(app.srcdir, '..', 'labgridhelper'))
187+
output = os.path.abspath(os.path.join(app.srcdir, 'modules'))
188+
cmd = ['sphinx-apidoc', module, '-M', '-H', 'Modules', '-o', output]
189+
main(cmd)
190+
191+
def setup(app):
192+
app.connect('builder-inited', run_apidoc)

doc/index.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Welcome to labgridhelper's documentation!
2+
===================================
3+
4+
Labgridhelper provides utility functions for the labgrid library and labgrid
5+
testsuites.
6+
7+
It is meant to provide wrapper functions for commonly used functionality such as
8+
the retrieval of the system service status information.
9+
10+
.. toctree::
11+
overview
12+
modules/modules
13+
:maxdepth: 2
14+
:caption: Contents
15+
16+
17+
Indices and Tables
18+
------------------
19+
20+
* :ref:`genindex`
21+
* :ref:`modindex`
22+
* :ref:`search`

doc/modules/labgridhelper.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
labgridhelper package
2+
=====================
3+
4+
.. automodule:: labgridhelper
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
8+
9+
Submodules
10+
----------
11+
12+
labgridhelper.barebox module
13+
----------------------------
14+
15+
.. automodule:: labgridhelper.barebox
16+
:members:
17+
:undoc-members:
18+
:show-inheritance:
19+
20+
labgridhelper.linux module
21+
--------------------------
22+
23+
.. automodule:: labgridhelper.linux
24+
:members:
25+
:undoc-members:
26+
:show-inheritance:
27+
28+

doc/modules/modules.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Modules
2+
=======
3+
4+
.. toctree::
5+
:maxdepth: 4
6+
7+
labgridhelper

doc/overview.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
==========
2+
Overview
3+
==========
4+
5+
Labgridhelper is separated into different submodules. These submodules are
6+
created for different stages of a device boot, i.e. the barebox submodules is
7+
used for the barebox bootloader and the linux submodule is used for a fully
8+
booted linux system.
9+
10+
Writing new helper functions
11+
============================
12+
Helper functions usually use one of the protocols from labgrid to retrive data
13+
from the device, reformat the data and return it to be consumed in the test
14+
case.
15+
These functions should not perform test asserts, this should be done in the
16+
individual test cases, to separate data reformating from testing.
17+
Asserts however are needed to verify that the correct protocol is passed to the
18+
helper function. This is usually done by importing the protocol from labgrid and
19+
performing the assert in the beginning of the helper, i.e.:
20+
21+
::
22+
23+
def get_systemd_status(command):
24+
assert isinstance(command, CommandProtocol), "command must be a CommandProtocol"
25+
26+
This should ensure that the correct protocol is used and the helper function is
27+
used correctly in the test suite.
28+
29+
Helper functions should also contain a docstring to document its function for
30+
the user, i.e.:
31+
32+
::
33+
34+
def get_commands(command, directories=None):
35+
"""Returns the commands of a running linux system
36+
37+
Args:
38+
command (CommandProtocol): An instance of a Driver implementing the CommandProtocol
39+
directories (list): An optional list of directories to include
40+
41+
Returns:
42+
list: list of commands available under linux
43+
"""

0 commit comments

Comments
 (0)