Skip to content

Commit 13933a5

Browse files
authored
👌 Allow names starting ~ in autodoc2-summary (#12)
1 parent 58be3fe commit 13933a5

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

docs/apidocs/autodoc2/autodoc2.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ API
6161

6262
.. py:data:: __version__
6363
:canonical: autodoc2.__version__
64-
:value: '0.3.0'
64+
:value: '0.4.2'
6565

6666
.. autodoc2-docstring:: autodoc2.__version__
6767

docs/summary.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ For example, the following:
1010
:renderer: myst
1111
1212
aiida.orm.Node
13+
~aiida.orm.Dict
1314
autodoc2.sphinx.docstring._example my example
1415
````
1516

@@ -19,13 +20,15 @@ creates:
1920
:renderer: myst
2021
2122
aiida.orm.Node
23+
~aiida.orm.Dict
2224
autodoc2.sphinx.docstring._example my example
2325
```
2426

2527
Note that fully qualified names can be used to refer to objects in other packages,
2628
and they will also resolve against public API names, i.e. if the object is specified in an `__all__` variable.
2729

28-
Any text after the fully qualified name will be used as the title for the object.
30+
Any text after the fully qualified name will be used as the title for the object,
31+
or alternatively, if the name begins with `~` then the last component will be used as the title.
2932

3033
The `:renderer:` option can also be used to specify the renderer to use for the summary.
3134

src/autodoc2/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Analyse a python project and create documentation for it."""
22

3-
__version__ = "0.4.1"
3+
__version__ = "0.4.2"
44

55

66
def setup(app): # type: ignore

src/autodoc2/sphinx/summary.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ def run(self) -> list[nodes.Node]:
5050
continue
5151
full_name = parts[0]
5252
alias: str | None = None
53+
if full_name.startswith("~"):
54+
full_name = full_name[1:]
55+
alias = full_name.split(".")[-1]
5356
if len(parts) > 1:
5457
alias = parts[1]
5558
if (item := db.get_item(full_name)) is None and (
@@ -63,7 +66,9 @@ def run(self) -> list[nodes.Node]:
6366
self.env.note_dependency(file_path)
6467
break
6568
if alias:
66-
aliases[full_name] = alias
69+
aliases[item["full_name"]] = alias
70+
elif full_name != item["full_name"]:
71+
aliases[item["full_name"]] = full_name
6772
objects.append(item)
6873
else:
6974
warn_sphinx(

tests/test_render/test_sphinx_build_directives.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@
6969
<row>
7070
<entry>
7171
<paragraph>
72-
<pending_xref py:class="True" py:module="True" refdoc="index" refdomain="py" refexplicit="False" reftarget="package.a.a1" reftype="obj" refwarn="False">
72+
<pending_xref py:class="True" py:module="True" refdoc="index" refdomain="py" refexplicit="True" reftarget="package.a.a1" reftype="obj" refwarn="False">
7373
<literal classes="xref py py-obj">
74-
package.a.a1
74+
package.a1
7575
<entry>
7676
<paragraph>
7777
a1 can be documented here.

0 commit comments

Comments
 (0)