Skip to content

Commit

Permalink
Merge pull request #6 from Hierosoft/main
Browse files Browse the repository at this point in the history
Get upstream examples. This branch is based on zeroconf-example except cdi attribute and pasted updates from upstream.
  • Loading branch information
Poikilos authored May 29, 2024
2 parents 061d7cd + 94a4a6a commit 2f23c2b
Show file tree
Hide file tree
Showing 15 changed files with 431 additions and 15 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@
/*.bad_json.txt
/settings.json
/.vscode/settings.json
# ^ /.vscode/settings.json is ignored since it may have python.defaultInterpreterPath with differs depending on the specific machine. Recommended: place that setting in there ("PythonOlcbNode Folder" tab in VSCode settings)
# ^ /.vscode/settings.json is ignored since it may have python.defaultInterpreterPath with differs depending on the specific machine. Recommended: place that setting in there ("PythonOlcbNode Folder" tab in VSCode settings)
/build
/doc/_autosummary
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = doc
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Linux:
mkdir -p ~/.virtualenvs
python3 -m venv ~/.virtualenvs/pytest-env
source ~/.virtualenvs/pytest-env/bin/activate
```
```

Windows:
```
Expand Down Expand Up @@ -51,11 +51,21 @@ If using VSCode (or fully open-source VSCodium):
- (recommended) **autoDocstring**: Type `"""` below a method or class and it will create a Sphinx-style template for you.
- The workspace file has `"autoDocstring.docstringFormat": "google"` set since Google style is widely used and comprehensive (documents types etc).

#### Documentation
The sources for building documentation are:
- rst (reStructuredText) file(s) in the doc directory
- Google-style docstrings which is one of the formats recognized by Sphinx (and one with a thorough explanation of input and output types).

To generate documentation that can be placed on a website (such as could be published to readthedocs.io automatically) or provided to end users, run:
```
make html
```

### Testing
To run the unit test suite:
```
python3 -m pip install --user pytest
# ^ or use a
# ^ or use a
python3 -m pytest
# or to auto-detect test and run with standard log level:
# python3 -m pytest tests
Expand Down Expand Up @@ -84,7 +94,7 @@ python3 example_node_implementation.py 192.168.1.40
python3 example_node_implementation.py 192.168.1.40:12021
```

There's also a serial-port based example.
There's also a serial-port based example.
```
python3 example_string_serial_interface.py /dev/cu.ProperSerialPort
```
Expand Down
32 changes: 32 additions & 0 deletions doc/_templates/custom-class-template.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{ fullname | escape | underline}}

.. currentmodule:: {{ module }}

.. autoclass:: {{ objname }}
:members:
:show-inheritance:
:inherited-members:

{% block methods %}
.. automethod:: __init__

{% if methods %}
.. rubric:: {{ _('Methods') }}

.. autosummary::
{% for item in methods %}
~{{ name }}.{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block attributes %}
{% if attributes %}
.. rubric:: {{ _('Attributes') }}

.. autosummary::
{% for item in attributes %}
~{{ name }}.{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
66 changes: 66 additions & 0 deletions doc/_templates/custom-module-template.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{{ fullname | escape | underline}}

.. automodule:: {{ fullname }}

{% block attributes %}
{% if attributes %}
.. rubric:: {{ _('Module Attributes') }}

.. autosummary::
:toctree:
{% for item in attributes %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block functions %}
{% if functions %}
.. rubric:: {{ _('Functions') }}

.. autosummary::
:toctree:
{% for item in functions %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block classes %}
{% if classes %}
.. rubric:: {{ _('Classes') }}

.. autosummary::
:toctree:
:template: custom-class-template.rst
{% for item in classes %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block exceptions %}
{% if exceptions %}
.. rubric:: {{ _('Exceptions') }}

.. autosummary::
:toctree:
{% for item in exceptions %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block modules %}
{% if modules %}
.. rubric:: Modules

.. autosummary::
:toctree:
:template: custom-module-template.rst
:recursive:
{% for item in modules %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
38 changes: 38 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

import os
import sys
sys.path.insert(0, os.path.abspath('..'))

project = 'python-openlcb'
copyright = '2024, Bob Jacobsen'
author = 'Bob Jacobsen'
release = '0.1.0'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.coverage',
'sphinx.ext.napoleon', # understands NumPy and Google docstrings.
]
autosummary_generate = True # Turn on sphinx.ext.autosummary

templates_path = ['_templates']
exclude_patterns = []



# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'alabaster'
html_static_path = ['_static']
49 changes: 49 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.. python-openlcb documentation master file, created by
sphinx-quickstart on Thu May 16 16:30:21 2024.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to python-openlcb's documentation!
==========================================
.. autosummary::
:toctree: _autosummary
:template: custom-module-template.rst
:recursive:

openlcb

.. toctree::
:maxdepth: 2
:caption: Contents:

.. image:: Overview.png
:width: 400
:alt: Flowchart of the software-defined node's network connection

For how this documentation is built into html, see README.md or create a github workflow to publish it to readthedocs.io.

For general info on how the "docbuild" was configured, see the following sources which where used:

- Install Sphinx: https://www.sphinx-doc.org/en/master/usage/installation.html

- Setup autodoc: https://eikonomega.medium.com/getting-started-with-sphinx-autodoc-part-1-2cebbbca5365

- Setup recursive gathering of docstrings using autosummary: https://stackoverflow.com/a/62613202/4541104

Instructions for adding new documentation:

- Use Google-style docstrings (Sphinx will automatically generate documentation sections for such docstrings when `make html` runs).

- For bullet lists within docstrings, reStructuredText must be used (blank line before each bullet).

- For additional text that is manually entered (not generated from docstrings),
use the reStructuredText format and add data to this file or other rst files
(in the "doc" folder in the case of this project, as configured in make.bat
and Makefile).

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
Loading

0 comments on commit 2f23c2b

Please sign in to comment.