2

I have a python module with the following structure:

my_mod
|--- __init__.py
|--- mod1
|    |---- __init__.py
     |---- testA.py
     |---- testB.py
     |---- testC.py

Inside each testX.py is a single function that is named testX. These functions are large so to keep my files manageable I separated testA,B, and C out. To avoid having to access these functions in this manner:

import my_mod.mod1.testA.testA

My mod1/__init__.py file is structured as follows:

from .testA import testA
from .testB import testB
from .testC import testC

So my functions are now accessible as

import my_mod.mod1.testA

This behaves as expected. However when I go to autodoc my module with Sphinx the documentation misses this feature in the __init__ and I end up with my functions being documented as

my_mod.mod1.testA.testA(blah, blah, blah)

Which is not the actual usage and will fail if called in an actual script.

Is there a way for Sphinx to understand this? Or if not a better way to structure my module to keep my file size small but avoid duplicate names on import?

Thanks for the help

mzjn
  • 48,958
  • 13
  • 128
  • 248
Kschau
  • 145
  • 1
  • 12
  • Looks similar to https://stackoverflow.com/q/15115514/407651 – mzjn Feb 02 '19 at 04:19
  • @mzjn Following the link provided does not solve the issue. Creating the `__all__` in `mod1/__init__.py` keeps the desired import behavior, but the documentation still refers to the "file path" of each function inside testX.py not the import path. The `.. automodule :: my_mod.mod1` does not make a difference either. Setting the `add_module_names=False` does remove all the "file path" information clearing up the documentation a bit... Thanks for looking – Kschau Feb 02 '19 at 12:25
  • Maybe this helps: https://stackoverflow.com/a/24787344/407651. If it doesn't, please provide a [mcve]. – mzjn Feb 02 '19 at 12:30

0 Answers0