diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..2f8bb59 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,33 @@ +name: Build and Deploy Docs + +on: + push: + branches: + - main + +permissions: + contents: write + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: "3.x" + - name: Install dependencies + run: pip install sphinx sphinx_rtd_theme sphinx-autodoc-typehints myst-parser + - name: Build Docs + run: | + python .\docs\source\generate_class_list.py + cd docs + sphinx-apidoc -o .\source\ ..\src\ -M --no-toc + rm .\source\*.rst + make html + - name: Deploy to GitHub Pages + uses: JamesIves/github-pages-deploy-action@v4 + with: + branch: gh-pages + folder: docs/build/html diff --git a/docs/source/conf.py b/docs/source/conf.py new file mode 100644 index 0000000..7347e96 --- /dev/null +++ b/docs/source/conf.py @@ -0,0 +1,32 @@ +# 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("../src/")) + +project = 'pyhoff' +copyright = '2025, Nicolas Kruse' +author = 'Nicolas Kruse' + +# -- General configuration --------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration + +extensions = ["sphinx.ext.autodoc", "sphinx.ext.napoleon", "sphinx_autodoc_typehints", "myst_parser"] + +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_theme = 'sphinx_rtd_theme' +html_static_path = ['_static'] + +autodoc_inherit_docstrings = True diff --git a/docs/source/generate_class_list.py b/docs/source/generate_class_list.py new file mode 100644 index 0000000..41720ba --- /dev/null +++ b/docs/source/generate_class_list.py @@ -0,0 +1,44 @@ +import importlib +import inspect +import fnmatch +from io import TextIOWrapper + + +def write_classes(f: TextIOWrapper, patterns: list[str], module_name: str, title: str, description: str = '', exclude: list[str] = []) -> None: + + module = importlib.import_module(module_name) + + classes = [ + name for name, obj in inspect.getmembers(module, inspect.isclass) + if (obj.__module__ == module_name and + any(fnmatch.fnmatch(name, pat) for pat in patterns if pat not in exclude) and + obj.__doc__ and '(Automatic generated stub)' not in obj.__doc__) + ] + + """Write the classes to the file.""" + f.write(f'## {title}\n\n') + if description: + f.write(f'{description}\n\n') + + for cls in classes: + f.write('```{eval-rst}\n') + f.write(f'.. autoclass:: {module_name}.{cls}\n') + f.write(' :members:\n') + f.write(' :undoc-members:\n') + f.write(' :show-inheritance:\n') + f.write(' :inherited-members:\n') + if title != 'Base classes': + f.write(' :exclude-members: select\n') + f.write('```\n\n') + + +with open('docs/source/modules.md', 'w') as f: + f.write('# Classes\n\n') + write_classes(f, ['BK*', 'WAGO_750_352'], 'pyhoff.devices', title='Bus coupler', + description='These classes are bus couplers and are used to connect the IO bus terminals to a Ethernet interface.') + write_classes(f, ['KL*'], 'pyhoff.devices', title='Beckhoff bus terminals') + write_classes(f, ['WAGO*'], 'pyhoff.devices', title='WAGO bus terminals', exclude=['WAGO_750_352']) + write_classes(f, ['*'], 'pyhoff', title='Base classes', + description='These classes are base classes for devices and are typically not used directly.') + write_classes(f, ['*'], 'pyhoff.modbus', title='Modbus', + description='This modbus implementation is used internally.') diff --git a/docs/source/index.md b/docs/source/index.md new file mode 100644 index 0000000..7232e27 --- /dev/null +++ b/docs/source/index.md @@ -0,0 +1,10 @@ +```{toctree} +:maxdepth: 2 +:caption: Contents: + +readme +modules +``` + +```{include} ../../README.md +``` \ No newline at end of file diff --git a/docs/source/readme.md b/docs/source/readme.md new file mode 100644 index 0000000..060259b --- /dev/null +++ b/docs/source/readme.md @@ -0,0 +1,2 @@ +```{include} ../../README.md +``` \ No newline at end of file