Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning][].
### Fixed

- header shadow now only extends downward (#70)
- the autosummary class template now correctly handles classes referenced through aliased modules (#71)

## [0.2.3]

Expand Down
7 changes: 5 additions & 2 deletions src/scverse_doc/autodoc/templates/autosummary/class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
.. autoclass:: {{ fullname }}

{% set methods = methods | select("ne", "__init__") | list %}
{#- Inside autoclass, names resolve against the class’s real module, so prefix the class name:
`objname` can go through a module alias, and bare members break autosummary’s instance attribute fallback. #}
{% set clsname = fullname.split(".") | last %}

{% block attributes %}
{% for item in attributes %}
Expand All @@ -16,7 +19,7 @@

.. autosummary::
{% endif %}
~{{ [objname, item] | join(".") }}
~{{ [clsname, item] | join(".") }}
{%- endfor %}
{% endblock %}

Expand All @@ -28,7 +31,7 @@

.. autosummary::
{% endif %}
~{{ [objname, item] | join(".") }}
~{{ [clsname, item] | join(".") }}
{% endfor %}
{% endblock %}

Expand Down
2 changes: 2 additions & 0 deletions tests/roots/autodoc/apipkg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# SPDX-License-Identifier: MPL-2.0
"""A package to document recursively."""

from ._core import aliased # noqa: F401
2 changes: 2 additions & 0 deletions tests/roots/autodoc/apipkg/_core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# SPDX-License-Identifier: MPL-2.0
"""Private implementation, re-exported under public names."""
12 changes: 12 additions & 0 deletions tests/roots/autodoc/apipkg/_core/aliased.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPDX-License-Identifier: MPL-2.0
"""A module only reachable through an alias, i.e. not importable as `apipkg.aliased`."""


class Aliased:
"""A class in an aliased module."""

attr: int = 1
"""An attribute."""

def meth(self) -> None:
"""A method."""
8 changes: 8 additions & 0 deletions tests/roots/autodoc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ API

apipkg

.. currentmodule:: apipkg

.. autosummary::
:toctree: generated
:recursive:

aliased

.. currentmodule:: apimod

.. autosummary::
Expand Down
6 changes: 6 additions & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ def test_class_template_documents_members_by_kind(autodoc: Path) -> None:
assert 'href="#apimod.Thing.ivar"' in html


def test_class_template_handles_aliased_modules(autodoc: Path) -> None:
html = (autodoc / "generated" / "apipkg.aliased.Aliased.html").read_text()
assert 'href="#apipkg.aliased.Aliased.attr"' in html
assert 'href="#apipkg.aliased.Aliased.meth"' in html


def test_module_template_recurses(autodoc: Path) -> None:
assert (autodoc / "generated" / "apipkg.sub.deep.html").is_file()

Expand Down
Loading