2 # you must invoke this with an explicit python, from the tree root
4 """Run an arbitrary command with a PYTHONPATH that will include the Tahoe
5 code, including dependent libraries. Run this like:
7 python misc/build_helpers/run-with-pythonpath.py python foo.py
10 import os, sys, subprocess
12 # figure out where support/lib/pythonX.X/site-packages is
13 # add it to os.environ["PYTHONPATH"]
14 # spawn the child process
17 def pylibdir(prefixdir):
18 pyver = "python%d.%d" % (sys.version_info[:2])
19 if sys.platform == "win32":
20 return os.path.join(prefixdir, "Lib", "site-packages")
22 return os.path.join(prefixdir, "lib", pyver, "site-packages")
24 basedir = os.path.dirname(os.path.abspath(__file__))
25 supportlib = pylibdir(os.path.abspath("support"))
27 oldpp = os.environ.get("PYTHONPATH", "").split(os.pathsep)
29 # grr silly split() behavior
31 newpp = os.pathsep.join(oldpp + [supportlib,])
32 os.environ['PYTHONPATH'] = newpp
34 from twisted.python.procutils import which
36 if cmd and cmd[0] not in "/~.":
39 print >>sys.stderr, "'%s' not found on PATH" % (cmd,)
43 os.execve(cmd, sys.argv[1:], os.environ)