2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-21 17:34:03 +08:00
artiq/lit-test/harness.py

26 lines
938 B
Python
Raw Normal View History

"""
The purpose of this harness is to emulate the behavior of
the python executable, but add the ARTIQ root to sys.path
beforehand.
This is necessary because eggs override the PYTHONPATH environment
variable, but not current directory; therefore `python -m artiq...`
ran from the ARTIQ root would work, but there is no simple way to
emulate the same behavior when invoked under lit.
"""
import sys, os, argparse, importlib
parser = argparse.ArgumentParser(description=__doc__)
2015-06-06 22:15:06 +08:00
parser.add_argument('-m', metavar='mod', type=str, required=True,
help='run library module as a script')
parser.add_argument('args', type=str, nargs='+',
help='arguments passed to program in sys.argv[1:]')
args = parser.parse_args(sys.argv[1:])
artiq_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.insert(1, artiq_path)
sys.argv[1:] = args.args
importlib.import_module(args.m).main()