[Python-Dev] sys.path in interactive session

Phillip J. Eby pje at telecommunity.com
Fri Jun 3 02:48:27 CEST 2005


At 05:08 PM 6/2/2005 -0700, Bob Ippolito wrote:
>On Jun 2, 2005, at 4:50 PM, Guido van Rossum wrote:
> >
> > I think that the "absolutizing" of sys.path entries is relatively new
> > (seems to have started in 2.3).
> >
> > Also note that it's not really the current directory but the directory
> > containing the script; that is definitely intentional.
>
>The absolutizing of sys.path in site.py is misbehavior anyway..

Your patch doesn't fix it doing this to __file__; probably this should not 
touch __file__ if a module has a __loader__ set, or if the path it's 
absolutizing doesn't exist.

Actually, your patch doesn't fix it doing this to all the sys.path entries, 
either.  It appears that site.py may be quite broken with respect to PEP 
302.  Fixing it is going to be interesting, since it's quite possible that 
you can have stuff on PYTHONPATH for which the sys.path_hooks entries don't 
exist yet.  Thus, you can't guarantee when you absolutize a path entry that 
it is in fact a filename, unless you check for its existence - which in 
principle could be a coincidence.

It may be that we need to define more clearly what is allowed on sys.path, 
such that site.py can tell the difference between filesystem paths, and 
non-filesystem PEP 302 specifiers.  Right now, the only major PEP 302 
implementation that I know of is zipimport, but zipimport uses strings that 
are effectively filesystem paths, so site.py doesn't break them.




More information about the Python-Dev mailing list