finding the same package in multiple places

Skip Montanaro skip at
Wed Jun 30 21:05:22 CEST 2004

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).



More information about the Python-list mailing list