[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Ideal directory structure?


Guy Hulbert wrote:
> appending lib to everything is really ugly* ... is it because
> ./appname.py
> ./appname/__init__.py
> fails to work ?

Yes! If you import appname from the appname.py, it will try to import
itself ! What I do right now is the following :


And then in /scripts/appname (the executable) I put:

SCRIPTS_DIR = "scripts"
def _is_in_devel():
    d = os.path.split(os.path.dirname(os.path.abspath(__file__)))[1]
    return d == SCRIPTS_DIR
if _is_in_devel():
    d = os.path.split(os.path.dirname(os.path.abspath(__file__)))[0]
    sys.path.insert(0, d)
    os.environ["PATH"] += ":%s" % (os.path.join(d, SCRIPTS_DIR))
    from appname import runner

I for inspired by pitivi, which does that. (thanks Ed!) For the runner
thing, I got inspired from Twisted.

I am not saying this is perfect, but it works well with the limitations
of the packaging in importing mechanism in Python.

Alexandre Quessy

Reply to: