0

My project (written in python 2.7) has a complex structure and most modules are interlinked. There is no direct entry or link to this project to execute. It works as toolbox for other project.

When I tried to use sphinx to create the documentation it is giving error related to "unable to import module. sample structure:

<workspace>
└── toolbox (main folder)
    ├── __init__.py 
    │   
    ├── sub
    │   ├── __init__.py
    │   ├── sub1.py
    │   └── sub2.py     
    │   
    ├── subpackageA
    │   ├── __init__.py
    │   ├── submoduleA1.py
    │   └── submoduleA2.py
    │   
    └── subpackageB
        ├── __init__.py
        ├── submoduleB1.py
        └── submoduleB2.py code[from sub import sub1
                                from subpackageA import submoduleA2 and so on]

Is there a way to configure the index.rst or the config.rst to ignore the import module error and give a output document directory like below:

└── toolbox
    │  
    ├── sub
    │   ├── index
    │   ├── sub1.m
    │   └── sub2.m    
    │   
    ├── subpackageA
    │   ├── index
    │   ├── submoduleA1.m
    │   └── submoduleA2.m
    │   
    └── subpackageB
        ├── index
        ├── submoduleB1.m
        └── submoduleB2.m

I tried adding system path in config.rst

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

even hardcoded the project path.

even tried to use the sphinx.ext.autodoc but getting the same import error. commands used:

sphinx-apidoc -o doc project/toolbox 
make html
arya
  • 35
  • 3
  • What do you mean by "external modules"? Do you have dependencies to 3pp Python packages? – mzjn May 25 '22 at 06:45
  • @mzjn like shown in sample structure in submoduleB2.py code `from sub import sub1 from subpackageA import submoduleA2 ` it is not able import the submodules from toolbox folder. Here external modules are referred to modules present in my project toolbox folder – arya May 25 '22 at 06:49
  • 1
    It's unclear to me why you say "external" when the module is part of your project. In any case, more information is needed. See [mcve]. – mzjn May 25 '22 at 06:50
  • @mzjn is there a way to edit the config/index.rst to ignore the internal module import error. why sphinx/ pdoc tries to execute the code? can it just look into folder/sub-folder/.py and just pick the doc strings for respective def? – arya May 25 '22 at 06:53
  • Modules must be importable. That is how autodoc works. https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html – mzjn May 25 '22 at 06:56
  • @mzjn is there any other package which creates documentation using doc strings and does not care about the imported modues? – arya May 25 '22 at 07:01

0 Answers0