locality/dev.py

59 lines
1.4 KiB
Python

import argparse
import os
import subprocess
import sys
# The directory containing this script should be the root directory of the
# locality repository.
ROOT_DIR = sys.path[0]
def devupdate(args):
subprocess.run(
[sys.executable, '-m', 'pip', 'install', '-r',
os.path.join(ROOT_DIR, 'dev-python-requirements.txt'), ])
def import_run():
"""Import the scripts.run module and return it.
We do this in a function so that devupdate() can be run without everything
needed by this module being available."""
import scripts.run
scripts.run.ROOT_DIR = ROOT_DIR
return scripts.run
def run(args):
import_run().run(args)
def unit_tests(args):
import_run().unit_tests(args)
def database_tests(args):
import_run().database_tests(args)
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(required=True)
run_parser = subparsers.add_parser(
'run', help='Run a test instance of locality'
)
run_parser.set_defaults(func=run)
run_parser = subparsers.add_parser(
'dbtest', help='Run database tests'
)
run_parser.set_defaults(func=database_tests)
run_parser = subparsers.add_parser(
'unittest', help='Run unit tests'
)
run_parser.set_defaults(func=unit_tests)
devupdate_parser = subparsers.add_parser(
'devupdate', help='Install or update packages used by this script'
)
devupdate_parser.set_defaults(func=devupdate)
args = parser.parse_args()
args.func(args)