[Python-Dev] Relative Package Imports

M.-A. Lemburg mal@lemburg.com
Sat, 11 Sep 1999 12:29:48 +0200


Guido van Rossum wrote:
> 
> > I've spent the last two hours trying to get relative package
> > imports to work because I need them for my extension packages
> > which will soon all move under a new top-level package name
> > to overcome the conflicts with PIL and Zope.
> 
> I'd much rather use absolute package names for anything that's not in
> the same directory as the current module.

Of course, you could do everything with absolute names, but then
the package author would dictate the complete absolute path which
is not always desirable since it can cause name collisions such
as DateTime in mxDateTime and Zope or Queue in mxQueue (to be
released) and Mark's win32 stuff.

As more and more packages appear, we run into this problem more
and more often. Relative imports would greatly reduce the
risk these collisions, because packages could be written
self-contained meaning that they can reach their internal
modules via relative paths only and don't have to know about
the absolute paths by which they are reachable from other parts
of the Python universe.

I could then make all my packages self-contained and
distribute them in two forms without having to change
a single line for the added support:

1. under the new 'mx' package, e.g. mx.DateTime
2. for backward compatibility under 'DateTime'

Another major advantage is that I could take any other
self-contained package and install it under absolute paths
of my choice, e.g. put Zope under org.zope.core, Python under
org.python.core etc., without harming their functionality
or having to dive deep into their import structures to fix
them manually. 

To further enhance this mechanism I would like to have an
alias mechanism in import, pickle et al. so that changes
in the package structures become manageable without user
intervention: pickles are a major problem whenever import
structures change because they store absolute module names.

-- 
Marc-Andre Lemburg
______________________________________________________________________
Y2000:                                                   111 days left
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/