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/run-with-pythonpath.py python foo.py
9 python misc/run-with-pythonpath.py trial -r poll allmydata.test.test_util
13 import os, sys, subprocess
15 # figure out where support/lib/pythonX.X/site-packages is
16 # add it to os.environ["PYTHONPATH"]
17 # spawn the child process
20 def pylibdir(prefixdir):
21 pyver = "python%d.%d" % (sys.version_info[:2])
22 if sys.platform == "win32":
23 return os.path.join(prefixdir, "Lib", "site-packages")
25 return os.path.join(prefixdir, "lib", pyver, "site-packages")
27 basedir = os.path.dirname(os.path.abspath(__file__))
28 supportlib = pylibdir(os.path.abspath("support"))
30 oldpp = os.environ.get("PYTHONPATH", "").split(os.pathsep)
32 # grr silly split() behavior
34 newpp = os.pathsep.join(oldpp + [supportlib,])
35 os.environ['PYTHONPATH'] = newpp
37 command = sys.argv[1:]
38 rc = subprocess.call(command)