Skip to content

Commit bebe1e3

Browse files
authored
Add documentation (#10)
* Add full documentation for the PyOpenocdClient library. The documentation includes: ** Quick-start chapter with examples ** Full API documentation * Added a script to build the documentation locally: build_doc.py
1 parent 8c3d937 commit bebe1e3

18 files changed

+1013
-50
lines changed

.github/workflows/build_doc.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Build documentation
2+
on: [push]
3+
jobs:
4+
build_doc:
5+
runs-on: ubuntu-22.04
6+
steps:
7+
- name: Check out the repository code
8+
uses: actions/checkout@v4
9+
10+
- name: Install tools for documentation
11+
run: |
12+
python3 -m pip install --user -r requirements_doc.txt
13+
14+
- name: Build the documentation
15+
run: |
16+
python3 build_doc.py
17+
18+
19+

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ instance/
7070

7171
# Sphinx documentation
7272
docs/_build/
73+
doc/py_openocd_client/_build
7374

7475
# PyBuilder
7576
.pybuilder/

build_doc.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python3
2+
3+
# SPDX-License-Identifier: MIT
4+
5+
import subprocess
6+
import sys
7+
from pathlib import Path
8+
from typing import List
9+
10+
11+
def get_script_dir() -> Path:
12+
"""Return path to the script directory."""
13+
return Path(__file__).resolve().parent
14+
15+
16+
def run_subproc(cmd: List[str], cwd: Path) -> None:
17+
print("Running command: " + repr(cmd))
18+
subprocess.check_call(cmd, cwd=cwd)
19+
20+
21+
def main() -> int:
22+
work_dir = get_script_dir() / "doc" / "py_openocd_client"
23+
run_subproc(
24+
[
25+
sys.executable,
26+
"-m",
27+
"sphinx",
28+
"--fail-on-warning",
29+
"--keep-going",
30+
".",
31+
"_build/html",
32+
],
33+
cwd=work_dir,
34+
)
35+
return 0
36+
37+
38+
if __name__ == "__main__":
39+
sys.exit(main())

doc/py_openocd_client/apidocs.rst

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
.. _api_doc:
3+
4+
API Documentation
5+
=================
6+
7+
|
8+
9+
PyOpenocdClient
10+
---------------
11+
12+
.. automodule:: py_openocd_client
13+
14+
.. autoclass:: py_openocd_client.PyOpenocdClient
15+
:members:
16+
17+
|
18+
19+
Command result
20+
--------------
21+
22+
.. autoclass:: py_openocd_client.OcdCommandResult
23+
:members:
24+
25+
|
26+
27+
Exceptions
28+
----------
29+
30+
.. autoexception:: OcdCommandFailedError
31+
:members:
32+
33+
.. autoexception:: OcdConnectionError
34+
35+
.. autoexception:: OcdCommandTimeoutError
36+
:members:
37+
38+
.. autoexception:: OcdInvalidResponseError
39+
:members:
40+
41+
.. autoexception:: OcdBaseException
42+
43+
|
44+
45+
Other data types
46+
----------------
47+
48+
.. autoclass:: py_openocd_client.BpInfo
49+
:members:
50+
51+
.. autoclass:: py_openocd_client.WpInfo
52+
:members:
53+
54+
.. autoenum:: py_openocd_client.BpType
55+
:members:
56+
57+
.. autoenum:: py_openocd_client.WpType
58+
:members:
59+

doc/py_openocd_client/conf.py

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# This file only contains a selection of the most common options. For a full
4+
# list see the documentation:
5+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
7+
# -- Path setup --------------------------------------------------------------
8+
9+
# If extensions (or modules to document with autodoc) are in another directory,
10+
# add these directories to sys.path here. If the directory is relative to the
11+
# documentation root, use os.path.abspath to make it absolute, like shown here.
12+
#
13+
import os
14+
from pathlib import Path
15+
import sys
16+
17+
18+
def get_script_dir() -> Path:
19+
"""Return path to the script directory."""
20+
return Path(__file__).resolve().parent
21+
22+
23+
src_dir = get_script_dir() / ".." / ".." / "src"
24+
src_dir = src_dir.resolve()
25+
assert(src_dir.is_dir())
26+
27+
sys.path.insert(0, str(src_dir))
28+
29+
30+
# -- Project information -----------------------------------------------------
31+
32+
project = 'PyOpenocdClient'
33+
copyright = '2024, Jan Matyáš'
34+
author = 'Jan Matyáš'
35+
36+
37+
# -- General configuration ---------------------------------------------------
38+
39+
# Add any Sphinx extension module names here, as strings. They can be
40+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
41+
# ones.
42+
extensions = [
43+
'sphinx.ext.autodoc',
44+
'sphinx.ext.doctest',
45+
'sphinx.ext.intersphinx',
46+
'sphinx_design',
47+
'enum_tools.autoenum',
48+
]
49+
50+
# Add any paths that contain templates here, relative to this directory.
51+
templates_path = ['_templates']
52+
53+
# List of patterns, relative to source directory, that match files and
54+
# directories to ignore when looking for source files.
55+
# This pattern also affects html_static_path and html_extra_path.
56+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
57+
58+
# Keep the order of methods as in the source code
59+
autodoc_member_order = 'bysource'
60+
61+
# -- Options for HTML output -------------------------------------------------
62+
63+
# The theme to use for HTML and HTML Help pages. See the documentation for
64+
# a list of builtin themes.
65+
#
66+
html_theme = 'sphinx_rtd_theme'
67+
68+
html_theme_options = {
69+
"navigation_depth": 3
70+
}
71+
72+
# Add any paths that contain custom static files (such as style sheets) here,
73+
# relative to this directory. They are copied after the builtin static files,
74+
# so a file named "default.css" will overwrite the builtin "default.css".
75+
#html_static_path = ['_static']
76+
77+
# Set up intersphinx maps
78+
intersphinx_mapping = {'numpy': ('https://numpy.org/doc/stable', None)}

doc/py_openocd_client/index.rst

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
PyOpenocdClient documentation
3+
=============================
4+
5+
**PyOpenocdClient** is a Python library for controlling `OpenOCD`_ software tool.
6+
It allows to send commands from Python programs to OpenOCD (commands like halt execution
7+
of the debugged target, read data from memory, read values of processor registers, ...)
8+
and receive results of these commands.
9+
10+
OpenOCD is controlled by commands written in TCL language, and the set of available
11+
commands can be found in `OpenOCD documentation`_.
12+
13+
.. _OpenOCD: https://openocd.org
14+
.. _OpenOCD documentation: https://openocd.org/pages/documentation.html
15+
16+
Homepage of PyOpenocdClient: https://github.com/HonzaMat/PyOpenocdClient
17+
18+
19+
.. toctree::
20+
:maxdepth: 1
21+
:caption: Contents:
22+
23+
installing
24+
quickstart
25+
apidocs

doc/py_openocd_client/installing.rst

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Installation
2+
============
3+
4+
|
5+
6+
Installing PyOpenocdClient via Pip
7+
----------------------------------
8+
9+
To install PyOpenocdClient, use Pip as usual to download and install
10+
the package from the PyPI repository:
11+
12+
.. code-block:: bash
13+
14+
$ python3 -m pip install PyOpenocdClient
15+
16+
|
17+
18+
Installing PyOpenocdClient from source
19+
--------------------------------------
20+
21+
.. note::
22+
This approach is only recommended for advanced users.
23+
24+
Alternatively, PyOpenocdClient can be installed directly from the source code.
25+
This may be useful for experiments or when making own contributions to PyOpenocdClient.
26+
27+
.. code-block:: bash
28+
29+
$ git clone https://github.com/HonzaMat/PyOpenocdClient.git
30+
$ cd PyOpenocdClient
31+
32+
# Optionally, check out a specific revision
33+
$ git checkout 0.1.0
34+
35+
$ python3 -m pip install .
36+

0 commit comments

Comments
 (0)