By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,830 Members | 1,758 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,830 IT Pros & Developers. It's quick & easy.

finding the same package in multiple places

P: n/a

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

Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Skip Montanaro wrote:
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

Jul 18 '05 #2

P: n/a

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

Thanks Peter. This does exactly what I need.

Skip

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.