Coverage for app / main.py: 95%

22 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2025-12-16 13:09 +0000

1from pathlib import Path 

2 

3import modal 

4from fastapi import FastAPI 

5from fastapi.staticfiles import StaticFiles 

6 

7from app.config import settings 

8from app.routers import data, hypermedia 

9 

10web_app = FastAPI(title=settings.APP_NAME) 

11app = modal.App("sql_translate") 

12 

13 

14static_path = Path(__file__).parent.with_name("static").resolve() 

15static_remote_path = "/assets/static" 

16templates_path = Path(__file__).parent.with_name("templates").resolve() 

17templates_remote_path = "/assets/templates" 

18pyproject_toml_path = Path(__file__).parent.with_name("pyproject.toml").resolve() 

19 

20image = ( 

21 modal.Image.debian_slim(python_version="3.13") 

22 .pip_install_from_pyproject(pyproject_toml_path) 

23 .env({"ENVIRONMENT": "prod"}) 

24 .add_local_dir(static_path, remote_path=static_remote_path) 

25 .add_local_dir(templates_path, remote_path=templates_remote_path) 

26) 

27 

28static_files = ( 

29 StaticFiles(directory=static_remote_path) 

30 if settings.ENVIRONMENT == "prod" 

31 else StaticFiles(directory=static_path) 

32) 

33 

34web_app.mount("/static", static_files, name="static") 

35 

36web_app.include_router(data.router) 

37web_app.include_router(hypermedia.router) 

38 

39 

40@app.function(image=image) 

41@modal.asgi_app() 

42def fastapi_app() -> FastAPI: 

43 return web_app