Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: no links generated in summary table #70

Merged
merged 3 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 + '.')
Chilipp marked this conversation as resolved.
Show resolved Hide resolved
else:
obj_ref_path = documenter.fullname
Chilipp marked this conversation as resolved.
Show resolved Hide resolved

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