SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"

export TEKHSI_DATA_DIR="$SCRIPT_DIR/../data"

python setup.py build_ext

python - "$@" <<'PY'
import glob
import sys
from pathlib import Path

script_dir = Path(__file__).resolve().parent
build_libs = sorted((script_dir / "build").glob("lib.*"))
for build_lib in build_libs:
    sys.path.insert(0, str(build_lib))

import tekhsi_test_server as server

args = sys.argv[1:]
if "--benchmark" in args and "--verbose" in args:
    raise SystemExit("--benchmark and --verbose are mutually exclusive")

server.benchmark = "--benchmark" in args
server.verbose = "--verbose" in args

server.serve()
server.wait_for_termination()
PY
