In short, I have code that works but if I make a slight tweak, some things fall apart and I can't seem to figure out why. I'm hoping someone more experienced than me can give me a few Sphinx pointers. I've searched and haven't seen anything like this issue posted before.
Thing that works
I have package my_pkg
that contains module mod
that contains a number of classes and functions.
If I use the following line in my conf.py
sys.path.insert(0, os.path.abspath('../my_pkg'))
and one of my .rst files contains the following
.. automodule:: mod
.. autoclass:: mod.classA
:members:
.. autofunction:: mod.functionA
.. autoclass:: mod.classB
:members:
then when I run my documentation everything works! However, these render the call signatures in the output documentation as mod.classA (for instance) and I'd rather they render as my_pkg.mod.classA.
Thing that doesn't work
To make this change, I thought I should remove pkg from conf.py
like so
sys.path.insert(0, os.path.abspath('../my_pkg'))
and then change my .rst file to start looking from pkg like the following:
.. automodule:: my_pkg.mod
.. autoclass:: my_pkg.mod.classA
:members:
.. autofunction:: my_pkg.mod.functionA
.. autoclass:: my_pkg.mod.classB
:members:
If I do this, the automodule directive doesn't pick up on anything and therefore doesn't show my module's docstring (I don't get any warnings about autodoc being unable to find pkg.mod, so I find this bizarre). The output for
.. autoclass:: my_pkg.mod.classA
:members:
is simply alias of my_pkg.mod.
... even though that's wrong. Despite this, the "source" button in the class signature correctly links to the code for that class. Finally, the remaining function and class render precisely as I want them to. It just appears Sphinx really doesn't want to document this module or classA for some reason.
This problem is driving me bonkers. It happens across multiple themes, so I believe it's a Sphinx issue. I've tried changing the docstring of classA to be just """foo""". I've tried moving classA around in the document so it's not the first bit of real code. I've tried renaming classA. Nothing seems to fix it and classA is always the problem.
Does anyone know why this could happen? I'm using Sphinx v4.1.1 and sphinx-rtd-theme v0.5.2 (the latest versions of both at the time of this post).