2 import sys, imp, os, os.path
3 PYTHONPATH = os.environ.get('PYTHONPATH')
4 if PYTHONPATH is None or (sys.platform=='win32' and not PYTHONPATH):
7 PYTHONPATH = PYTHONPATH.split(os.pathsep)
9 pic = getattr(sys,'path_importer_cache',{})
10 stdpath = sys.path[len(PYTHONPATH):]
11 mydir = os.path.dirname(__file__)
12 #print "searching",stdpath,sys.path
15 if item==mydir or not item:
16 continue # skip if current dir. on Windows, or my own directory
17 importer = pic.get(item)
18 if importer is not None:
19 loader = importer.find_module('site')
20 if loader is not None:
21 # This should actually reload the current module
22 loader.load_module('site')
26 stream, path, descr = imp.find_module('site',[item])
32 # This should actually reload the current module
33 imp.load_module('site',stream,path,descr)
38 raise ImportError("Couldn't find the real 'site' module")
40 #print "loaded", __file__
42 known_paths = dict([(makepath(item)[1],1) for item in sys.path]) # 2.2 comp
44 oldpos = getattr(sys,'__egginsert',0) # save old insertion position
45 sys.__egginsert = 0 # and reset the current one
47 for item in PYTHONPATH:
50 sys.__egginsert += oldpos # restore effective old position
52 d,nd = makepath(stdpath[0])
59 if np==nd and insert_at is None:
60 # We've hit the first 'system' path entry, so added entries go here
61 insert_at = len(new_path)
63 if np in known_paths or insert_at is None:
66 # new path after the insert point, back-insert it
67 new_path.insert(insert_at, item)
70 sys.path[:] = new_path