Bundling an application with third-party modules

Serge Orlov Serge.Orlov at gmail.com
Wed Jun 14 21:45:06 EDT 2006


Ben Finney wrote:
> "Serge Orlov" <Serge.Orlov at gmail.com> writes:
>
> > Ben Finney wrote:
> > > That's a large part of my question. How can I lay out these
> > > modules sensibly during installation so they'll be easily
> > > available to, but specific to, my application?
> >
> > Put them in a directory "lib" next to the main module and start the
> > main module with the following blurb:
> > ------------------------------------------------
> > import sys, os
> > sys.path.insert(1, os.path.join(sys.path[0],"lib"))
> > ------------------------------------------------
>
> The application consists of many separate programs to perform various
> tasks, some larger than others. There's no sensible place for a "main
> module".

Perhaps I'm using my own jargon. By "main module" I mean every module
used to start any application within your project. If you want
relocatable solution, create empty .topdir file in the top directory
and put this blurb into every application:
------------------------
import sys, os
top_dir = sys.path[0]
while True:
    if os.path.exists(os.path.join(top_dir,".topdir")):
        break
    top_dir = os.path.dirname(top_dir)
sys.path.insert(1, os.path.join(top_dir,"lib"))
------------------------
I don't think you need to worry about duplication, I used this code. It
is verion 1.0 and it is final :) You won't need to change it.

> There probably will be a library directory for common code,
> though. Are you suggesting that the third-party libraries should go
> within the application-native library?

Not really. I was just feeling lazy to type a generic solution, so I
assumed one project == one application.

> What's a good way to get from upstream source code (some of which is
> eggs, some of which expects 'distutils' installation, and some of
> which is simple one-file modules) to a coherent set of application
> library code, that is automatable in an install script?

Well, I did it manually, it's not that time consuming if you keep in
mind that you also need to test new version and by testing I also mean
finding integration bugs days later. Anyway, if you feel like
automating I think you can do something using distutils command
"install --home=/temp/dir" and then copying to your common library
directory in a flat manner (--home option puts files in subdirectories
that don't make sense for a bundled lib)




More information about the Python-list mailing list