finding the same package in multiple places

S

Skip Montanaro

At work we have a package structure for our homegrown code. Developers each
have their own sandboxes where they work on the stuff they are responsible
for (mixtures of C++ libraries, SWIG wrappers and pure Python packages).
We're running into a problem where we have two versions of the main package,
one in the developer's sandbox that contains just the developer's bits and
one in the central location which contains all the installed stuff. We're
running into problems because the search for a module within a package stops
when the first instance of the top level package is found. I don't know of
a good way to work around this problem. I've cooked up a scheme involving
symlinks, but that's a very bad hack. I'd like something cleaner.

Let me make it more concrete. We have a central package, call it "central".
Inside that package are three subpackages, "a", "b" and "c". Imports thus
look like

import central.a
from central import b
from central.c import foo

Now suppose I need to work on subpackage c. If I create a local package
called "central" and install my working copy of "c" there, athen adjust
PYTHONPATH accordingly, I can't import "central.a" or "central.b" any longer
because the search for them ends when the developer's local version of
"central" is encountered. For various reasons our sandbox directory doesn't
have the same structure as the installation directory, so I actually have to
"install" stuff in my local sandbox to get the proper directory structure.
Even if that wasn't the case, most developers don't need or want to build
all the C++ and SWIG stuff anyway.

Any ideas would be greatly appreciated (import hooks that cause the search
for a package's submodules and subpackages to continue beyond the first
occurrence of the package would be especially welcome).

Thanks,

Skip
 
P

Peter Otten

Skip said:
Let me make it more concrete. We have a central package, call it
"central".
Inside that package are three subpackages, "a", "b" and "c". Imports thus
look like

import central.a
from central import b
from central.c import foo

Now suppose I need to work on subpackage c. If I create a local package
called "central" and install my working copy of "c" there, athen adjust
PYTHONPATH accordingly, I can't import "central.a" or "central.b" any
longer

I haven't used it myself, but if I read the documentation correctly,
http://docs.python.org/lib/module-pkgutil.html
may do what you need.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,888
Messages
2,569,964
Members
46,294
Latest member
HollieYork

Latest Threads

Top