[Python-Dev] Re: .pth files in current or script directory

Richard Cooper anon at spam-trap.richardcooper.net
Sun May 16 07:39:08 EDT 2004


Tim Delaney wrote:
> A discussion (last week?) on c.l.py prompted a thought about .pth 
> files.
> Feel free to shoot it down ;)
>
> The discussion in question concerned someone using a version control
> system, and needing to change PYTHONPATH depending on which branch they
> were in.

That was me, I think.

> My immediately two thoughts were:
>
> 1. Use a build system (e.g. make) to set PYTHONPATH appropriately. This
> is they type of thing we do.

I'm on windows and am quite attached to coding and running inside SciTE.
I think I could knock up a script to do the right thing and configure
SciTE to run it rather than python. However since I sometimes run from
the command line and my colleagues use different editors that's a whole
other can of worms.

> 2. Use a .pth file in the directory the code is run from (or possibly,
> the same directory as the script).

<sniped reason this doesn't work now>

Guido van Rossum wrote:
> Can't they manipulate sys.path *inside* the code in question?  That's
> invariably the solution I end up using -- I never play with
> PYTHONPATH any more.

I suppose I could, but adding a bit of boilerplate to the top of every
source file to support something that should be completely orthogonal
to the the language (using source control branches) seems a bit hacky-
workaround-tastic even compared to my current solution (a post-it
saying 'check PYTHONPATH' in big letters stuck to my monitor)

Anyway, enough discussion of my situation, which is probably more suited
to python-list. My real question is:

Is there any desire to address this problem in some future python? When
I see 2 python-dev'ers say "PYTHONPATH isn't up to it, here's what I do"
I smell something that should be fixed once rather that worked around
everywhere.

My initial idea was 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 just so that modules could import (absolutely) from their own
package.

What do you think? Possible? Sensible? Any other ideas?

Rich




More information about the Python-Dev mailing list