[Python-ideas] Policy for altering sys.path

Florian Bruhin me at the-compiler.org
Thu May 7 08:48:36 CEST 2015


* Thomas Güttler <guettliml at thomas-guettler.de> [2015-05-07 08:00:09 +0200]:
> Am 06.05.2015 um 17:07 schrieb Paul Moore:
> > On 6 May 2015 at 15:05, Thomas Güttler <guettliml at thomas-guettler.de> wrote:
> >> I am missing a policy how sys.path should be altered.
> > 
> > Well, the docs say that applications can modify sys.path as needed.
> > Generally, applications modify sys.path in place via sys.path[:] =
> > whatever, but that's not mandated as far as I know.
> > 
> >> We run a custom sub class of list in sys.path. We set it in sitecustomize.py
> > 
> > Can you explain why? 
> 
> I forgot to explain the why I use a custom class. Sorry, here is the background.
> 
> I want sys.path to ordered:
> 
>  1. virtualenv
>  2. /usr/local/
>  3. /usr/lib
> 
> We use virtualenvs with system site-packages.
> 
> There are many places where sys.path gets altered.
> 
> The last time we had sys.path problems I tried to write a test
> which checks that sys.path is the same for cron jobs and web requests.
> I failed. Too many places,  I could not find all the places
> and the conditions where sys.path got modified in a different way.

It looks like you explained *how* you do what you do, but not *why* -
what problem is this solving? Why can't you just invoke the
virtualenv's python and let python take care of sys.path?

$ ./venv/bin/python -c 'import sys; from pprint import pprint; pprint(sys.path)'
['',
 '/home/user/venv/lib/python2.7',
 '/home/user/venv/lib/python2.7/plat-x86_64-linux-gnu',
 '/home/user/venv/lib/python2.7/lib-tk',
 '/home/user/venv/lib/python2.7/lib-old',
 '/home/user/venv/lib/python2.7/lib-dynload',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/home/user/venv/local/lib/python2.7/site-packages',
 '/home/user/venv/lib/python2.7/site-packages']

Florian

-- 
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150507/60b82101/attachment.sig>


More information about the Python-ideas mailing list