]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - misc/run-with-pythonpath.py
fix quicktest: stop using setuptools, add misc/run-with-pythonpath.py, to make it...
[tahoe-lafs/tahoe-lafs.git] / misc / run-with-pythonpath.py
1 # -*- python -*-
2 # you must invoke this with an explicit python, from the tree root
3
4 """Run an arbitrary command with a PYTHONPATH that will include the Tahoe
5 code, including dependent libraries. Run this like:
6
7  python misc/run-with-pythonpath.py python foo.py
8 or
9  python misc/run-with-pythonpath.py trial -r poll allmydata.test.test_util
10
11 """
12
13 import os, sys, subprocess
14
15 # figure out where support/lib/pythonX.X/site-packages is
16 # add it to os.environ["PYTHONPATH"]
17 # spawn the child process
18
19
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")
24     else:
25         return os.path.join(prefixdir, "lib", pyver, "site-packages")
26
27 basedir = os.path.dirname(os.path.abspath(__file__))
28 supportlib = pylibdir(os.path.abspath("support"))
29
30 oldpp = os.environ.get("PYTHONPATH", "").split(os.pathsep)
31 if oldpp == [""]:
32     # grr silly split() behavior
33     oldpp = []
34 newpp = os.pathsep.join(oldpp + [supportlib,])
35 os.environ['PYTHONPATH'] = newpp
36
37 command = sys.argv[1:]
38 rc = subprocess.call(command)
39 sys.exit(rc)