Coverage for app / backend / src / run_locally.py: 0%
31 statements
« prev ^ index » next coverage.py v7.13.2, created at 2026-02-03 06:18 +0000
« prev ^ index » next coverage.py v7.13.2, created at 2026-02-03 06:18 +0000
1"""You can execute this script from pycharm/vscode's debugger!"""
3import os
4from collections.abc import Generator
5from pathlib import Path
6from tempfile import TemporaryDirectory
9def parse_env_lines(file: Path) -> Generator[tuple[str, str]]:
10 for line in file.resolve().read_text().splitlines():
11 if not line.strip() or line.startswith("#"):
12 continue
13 name, value = line.split("=", maxsplit=1)
14 yield name, value
17def read_db_password() -> str:
18 postgres_env = parse_env_lines(Path(__file__).parent / "../../postgres.dev.env")
19 db_password = dict(postgres_env)["POSTGRES_PASSWORD"]
20 return db_password
23def update_env() -> None:
24 backend_env = parse_env_lines(Path(__file__).parent / "../../backend.dev.env")
25 db_password = read_db_password()
27 envs = {
28 **dict(backend_env),
29 "SMTP_HOST": "localhost",
30 "OPENTELEMETRY_ENDPOINT": "localhost:4317",
31 "DATABASE_CONNECTION_STRING": f"postgresql://postgres:{db_password}@localhost:6545/postgres",
32 }
34 os.environ.update(envs)
37def main() -> None:
38 update_env()
40 if __name__ == "__main__":
41 # It's not created in app.py, since it's under __name__ == "__main__".
42 # Note that we have to do it before importing "app"
43 prometheus_multiproc_dir = TemporaryDirectory()
44 os.environ["PROMETHEUS_MULTIPROC_DIR"] = prometheus_multiproc_dir.name
46 # Only import it here because it has side effects.
47 import app
49 if __name__ == "__main__":
50 app.common_init()
51 app.main()
52 elif __name__ == "__mp_main__": # processes created via multiprocessing
53 app.common_init()
56main()