Description
I've had some issues with reference targets not being found in the summary table. This happens in multiple of my projects, but within each project, the problem was limited to some modules only. This is a bit annoying because you can't just click an object in the summary table and jump directly to its full documentation.
I think I've found the cause for the issue now. Let me give an example project structure.
my_module
├─ submodule1
├─ submodule2
submodule1.py
class MyClass1:
pass
submodule1.rst
.. automodule:: my_module.submodule1
:members:
:autosummary:
This will generate the following output:
.. py:module:: my_module.submodule1
**Classes:**
.. autosummary::
~my_module.submodule1.MyClass1
[...]
Everything works fine and all reference targets are found, until I add an import statement like import my_module.submodule2
to submodule1.py
. Why and how the in-code imports break the reference targets is something that I don't fully understand. But as soon as I import some other module from my own package, the reference targets in the module that contains the import statement are no longer found.
I've found that reference targets work correctly if I make a minor change to autodocsumm.
autodocsumm/autodocsumm/__init__.py
Lines 305 to 308 in 255292a
By changing Line 307 to indent + documenter.object_name, sourcename)
, reference targets work correctly for module and class summaries in all cases that I have tested.
The generated output after this is
.. py:module:: my_module.submodule1
**Classes:**
.. autosummary::
MyClass1
[...]
The visual representation of the summary table does not change because of this.
Edit: I forgot, this on Python 3.8 with Sphinx v4.4.0