Skip to content

Commit

Permalink
Replace sphinx napoleon for numpydoc (#195)
Browse files Browse the repository at this point in the history
Add `numpydoc` to requirements for building the docs. Add `numpydoc` to
Sphinx configuration file. Update Sphinx template for classes. Move
admonitions in `Ellipsoid` and `Sphere` classes to the Notes section so
`numpydoc` can render them properly.
  • Loading branch information
santisoler authored Oct 15, 2024
1 parent 2a60a68 commit 0cb2fa2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 22 deletions.
2 changes: 2 additions & 0 deletions boule/_ellipsoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class Ellipsoid:
comments : str or None
Additional comments regarding the ellipsoid (optional).
Notes
-----
.. caution::
Expand Down
2 changes: 2 additions & 0 deletions boule/_sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class Sphere:
comments : str or None
Additional comments regarding the ellipsoid (optional).
Notes
-----
.. caution::
Expand Down
21 changes: 5 additions & 16 deletions doc/_templates/autosummary/class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,25 @@ Attributes
----------

{% for item in attributes %}

.. autoattribute:: {{ objname }}.{{ item }}

{% endfor %}

{% endif %}

Methods
-------

.. rubric:: List of methods

.. autosummary::
{% for item in methods %}
{% if item != "__init__" %}
{{ objname }}.{{ item }}
{% endif %}
{% endfor %}
{% if methods %}

.. rubric:: Methods documentation
Methods
-------

{% for item in methods %}
{% if item != '__init__' %}
.. automethod:: {{ objname }}.{{ item }}

----

{% endif %}
{% endfor %}

{% endif %}

.. raw:: html

<div style='clear:both'></div>
Expand Down
13 changes: 7 additions & 6 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"numpydoc",
"sphinx.ext.coverage",
"sphinx.ext.mathjax",
"sphinx.ext.doctest",
"sphinx.ext.viewcode",
"sphinx.ext.extlinks",
"sphinx.ext.intersphinx",
"sphinx.ext.napoleon",
"sphinx_design",
"sphinx_copybutton",
"jupyter_sphinx",
Expand All @@ -48,11 +48,12 @@
# Autosummary pages will be generated by sphinx-autogen instead of sphinx-build
autosummary_generate = []

# Otherwise, the Return parameter list looks different from the Parameters list
napoleon_use_rtype = False
# Otherwise, the Attributes parameter list looks different from the Parameters
# list
napoleon_use_ivar = True
# Create cross-references for the parameter types in the Parameters, Other
# Parameters, Returns and Yields sections of the docstring
numpydoc_xref_param_type = True

# Format the Attributes like the Parameters section.
numpydoc_attributes_as_param_list = True

# Sphinx project configuration
templates_path = ["_templates"]
Expand Down
1 change: 1 addition & 0 deletions env/requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Requirements for building the documentation
sphinx==7.2.*
numpydoc==1.7.*
sphinx-book-theme==1.1.*
sphinx-copybutton==0.5.*
sphinx-design==0.5.*
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies:
- pymap3d>=2.9
# Documentation
- sphinx==7.2.*
- numpydoc==1.7.*
- sphinx-book-theme==1.1.*
- sphinx-copybutton==0.5.*
- sphinx-design==0.5.*
Expand Down

0 comments on commit 0cb2fa2

Please sign in to comment.