Reputation: 121
I am new to both Python and Sphinx and am attempting to autodoc python files located in a directory structured similar to the following:
Project
├── Sphinx
| ├── index.rst
| ├── autodoc.rst
| └── conf.py
├── Scripts
| ├── file1.py
| └── file2.py
| ├── folder
| | └── file3.py
My conf.py file contains:
sys.path.insert(0, os.path.abspath("../Scripts/"))
And autodoc contains:
.. automodule:: file1
:members:
.. automodule:: file2
:members:
.. automodule:: folder.file3
:members:
File3.py is not autodoc'ing correctly (Error: No module named metric.billpay)
I've also tried:
.. automodule:: folder/file3
:members:
But I receive
WARNING: invalid signature for automodule (u'folder/file3')
WARNING: don't know which module to import for autodocumenting u'folder/file3' (try placing a "module" or "currentmodule" directive in the document, or giving an explicit module name)
Does anyone know how to fix this? I am new to Python, Sphinx, and StackOverflow, so my apologies if there are problems with this question.
Upvotes: 4
Views: 5801
Reputation: 5192
I strongly suspect there was no __init__.py
in the Scripts
folder.
Adding to the sys.path
is something you should only need at the root, it at all (better to be in an environment where the PYTHONPATH
environment variable is correctly set to have the packages found.
The only exception I sometimes find to this is if I need to add a tests folder in addition to my main source folder.
Upvotes: 0
Reputation: 121
In addition too:
sys.path.insert(0, os.path.abspath("..Scripts/"))
I added this afterward:
sys.path.insert(0, os.path.abspath("..Scripts/Folder/"))
Which allowed me to access files in Folder with autodoc.
Upvotes: 8