0

I have an application containing a package, thus:

* fruits/
 | citrus/
 | | __init__.py
 | | oranges.py
 | | mandarins.py
 | | satsumas.py
 | | ... etc

The Python files under fruits/citrus/ contain definitions of about 300 subclasses of fruits.citrus.Citrus.

They live in separate files like this only for administrative reasons. Nobody should know or care about fruits.citrus.mandarins etc unless they're working on the fruits.citrus package. To put it another way, I would like this package to pretend it's a module.

I have tried putting this in __init__.py:

from fruits.citrus.oranges import *
from fruits.citrus.mandarins import *
from fruits.citrus.satsumas import *
[...]
g = list(globals().items())
__all__ = list([
 name for name, value in g
 if value.__class__==type and
 issubclass(value, Citrus)
 ])

This sort of works, in that you can see fruits.citrus.Tangerine. But pydoc and sphinx still list oranges, mandarins, etc as package contents. And Tangerine is both at fruits.citrus.Tangerine and at fruits.citrus.mandarins.Tangerine, so things are even more complicated than when I started.

There has to be a way to do this, but everything I tried has been a lemon. Help?

asked Apr 19, 2022 at 21:44
2
  • 2
    Can you specify why you are attempting to do this? does Tangerine exist twice or is it just linked in the init.py file? Copying a file to exist twice is very bad practice. Commented Apr 28, 2022 at 10:08
  • It was just linked in the init.py file. I was trying to think of how to get an autodoc program to ignore this, but I decided in the end not to use the autodoc program! Commented May 15, 2022 at 1:28

2 Answers 2

2

can you tell if that helps hiding those submodules:

from .mandarins import *
from .oranges import *
del globals()['mandarins']
del globals()['oranges']
answered Apr 24, 2022 at 19:34
Sign up to request clarification or add additional context in comments.

Comments

0

Turns out there isn't a good way, but that's all right.

I was trying to use an autodoc program to document a codebase, and it kept listing all these classes twice. The answer in the end was just to specify the classes by hand!

answered May 15, 2022 at 1:30

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.