Skip to content

Commit afd6c27

Browse files
author
Foucher Alexandre
committed
add python example
1 parent 506be8b commit afd6c27

File tree

18 files changed

+412
-23
lines changed

18 files changed

+412
-23
lines changed

cpp-example/docs/source/conf.py

+17-21
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,35 @@
1111
author = 'Alexandre Foucher'
1212
release = '1.0'
1313

14+
# -- Options for HTML output -------------------------------------------------
15+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
16+
17+
html_theme = 'sphinx_rtd_theme'
18+
html_static_path = ['_static']
19+
1420
# -- General configuration ---------------------------------------------------
1521
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
1622

17-
extensions = [
18-
'breathe',
19-
'exhale'
20-
]
23+
extensions = []
24+
25+
templates_path = ['_templates']
26+
exclude_patterns = []
27+
28+
language = 'fr'
29+
30+
# -----------------------------------------------------------------------------
31+
32+
extensions += ['breathe','exhale']
2133

2234
breathe_projects = {"My Project": "../build/_doxygen/xml"}
2335
breathe_default_project = "My Project"
2436

2537
exhale_args = {
26-
# These arguments are required
2738
"containmentFolder": "./api",
2839
"rootFileName": "library_root.rst",
2940
"doxygenStripFromPath": "..",
30-
# Heavily encouraged optional argument (see docs)
3141
"rootFileTitle": "Library API",
32-
# Suggested optional arguments
3342
"createTreeView": True,
34-
# TIP: if using the sphinx-bootstrap-theme, you need
35-
# "treeViewIsBootstrap": True,
3643
"exhaleExecutesDoxygen": True,
3744
"exhaleDoxygenStdin": "INPUT = ../../include"
38-
}
39-
40-
templates_path = ['_templates']
41-
exclude_patterns = []
42-
43-
language = 'fr'
44-
45-
# -- Options for HTML output -------------------------------------------------
46-
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
47-
48-
html_theme = 'shibuya'
49-
html_static_path = ['_static']
45+
}

cpp-example/readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
```sh
1010
# Installing dependencies
11-
pip3 install sphinx shibuya breathe exhale
11+
pip3 install sphinx sphinx_rtd_theme breathe exhale
1212
sudo apt-get install doxygen
1313

1414
# Generating documentation
@@ -85,5 +85,5 @@ The best way is to go in `source/index.rst` and add `api/library_root` as an ent
8585
Inside the `docs` directory you can now execute `make html` !
8686
You can acces it through `docs/build/html/index.html`.
8787

88-
> :warning: **Warning**
88+
> **Warning**
8989
> Do not store the `build` folder in your remote storage, if you use `git` simply copy the `.gitignore` inside `cpp-example/docs` and paste it to your `docs` folder.

py-example/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/__pycache__/

py-example/docs/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/
2+
source/api

py-example/docs/Makefile

+20
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 = source
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)

py-example/docs/make.bat

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=source
11+
set BUILDDIR=build
12+
13+
%SPHINXBUILD% >NUL 2>NUL
14+
if errorlevel 9009 (
15+
echo.
16+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
17+
echo.installed, then set the SPHINXBUILD environment variable to point
18+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
19+
echo.may add the Sphinx directory to PATH.
20+
echo.
21+
echo.If you don't have Sphinx installed, grab it from
22+
echo.https://www.sphinx-doc.org/
23+
exit /b 1
24+
)
25+
26+
if "%1" == "" goto help
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
:orphan:
2+
3+
{{ fullname | escape | underline}}
4+
5+
.. currentmodule:: {{ module }}
6+
7+
attribute
8+
9+
.. auto{{ objtype }}:: {{ fullname | replace("numpy.", "numpy::") }}
10+
11+
{# In the fullname (e.g. `numpy.ma.MaskedArray.methodname`), the module name
12+
is ambiguous. Using a `::` separator (e.g. `numpy::ma.MaskedArray.methodname`)
13+
specifies `numpy` as the module name. #}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{% if objtype == 'property' %}
2+
:orphan:
3+
{% endif %}
4+
5+
{{ fullname | escape | underline}}
6+
7+
.. currentmodule:: {{ module }}
8+
9+
{% if objtype == 'property' %}
10+
property
11+
{% endif %}
12+
13+
.. auto{{ objtype }}:: {{ fullname | replace("numpy.", "numpy::") }}
14+
15+
{# In the fullname (e.g. `numpy.ma.MaskedArray.methodname`), the module name
16+
is ambiguous. Using a `::` separator (e.g. `numpy::ma.MaskedArray.methodname`)
17+
specifies `numpy` as the module name. #}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{% extends "!autosummary/class.rst" %}
2+
3+
{% block methods %}
4+
{% if methods %}
5+
.. HACK -- the point here is that we don't want this to appear in the output, but the autosummary should still generate the pages.
6+
.. autosummary::
7+
:toctree:
8+
{% for item in all_methods %}
9+
{%- if not item.startswith('_') or item in ['__call__'] %}
10+
{{ name }}.{{ item }}
11+
{%- endif -%}
12+
{%- endfor %}
13+
{% endif %}
14+
{% endblock %}
15+
16+
{% block attributes %}
17+
{% if attributes %}
18+
.. HACK -- the point here is that we don't want this to appear in the output, but the autosummary should still generate the pages.
19+
.. autosummary::
20+
:toctree:
21+
{% for item in all_attributes %}
22+
{%- if not item.startswith('_') %}
23+
{{ name }}.{{ item }}
24+
{%- endif -%}
25+
{%- endfor %}
26+
{% endif %}
27+
{% endblock %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
:orphan:
2+
3+
{{ fullname | escape | underline}}
4+
5+
.. currentmodule:: {{ module }}
6+
7+
member
8+
9+
.. auto{{ objtype }}:: {{ fullname | replace("numpy.", "numpy::") }}
10+
11+
{# In the fullname (e.g. `numpy.ma.MaskedArray.methodname`), the module name
12+
is ambiguous. Using a `::` separator (e.g. `numpy::ma.MaskedArray.methodname`)
13+
specifies `numpy` as the module name. #}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
:orphan:
2+
3+
{{ fullname | escape | underline}}
4+
5+
.. currentmodule:: {{ module }}
6+
7+
method
8+
9+
.. auto{{ objtype }}:: {{ fullname | replace("numpy.", "numpy::") }}
10+
11+
{# In the fullname (e.g. `numpy.ma.MaskedArray.methodname`), the module name
12+
is ambiguous. Using a `::` separator (e.g. `numpy::ma.MaskedArray.methodname`)
13+
specifies `numpy` as the module name. #}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{{ fullname | escape | underline}}
2+
3+
.. automodule:: {{ fullname }}
4+
5+
{% block docstring %}
6+
{% endblock %}
7+
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{% extends "!autosummary/module.rst" %}
2+
3+
{# This file is almost the same as the default, but adds :toctree: to the autosummary directives.
4+
The original can be found at `sphinx/ext/autosummary/templates/autosummary/module.rst`. #}
5+
6+
{% block attributes %}
7+
{% if attributes %}
8+
.. rubric:: Module Attributes
9+
10+
.. autosummary::
11+
:toctree:
12+
{% for item in attributes %}
13+
{{ item }}
14+
{%- endfor %}
15+
{% endif %}
16+
{% endblock %}
17+
18+
{% block functions %}
19+
{% if functions %}
20+
.. rubric:: Functions
21+
22+
.. autosummary::
23+
:toctree:
24+
{% for item in functions %}
25+
{{ item }}
26+
{%- endfor %}
27+
{% endif %}
28+
{% endblock %}
29+
30+
{% block classes %}
31+
{% if classes %}
32+
.. rubric:: Classes
33+
34+
.. autosummary::
35+
:toctree:
36+
{% for item in classes %}
37+
{{ item }}
38+
{%- endfor %}
39+
{% endif %}
40+
{% endblock %}

py-example/docs/source/conf.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# For the full list of built-in configuration values, see the documentation:
4+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
5+
6+
# -- Project information -----------------------------------------------------
7+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
8+
9+
project = 'py-example'
10+
copyright = '2024, Alexandre Foucher'
11+
author = 'Alexandre Foucher'
12+
release = '1.0'
13+
14+
# -- General configuration ---------------------------------------------------
15+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
16+
17+
extensions = []
18+
19+
templates_path = ['_templates']
20+
exclude_patterns = []
21+
22+
language = 'fr'
23+
24+
# -- Options for HTML output -------------------------------------------------
25+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
26+
27+
html_theme = "sphinx_rtd_theme"
28+
html_static_path = ['_static']
29+
30+
import os
31+
import sys
32+
sys.path.insert(0, os.path.abspath('../..'))
33+
print(os.path.abspath('../..'))
34+
35+
extensions += [
36+
'sphinx.ext.napoleon',
37+
'sphinx.ext.autodoc',
38+
'sphinx.ext.autosummary'
39+
]
40+
41+
autosummary_generate = True

py-example/docs/source/index.rst

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.. py-example documentation master file, created by
2+
sphinx-quickstart on Wed Jan 24 17:28:52 2024.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
Welcome to py-example's documentation!
7+
======================================
8+
9+
.. toctree::
10+
:maxdepth: 2
11+
:caption: Contents:
12+
13+
api
14+
15+
API
16+
---
17+
18+
.. autosummary::
19+
:toctree: api
20+
:recursive:
21+
22+
pyexample
23+
24+
Indices and tables
25+
==================
26+
27+
* :ref:`genindex`
28+
* :ref:`modindex`
29+
* :ref:`search`

py-example/pyexample/Driver.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
class Driver:
2+
"""
3+
Driver for specific sensor
4+
5+
Attributes
6+
----------
7+
name : str
8+
Name of the sensor
9+
10+
Methods
11+
-------
12+
write(buffer):
13+
Send data to the sensor.
14+
"""
15+
16+
def __init__(self, name:str):
17+
"""
18+
Constructs all the necessary attributes for the driver object.
19+
20+
Parameters
21+
----------
22+
name : str
23+
Name of the sensor
24+
"""
25+
26+
self.name = name
27+
28+
def write(self, buffer:str) -> int:
29+
"""
30+
Send data buffer to the sensor.
31+
32+
Parameters
33+
----------
34+
buffer : str
35+
Data buffer to be send
36+
37+
Returns
38+
-------
39+
status_code : int
40+
status code of the operation SUCCES, FAILURE
41+
"""
42+
43+
# Do something
44+
return 0

py-example/pyexample/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)