2

I'm going crazy with Sphinx's recursive autosummary. My working directory is:

my_wd
|
|-- docs
|   |-- source
|      |--index.md
|      |--conf.py
|      |-- _templates
|          |-- custom-module-template.rst
|          |-- custom-class-template.rst
|-- my_library
|   |-- several .py modules

at the top of conf.pyis:

import os
import sys

sys.path.insert(0, os.path.abspath('../..'))

in index.md I have:

```{toctree}
:caption: 'Contents:'
:maxdepth: 2

Home <self>

```

```{include} ../../README.md
:relative-images:
```

```{eval-rst}
.. autosummary::
   :toctree: _autosummary
   :template: custom-module-template.rst
   :recursive:
   
   my_library
```

and the files custom-module-template.rst and custom-class-template.rst are filled according to this answer.

Still, the autosummary is not working. In the log I first get

[autosummary] generating autosummary for: _autosummary/module1.rst, _autosummary/module2.rst...  

(which doesn't seem right: why is it looking for rst files?)

Then I get

WARNING: [autosummary] failed to import my_library.
    Possible hints:
    * ValueError: not enough values to unpack (expected 2, got 1)
    * ModuleNotFoundError: No module named 'my_library'
    * KeyError: 'my_library'
    
failed to import my_library.module

for every module.py that is included in the my_library folder.

This means (I guess) that sphinx is actually seeing the different .py modules in the my_library folder (but it's then looking for the corresponding rst files?!). So the absolute path should be right.

This sounds like a path error to me, but I think the path is right. What am I doing wrong?

sato
  • 768
  • 1
  • 9
  • 30
  • 1
    Do you have an `__init__.py` in `my_library` to make it a Python package? Sphinx can only import Python packages. [`autosummary`](https://www.sphinx-doc.org/en/master/usage/extensions/autosummary.html) generates autodoc summary files. Then you use `autodoc` to create HTML docs. You also might need to specify the valid file extensions that MyST looks for when using `autosummary`. – Steve Piercy Nov 09 '22 at 10:29
  • 1
    This has nothing to do with __init__.py. If any of your modules import from other modules in the same package, you'll get this error and I don't know what the solution is. Driving me crazy as well. – Julius Dec 30 '22 at 08:42

0 Answers0