Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Absolute Imports and PYTHONPATH (http://www.velocityreviews.com/forums/t330625-absolute-imports-and-pythonpath.html)

Richard Cooper 05-05-2004 09:48 PM

Absolute Imports and PYTHONPATH
 
I can't believe I've just been bitten by this again!

I'm part of a team writing an application in python. We have an fairly
extensive package structure and like sensible pythoneers we use
absolute imports throughout. The top level of our package is in
PYTHONPATH so that all the absolute imports can work.

This is all fine and dandy until I start playing with two different
versions of the code (working on 2 CVS branches for example). Whenever
I do this I inevitably forget to change PYTHONPATH at some point and
waste an hour or so debugging a problem that occurred because the
__main__ module from one tree is now importing from the other. This has
happened to me a few times now and is really irritating.

Am I missing an obvious non-hacktastic way to avoid this problem?

If not would it be possible to fix this problem in a future python? I'm
thinking something along the lines of:

When a module is imported its import search path includes everything it
does now PLUS the directory that is the top of the module's enclosing
package structure. That way you wouldn't have to add entries to
PYTHONPATH for packages that only import from themselves (and stdlib
and site-packages). Possible? Sensible? What do you think?

Regards,

Rich



John Roth 05-05-2004 11:59 PM

Re: Absolute Imports and PYTHONPATH
 
"Richard Cooper" <python-list@richardcooper.net> wrote in message
news:mailman.288.1083793726.25742.python-list@python.org...
> I can't believe I've just been bitten by this again!
>
> I'm part of a team writing an application in python. We have an fairly
> extensive package structure and like sensible pythoneers we use
> absolute imports throughout. The top level of our package is in
> PYTHONPATH so that all the absolute imports can work.
>
> This is all fine and dandy until I start playing with two different
> versions of the code (working on 2 CVS branches for example). Whenever
> I do this I inevitably forget to change PYTHONPATH at some point and
> waste an hour or so debugging a problem that occurred because the
> __main__ module from one tree is now importing from the other. This has
> happened to me a few times now and is really irritating.
>
> Am I missing an obvious non-hacktastic way to avoid this problem?
>
> If not would it be possible to fix this problem in a future python? I'm
> thinking something along the lines of:
>
> When a module is imported its import search path includes everything it
> does now PLUS the directory that is the top of the module's enclosing
> package structure. That way you wouldn't have to add entries to
> PYTHONPATH for packages that only import from themselves (and stdlib
> and site-packages). Possible? Sensible? What do you think?


As far as I'm concerned, the whole notion of Pythonpath is seriously
broken, but I'm not about to suggest replacing it given the discussion
around PEP 328. Redesigning the whole import mechanism is something
that will have to wait for the ever receeding 3.0

What I do is I have a separate command prompt (I'm on Windows)
for each different Pythonpath I need to work with, and it sets the
correct path for the rest of the work.
>
> Regards,
>
> Rich
>
>





All times are GMT. The time now is 05:30 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.