[Python-ideas] PYTHONUSERBASES (plural!)
larry at hastings.org
Tue Apr 21 23:39:37 CEST 2009
I was excited to see PYTHONUSERBASE added in 2.6/3.0. But I became disappointed when I learned it only allows you to specify one directory. I have use cases where I'd want more than one.
Also, PYTHONUSERBASE doesn't support all the directories that site.addsitepackages does. PYTHONUSERBASE examines exactly one; on non-Windows platforms, it's:
However, for each "prefix" directory Python knows about, site.addsitepackages examines these two on Linux:
(The list is even longer on OS X.)
I therefore propose a new environment variable called PYTHONUSERBASES. PYTHONUSERBASES is a list of directories separated by whatever directory separator characters PYTHONPATH permits on the local platform. At startup, after processing PYTHONUSERBASE but before calling site.addsitepackages, Python iterates down the list of directories listed in PYTHONUSERBASES and causes them to be processed by site.addsitepackages before the default prefix directories. (Probably by adding them to sys.prefixes.) PYTHONUSERBASES obeys -s, PYTHONNOUSERSITE, and the rules about effective user/group IDs, just as PYTHONUSERBASE does. The default value of PYTHONUSERBASES is the empty string; this would add no new directories.
It seems to me that PYTHONUSERBASES would turn "virtualenv" into a twenty-line shell script. Add the appropriate directories to LD_LIBRARY_PATH and PYTHONUSERBASES and you'd be off to the races. You'd have to be careful to manually specify --prefix when installing new software, which I'm guessing virtualenv obviates. But apart from that I think it would work fine. Or am I missing something important?
I would be happy--thrilled!, even--to write this up as a patch for Python 3.1 before the feature-freeze,
More information about the Python-ideas