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

Re: Ideal directory structure?



Hi Umang,

On Sat, Jan 30, 2010 at 5:24 AM, Umang <umang.me@gmail.com> wrote:
   foo-1.2.3.tar.gz
   foo-1.2.3/
   foo-1.2.3/bin/
   foo-1.2.3/bin/foo
   foo-1.2.3/foolib/
   foo-1.2.3/foolib/__init__.py
   ...

Now in foo-1.2.3/bin/foo how do I import foolib.wibble so that an installed foo (i.e. /usr/bin/foo after a "setup.py install") can import from the installed module/package (somewhere inside /usr/lib/) while a foo extracted from a source tarball (foo-1.2.3/bin/foo) can import a module/package from the extracted package (foo-1.2.3/foolib/wibble.py).

The PyGTK project LottaNZB has the very same source tarball structure and the problem you describe has been solved as follows:

Add an executable script "run-foo.sh" to the root directory foo-1.2.3 with the following content:

#!/bin/sh
FOOPATH=`dirname $0`
PYTHONPATH="$PYTHONPATH:$FOOPATH" exec $FOOPATH/bin/foo $*

This allows you to run 'foo' locally using 'run-foo.sh' without having to modify sys.path in bin/foo. It's probably not the most elegant approach, but it worked well for me.

Regards,
Severin

Reply to: