Skip to content

Commit

Permalink
Add jinja templates for apidoc (#3)
Browse files Browse the repository at this point in the history
sphinx-apidoc now uses the *.rst.jinja name format
  • Loading branch information
rboghe authored Nov 1, 2024
1 parent 271f86d commit 2e5c4ce
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 11 deletions.
13 changes: 13 additions & 0 deletions docs/source/_templates/apidoc/module.rst.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{%- if show_headings %}
{{- basename.split(".")[-1] | e | heading }}
{% endif -%}

{%- set parts = basename.split('.') %}
{%- set library_name = parts[0] %}
{%- set module_name = parts[1] if parts | length > 1 else '' %}
{%- set submodules = parts[2:] %}

.. automodule:: {{ qualname }}
{%- for option in automodule_options %}
:{{ option }}:
{%- endfor %}
52 changes: 52 additions & 0 deletions docs/source/_templates/apidoc/package.rst.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{%- macro automodule(modname, options) -%}
.. automodule:: {{ modname }}
{%- for option in options %}
:{{ option }}:
{%- endfor %}
{%- endmacro %}

{%- macro toctree(docnames) -%}
.. toctree::
:maxdepth: {{ maxdepth }}
{% for docname in docnames %}
{{ docname }}
{%- endfor %}
{%- endmacro %}

{%- if is_namespace %}
{{- [pkgname, "namespace"] | join(" ") | e | heading }}
{% else %}
{{- pkgname.split(".")[-1] | e | heading }}
{% endif %}

{%- if is_namespace %}
.. py:module:: {{ pkgname }}
{% endif %}

{%- if modulefirst and not is_namespace %}
{{ automodule(pkgname, automodule_options) }}
{% endif %}

{%- if subpackages %}

{{ toctree(subpackages) }}
{% endif %}

{%- if submodules %}

{% if separatemodules %}
{{ toctree(submodules) }}
{% else %}
{%- for submodule in submodules %}
{% if show_headings %}
{{- submodule.split(".")[-1] | e | heading(2) }}
{% endif %}
{{ automodule(submodule, automodule_options) }}
{% endfor %}
{%- endif %}
{%- endif %}

{%- if not modulefirst and not is_namespace %}

{{ automodule(pkgname, automodule_options) }}
{% endif %}
13 changes: 3 additions & 10 deletions docs/source/_templates/apidoc/package.rst_t
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,14 @@
{% else %}
{%- for submodule in submodules %}
{% if show_headings %}

{# Create breadcrumb navigation #}
{%- set parts = submodule.split('.') -%}
{%- for i in range(parts|length) %}
{{ '[{}]({}.html)'.format(parts[i], '/'.join(parts[:i+1])) | e | heading(2) }}
{%- endfor %}

{%- endif %}
{{- submodule.split(".")[-1] | e | heading(2) }}
{% endif %}
{{ automodule(submodule, automodule_options) }}
{% endfor %}
{%- endif %}
{%- endif %}

{%- if not modulefirst and not is_namespace %}
Module contents
---------------

{{ automodule(pkgname, automodule_options) }}
{% endif %}
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"2024, Idiap Research Institute, https://www.idiap.ch, EPFL, https://www.epfl.ch"
)
author = "Roberto Boghetti"
release = "0.1.2"
release = "0.1.3"

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

0 comments on commit 2e5c4ce

Please sign in to comment.