[Python-Dev] New relative import issue (original) (raw)

Paul Moore p.f.moore at gmail.com
Thu Sep 21 23:23:08 CEST 2006


On 9/21/06, Guido van Rossum <guido at python.org> wrote:

On 9/21/06, Paul Moore <p.f.moore at gmail.com> wrote: > On 9/21/06, Guido van Rossum <guido at python.org> wrote: > > I think one missing feature is a mechanism whereby you can say "THIS > > package (gives top-level package name) lives HERE (gives filesystem > > location of package)" without adding the parent of HERE to sys.path > > for all module searches. I think Phillip Eby's egg system might > > benefit from this. > > This is pretty easy to do with a custom importer on sys.metapath. > Getting the details right is a touch fiddly, but it's conceptually > straightforward.

Isn't the main problem how to specify a bunch of these in the environment? Or can this be done through .pkg files? Those aren't cheap either though -- it would be best if the work was only done when the package is actually needed.

Hmm, I wasn't thinking of the environment. I pretty much never use PYTHONPATH, so I tend to forget about that aspect. I was assuming an importer object with a "register(package_name, filesystem_path)" method. Then register the packages you want in your code, or in site.py.

I've attached a trivial proof of concept.

But yes, you'd need to consider the environment. Possibly just have an initialisation function called at load time (I'm assuming the new hook is defined in a system module of some sort - I mean when that system module is loaded) which parses an environment variable and issues a set of register() calls.

Paul. -------------- next part -------------- A non-text attachment was scrubbed... Name: imphook.py Type: text/x-python Size: 1247 bytes Desc: not available Url : http://mail.python.org/pipermail/python-dev/attachments/20060921/56e5b9b7/attachment.py



More information about the Python-Dev mailing list