Source

#!/usr/bin/env python ## try to find and import a nearby version of the 'py' package. # otherwise use the system global default # XXX turn this into a developer-only thing? #importsysimportosfromos.pathimportdirnameasopd,exists,join,basename,abspathdefsearchpy(current):while1:last=currentinitpy=join(current,'__init__.py')ifnotexists(initpy):pydir=join(current,'py')# recognize py-package and ensure it is importableifexists(pydir)andexists(join(pydir,'__init__.py')):#for p in sys.path:# if p == current:# return Trueifcurrent!=sys.path[0]:# if we are already first, then okprint>>sys.stderr,"inserting into sys.path:",currentsys.path.insert(0,current)returnTruecurrent=opd(current)iflast==current:returnFalseifnotsearchpy(abspath(os.curdir)):ifnotsearchpy(opd(abspath(sys.argv[0]))):ifnotsearchpy(opd(__file__)):pass# let's hope it is just on sys.path importpyif__name__=='__main__':print"py lib is at",py.__file__