I am trying to implement following hierarchy. My final goal is myscpt.sh should run from any folder
But I am getting import errors.
What is the best approach to implement such type of hierarchical architecture?
FooSoft
|
|-- foo/
|
|-- test.py
|
|-- common/
|
|-- utils/
|
|-- api/
|
|-- scripts/
|-- myscript.py
|
|-- bin/myscpt.sh
|
|-- etc/foo.conf
bin/myscpt.sh
/usr/bin/python /path/FooSoft/foo/script/myscript.py /path/FooSoft/etc/foo.conf
foo/script/myscript.py
from ..common import *
from ..utils import *
from ..test import *
.
.
<Doing some stuff>
I am using .. import
in most of modules to avoid absolute path.
Typically I resolve import errors by always using the package root as a reference.
First, I would include a setup.py file in the project root, and add in a minimal setuptools wrapper.
Then you don't have to worry about where you run the script from. Your imports become as follows: