简体   繁体   中英

Sphinx can't find my functions (probably due to imports or folder structure)

I have the following folder structure for a package project (simplified):

projectname
├── docs
├── packagename
│   ├── somemodule
│   |   ├── __init__.py (second)
|   │   └── somescript.py
│   └── __init__.py (first)
├── setup.cfg
└── pyproject.toml

In first __init__.py I do from. import somemodule from. import somemodule . In the second __init__.py I do from.somescript import * . And somescript.py contains some function my_sum . The problem is that sphinx doesn't see the function. It only sees module packagename.somemodule - there is no function doscstring for my_sum in generated documentation. The function works well if I install the library using pip install. from the projectname folder.
I'm sure the problem is in the folder structure or imports because there was no problem when somescript.py was placed directly in packagename folder.

Additional information (maybe useful, maybe not):
I use Read The Docs.
Part of .readthedocs.yaml :

python:
  install:
    - method: pip
      path: .

UPD :
Read The Docs generates the following warnings:

WARNING: autodoc: failed to import module 'somescript' from module 'packagename'; the following exception was raised:
No module named 'packagename.somescripts'
WARNING: html_static_path entry '_static' does not exist

UPD2 :
I fixed the warning from autodoc by fixing docs/source/packagename.rst but I still have the problem

I once had a similar problem and it could be solved by manually adding all directories of the module to the path. See also this answer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM