classification
Title: Allow site.addsitedir insert to beginning of sys.path
Type: enhancement Stage: test needed
Components: Library (Lib) Versions: Python 3.2, Python 2.7, Python 2.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: cjw296, gotgenes, mejo
Priority: normal Keywords:

Created on 2010-01-20 20:19 by gotgenes, last changed 2011-06-26 11:44 by mejo.

Messages (4)
msg98084 - (view) Author: Chris Lasher (gotgenes) Date: 2010-01-20 20:19
Would it be possible to add an extra option to site.addsitedir so that it left-appends (inserts at the beginning of the list rather than the end of the list) to sys.path the new path?

The use case for this is that sometimes the user has local versions of packages and modules they would prefer to use over versions installed system-wide. Since Python searches for packages and modules in the order given by sys.path, inserting the new path(s) at the beginning of sys.path. This leads to hack-ish work-arounds, such as the one given by http://code.google.com/p/modwsgi/wiki/VirtualEnvironments

If there was an option to left-append with site.addsitedir, it would really help in cases such as these.

Note that I'm not certain at the moment how best to add additional paths that are found in .pth files, i.e., whether to insert them at the beginning as well, or insert them between the initial path and the original paths (the paths that existed before site.addsitedir is called).
msg98085 - (view) Author: Chris Lasher (gotgenes) Date: 2010-01-20 21:21
One correction: by "beginning of sys.path", what I really mean is, "the portion of sys.path after the initial ''". I forgot that '', the empty path, should always be at the start of sys.path to ensure that packages and modules in the current working directory are given top priority. Thus, I would like to see insertions between sys.path[0] and sys.path[1].

Sorry for the confusion.
msg98184 - (view) Author: Chris Withers (cjw296) * (Python committer) Date: 2010-01-23 12:30
This sounds like something best taken to the python-ideas mailing list.
Can you do that and update the issue with the outcome of any discussion?
msg139167 - (view) Author: Jonas Meurer (mejo) Date: 2011-06-26 11:44
I would be interested in that feature as well. It's currently impossible to use custom new versions of a python module by adding the directory with site.addsitedir in case a old version of the module is already installed in the python systemwide path.
History
Date User Action Args
2011-06-26 11:44:41mejosetstatus: pending -> open
versions: + Python 2.6
nosy: + mejo

messages: + msg139167
2010-01-23 15:45:49brian.curtinsetstatus: open -> pending
priority: normal
stage: test needed
versions: + Python 2.7, Python 3.2
2010-01-23 12:30:56cjw296setnosy: + cjw296
messages: + msg98184
2010-01-20 21:21:56gotgenessetmessages: + msg98085
2010-01-20 20:19:22gotgenescreate