Coverage for app/backend/src/run_locally.py: 0%

31 statements  

« prev     ^ index     » next       coverage.py v7.16.1, created at 2026-09-19 15:47 +0000

1"""You can execute this script from pycharm/vscode's debugger!""" 

2 

3import os 

4from collections.abc import Generator 

5from pathlib import Path 

6from tempfile import TemporaryDirectory 

7 

8 

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 

15 

16 

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 

21 

22 

23def update_env() -> None: 

24 backend_env = parse_env_lines(Path(__file__).parent / "../../backend.dev.env") 

25 db_password = read_db_password() 

26 

27 envs = { 

28 **dict(backend_env), 

29 "SMTP_HOST": "localhost", 

30 "OPENTELEMETRY_ENDPOINT": "http://localhost:4318/v1/traces", 

31 "DATABASE_CONNECTION_STRING": f"postgresql://postgres:{db_password}@localhost:6545/postgres", 

32 "VALKEY_HOST": "localhost", 

33 } 

34 

35 os.environ.update(envs) 

36 

37 

38def main() -> None: 

39 update_env() 

40 

41 if __name__ == "__main__": 

42 # It's not created in app.py, since it's under __name__ == "__main__". 

43 # Note that we have to do it before importing "app" 

44 prometheus_multiproc_dir = TemporaryDirectory() 

45 os.environ["PROMETHEUS_MULTIPROC_DIR"] = prometheus_multiproc_dir.name 

46 

47 # Only import it here because it has side effects. 

48 import app # noqa: PLC0415 

49 

50 if __name__ == "__main__": 

51 app.common_init() 

52 app.main() 

53 elif __name__ == "__mp_main__": # processes created via multiprocessing 

54 app.common_init() 

55 

56 

57main()