Bug 1609564 [wpt PR 21209] - Update wpt metadata, a=testonly
[gecko.git] / config / pythonpath.py
blob9c7878727d86c2c9ede022d71b200d242055667e
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 from __future__ import absolute_import
6 from __future__ import print_function
7 """
8 Run a python script, adding extra directories to the python path.
9 """
12 def main(args):
13 def usage():
14 print >>sys.stderr, "pythonpath.py -I directory script.py [args...]"
15 sys.exit(150)
17 paths = []
19 while True:
20 try:
21 arg = args[0]
22 except IndexError:
23 usage()
25 if arg == '-I':
26 args.pop(0)
27 try:
28 path = args.pop(0)
29 except IndexError:
30 usage()
32 paths.append(os.path.abspath(path))
33 continue
35 if arg.startswith('-I'):
36 paths.append(os.path.abspath(args.pop(0)[2:]))
37 continue
39 break
41 script = args[0]
43 sys.path[0:0] = [os.path.abspath(os.path.dirname(script))] + paths
44 sys.argv = args
45 sys.argc = len(args)
47 frozenglobals['__name__'] = '__main__'
48 frozenglobals['__file__'] = script
50 execfile(script, frozenglobals)
53 # Freeze scope here ... why this makes things work I have no idea ...
54 frozenglobals = globals()
56 import sys
57 import os
59 if __name__ == '__main__':
60 main(sys.argv[1:])