I have a directory structure as follows
- mybasedir
- mysub1
- foo.py
- mysub2
- bar.py
- mysub3
- mysubderp3
- foo.py
- mysubderp3
- mysub1
I would like to import every module under mybasedir which has a foo.py, any not import anything else (i.e. mysub2 shouldnt get imported as it has bar.py, not foo.py)
I would then like to be able to access the module as the < the directory containing foo.py >.foo i.e. I want to use mysubderp3.foo instead of mysub3.mysubderp3.foo,
I have tried to walk the directory structure, looking for foo.py, and adding its path to __all__ in ./mybasedir/__init__.py,
i.e. __all__ = ['mysub1', 'mysub3/mysubderp3']
I would then import from some code as from mybasedir import *
This used to work in python 2.7, but doesnt seem to work in python 3.7
Does anyone have insight into how to accomplish this?