Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Automatic Code Documentation #698

Merged
merged 30 commits into from Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
58fc26f
docs: automatic generation of code documentation
victorgarcia98 May 24, 2023
51b4f7c
docs: class and module templates
victorgarcia98 May 24, 2023
0010661
fix: simplify generated docs
victorgarcia98 May 24, 2023
1c0ddbc
feat: switch on/off generation of code docs via the parameter gen_cod…
victorgarcia98 May 24, 2023
4e22c78
add docstrings for main modules
nhoening May 26, 2023
a1c64a5
Add docstrings to API modules
nhoening May 26, 2023
7486a87
fix: add autodoc and autosmmary when GEN_CODE_DOCS=True
victorgarcia98 May 29, 2023
7eb4771
fix: set gen_code_docs default to True and False for devs (calling up…
victorgarcia98 May 29, 2023
93c502e
Merge branch 'main' into 52-incomplete-documentation-of-internal-modules
victorgarcia98 May 29, 2023
dc7bf84
Merge branch 'main' into 52-incomplete-documentation-of-internal-modules
victorgarcia98 May 30, 2023
5dba038
move single test from config package into new tests package
nhoening Jun 6, 2023
76c7315
fix: show main modules
victorgarcia98 Jun 7, 2023
6f67b12
fix: remove documentation/_autosummary when gen_code_docs=False
victorgarcia98 Jun 7, 2023
a557df2
fix: make generated rst to live under _autosummary/ folder
victorgarcia98 Jun 7, 2023
a49ae85
add autosummary folder to .gitignore
nhoening Jun 7, 2023
8d7ff4a
add some spellright words
nhoening Jun 7, 2023
a569f3f
try setting FLASK_ENV during RTD building
nhoening Jun 7, 2023
7dadf17
fix: set a fake SQLALCHEMY_DATABASE_URI
victorgarcia98 Jun 7, 2023
fbb5a4f
Merge remote-tracking branch 'origin/52-incomplete-documentation-of-i…
victorgarcia98 Jun 7, 2023
36b47ea
no need to look for config file when building documentation
nhoening Jun 7, 2023
72747a6
Merge branch '52-incomplete-documentation-of-internal-modules' of git…
nhoening Jun 7, 2023
94a00e2
also export SECRET_KEY in RTD
nhoening Jun 7, 2023
cb6d9e8
test add SECRET_KEY
victorgarcia98 Jun 7, 2023
b66ca03
Merge remote-tracking branch 'origin/52-incomplete-documentation-of-i…
victorgarcia98 Jun 7, 2023
23b5595
docs: add private methods
victorgarcia98 Jun 7, 2023
777ee3f
test only with env variables set in conf.py
victorgarcia98 Jun 8, 2023
f0720ce
test
victorgarcia98 Jun 8, 2023
e0c6373
fix: remove exports
victorgarcia98 Jun 8, 2023
78724fa
re-do a change to a comment that is by now inaccurate and improve the…
nhoening Jun 9, 2023
1bfcf83
Merge branch 'main' into 52-incomplete-documentation-of-internal-modules
nhoening Jun 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/spellright.dict
Expand Up @@ -251,3 +251,4 @@ Changelog
Bugfixes
Dockerfile
nt
Backoffice
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -18,14 +18,14 @@ update-docs:
@echo "Creating docs environment ..."
make install-docs-dependencies
@echo "Creating documentation ..."
cd documentation; make clean; make html SPHINXOPTS="-W --keep-going -n"; cd ..
export GEN_CODE_DOCS=${gen_code_docs}; cd documentation; make clean; make html SPHINXOPTS="-W --keep-going -n"; cd ..

update-docs-pdf:
@echo "NOTE: PDF documentation requires packages (on Debian: latexmk texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended)"
@echo "NOTE: Currently, the docs require some pictures which are not in the git repo atm. Ask the devs."
make install-sphinx-tools

cd documentation; make clean; make latexpdf; make latexpdf; cd .. # make latexpdf can require two passes
export GEN_CODE_DOCS=${gen_code_docs}; cd documentation; make clean; make latexpdf; make latexpdf; cd .. # make latexpdf can require two passes

# ---- Installation ---

Expand Down
66 changes: 66 additions & 0 deletions documentation/_templates/custom-module-template.rst
@@ -0,0 +1,66 @@
.. Adapted from https://stackoverflow.com/a/62613202
{{ fullname | escape | underline}}

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

.. autosummary::
:toctree:
:template: custom-module-template.rst
:recursive:
{% for item in modules %}
{% if "test" not in item %}
{{ item }}
{% endif %}
{%- endfor %}
{% endif %}
{% endblock %}

.. automodule:: {{ fullname }}

{% block attributes %}
{% if attributes %}
.. rubric:: Module Attributes


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

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

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

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

{% for item in classes %}
.. autoclass:: {{ item }}
:members:
:special-members: __init__
{%- endfor %}
{% endif %}
{% endblock %}

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

{% for item in exceptions %}
.. autoexception::
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
19 changes: 18 additions & 1 deletion documentation/conf.py
Expand Up @@ -6,6 +6,8 @@
# full list see the documentation:
# http://www.sphinx-doc.org/en/stable/config

import os

from datetime import datetime
from pkg_resources import get_distribution
import sphinx_fontawesome
Expand Down Expand Up @@ -52,11 +54,20 @@
"sphinx_fontawesome",
"sphinxcontrib.autohttp.flask",
"sphinxcontrib.autohttp.flaskqref",
"sphinx.ext.autosummary",
"sphinx.ext.autodoc.typehints",
]

autodoc_default_options = {}

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

# generate autosummary even if no references
victorgarcia98 marked this conversation as resolved.
Show resolved Hide resolved
autosummary_generate = bool(
os.environ.get("GEN_CODE_DOCS", "False").lower() in ("t", "true", "1")
)

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
Expand All @@ -76,7 +87,7 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path .
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "_templates"]

# Todo: these are not mature enough yet for release, or should be removed
exclude_patterns.append("int/*.rst")
Expand Down Expand Up @@ -224,3 +235,9 @@ def setup(sphinx_app):
"live",
"env", # hard-coded, documentation is not server-specific for the time being
)

if autosummary_generate:

from flexmeasures.app import create

create() # we need to create the app for when sphinx imports modules that use current_app
14 changes: 11 additions & 3 deletions documentation/index.rst
Expand Up @@ -249,11 +249,19 @@ The platform operator of FlexMeasures can be an Aggregator.
dev/docker-compose


.. autosummary::
:caption: Code Documentation
:toctree: _autosummary
:template: custom-module-template.rst
:recursive:

Code documentation
------------------
flexmeasures

Go To :ref:`source`.

.. Code documentation
.. ------------------

.. Go To :ref:`source`.



Expand Down
78 changes: 0 additions & 78 deletions documentation/source.rst

This file was deleted.

4 changes: 4 additions & 0 deletions flexmeasures/api/__init__.py
@@ -1,3 +1,7 @@
"""
FlexMeasures API routes and implementations.
"""

from flask import Flask, Blueprint, request
from flask_security.utils import verify_password
from flask_json import as_json
Expand Down
4 changes: 4 additions & 0 deletions flexmeasures/app.py
@@ -1,3 +1,7 @@
"""
Starting point of the Flask application.
"""

from __future__ import annotations

import time
Expand Down
9 changes: 4 additions & 5 deletions flexmeasures/auth/__init__.py
@@ -1,3 +1,7 @@
"""
Authentication and authorization policies and helpers.
"""

from flask import Flask
from flask_security import Security, SQLAlchemySessionUserDatastore
from flask_login import user_logged_in, current_user
Expand All @@ -6,11 +10,6 @@
from flexmeasures.data import db


"""
Configure authentication and authorization.
"""


def register_at(app: Flask):

from flexmeasures.auth.error_handling import (
Expand Down
4 changes: 4 additions & 0 deletions flexmeasures/cli/__init__.py
@@ -1,3 +1,7 @@
"""
CLI functions for FlexMeasures hosts.
"""

import sys

from flask import Flask, current_app
Expand Down
4 changes: 4 additions & 0 deletions flexmeasures/data/__init__.py
@@ -1,3 +1,7 @@
"""
Models & schemata, as well as business logic (queries & services).
"""

import os

from flask import Flask
Expand Down
4 changes: 4 additions & 0 deletions flexmeasures/ui/__init__.py
@@ -1,3 +1,7 @@
"""
Backoffice user interface & charting support.
"""

import os

from flask import current_app, Flask, Blueprint
Expand Down