Skip to content

Commit

Permalink
fix: no links generated in summary table (Chilipp#65, Chilipp#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
theOehrly authored and Chilipp committed Apr 19, 2022
1 parent 073d513 commit b75f248
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 6 deletions.
25 changes: 19 additions & 6 deletions autodocsumm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,15 @@ def get_grouped_documenters(self, all_members=False):
self.options.update(options_save)
return documenters

def add_autosummary(self):
"""Add the autosammary table of this documenter."""
def add_autosummary(self, relative_ref_paths=False):
"""Add the autosammary table of this documenter.
Parameters
==========
relative_ref_paths: bool
Use paths relative to the current module instead of
absolute import paths for each object
"""
if (
self.options.get("autosummary")
and not self.options.get("no-autosummary")
Expand All @@ -303,8 +310,14 @@ def add_autosummary(self):
indent = ' '

for (documenter, _) in documenters:
self.add_line(
indent + '~' + documenter.fullname, sourcename)
if relative_ref_paths:
obj_ref_path = documenter.fullname.lstrip(
self.modname + '.')
else:
obj_ref_path = documenter.fullname

self.add_line(indent + '~' + obj_ref_path, sourcename)

self.add_line('', sourcename)


Expand Down Expand Up @@ -351,7 +364,7 @@ class AutoSummModuleDocumenter(ModuleDocumenter, AutosummaryDocumenter):
def add_content(self, *args, **kwargs):
super().add_content(*args, **kwargs)

self.add_autosummary()
self.add_autosummary(relative_ref_paths=True)

if self.options.get("autosummary-no-nesting"):
self.options["no-autosummary"] = "True"
Expand Down Expand Up @@ -400,7 +413,7 @@ class AutoSummClassDocumenter(ClassDocumenter, AutosummaryDocumenter):
def add_content(self, *args, **kwargs):
super().add_content(*args, **kwargs)

self.add_autosummary()
self.add_autosummary(relative_ref_paths=True)


class CallableDataDocumenter(DataDocumenter):
Expand Down
Empty file.
9 changes: 9 additions & 0 deletions tests/test-root/dummy_submodule/submodule1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import dummy_submodule.submodule2


class SubmoduleClass1:
"""Docu for myclass 1"""

def func1(self):
"""Docu for func 1"""
pass
9 changes: 9 additions & 0 deletions tests/test-root/dummy_submodule/submodule2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import dummy_submodule.submodule1


class SubmoduleClass2:
"""Docu for myclass 1"""

def func2(self):
"""Docu for func 1"""
pass
2 changes: 2 additions & 0 deletions tests/test-root/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ Example documentation
test_automodulesumm
test_automodulesumm_some_sections
test_empty
test_class_submodule
test_module_submodule
4 changes: 4 additions & 0 deletions tests/test-root/test_class_submodule.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Test if links in summary are correctly generated
================================================

.. autoclass:: dummy_submodule.submodule1.SubmoduleClass1
4 changes: 4 additions & 0 deletions tests/test-root/test_module_submodule.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Test if links in summary are correctly generated
================================================

.. automodule:: dummy_submodule.submodule2
22 changes: 22 additions & 0 deletions tests/test_autodocsumm.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,28 @@ def test_autoclasssumm_inline(self, app):

assert docstring_end > methods_start

def test_class_submodule(self, app):
app.build()

html = get_html(app, '/test_class_submodule.html')

# check that hyperlink for instance method exists in summary table
assert re.findall(r'<td>.*href="#dummy_submodule\.submodule1'
r'\.SubmoduleClass1\.func1".*</td>', html)

def test_module_submodule(self, app):
app.build()

html = get_html(app, '/test_module_submodule.html')

# check that hyperlink for class exists in summary table
assert re.findall(r'<td>.*href="#dummy_submodule\.submodule2'
r'\.SubmoduleClass2".*</td>', html)

# check that hyperlink for instance method exists in summary table
assert re.findall(r'<td>.*href="#dummy_submodule\.submodule2'
r'\.SubmoduleClass2\.func2".*</td>', html)


class TestAutoDocSummDirective:
"""Test case for the :class:`autodocsumm.AutoDocSummDirective`."""
Expand Down

0 comments on commit b75f248

Please sign in to comment.