run_setup: defer psycopg2 import so --help works without it

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
peter 2026-09-02 17:29:18 +01:00
parent eed06559c0
commit 6dde987cfb

View file

@ -28,8 +28,6 @@ import argparse
from pathlib import Path from pathlib import Path
from typing import Dict from typing import Dict
import psycopg2
SQL_DIR = Path(__file__).parent / "sql" SQL_DIR = Path(__file__).parent / "sql"
CONFIG_FILE = Path(__file__).parent / "db_config.json" CONFIG_FILE = Path(__file__).parent / "db_config.json"
@ -150,6 +148,13 @@ def main() -> int:
p.add_argument("--yes", action="store_true", help="Skip confirmation prompts") p.add_argument("--yes", action="store_true", help="Skip confirmation prompts")
args = p.parse_args() args = p.parse_args()
try:
import psycopg2
except ModuleNotFoundError:
print("[FAIL] psycopg2 not installed. Run inside an environment that has "
"it (e.g. the TSAPI_SERIESDB_PG_PY venv), or: pip install psycopg2-binary")
return 1
cfg = load_config(args) cfg = load_config(args)
print("=" * 70) print("=" * 70)