Coverage for src/fastoai/cli.py: 0%

12 statements  

« prev     ^ index     » next       coverage.py v7.6.8, created at 2024-12-06 09:34 +0800

1from typing import Annotated 

2from urllib.parse import urlparse 

3 

4import typer 

5import uvicorn 

6 

7from .dependencies import get_settings 

8 

9app = typer.Typer() 

10 

11 

12result = urlparse(get_settings().base_url) 

13DEFAULT_HOST = result.hostname or "127.0.0.1" 

14DEFAULT_PORT = result.port or 8000 

15 

16 

17@app.command() 

18def serve( 

19 host: Annotated[ 

20 str, typer.Option(help="If not specified, will read from env FASTOAI_BASE_URL") 

21 ] = DEFAULT_HOST, 

22 port: Annotated[ 

23 int, 

24 typer.Option(help="If not specified, will read from env FASTOAI_BASE_URL"), 

25 ] = DEFAULT_PORT, 

26 reload: bool = False, 

27): 

28 """Serve the FastAPI application.""" 

29 uvicorn.run( 

30 "fastoai:app", 

31 host=host, 

32 port=port, 

33 reload=reload, 

34 reload_excludes=["generated/*.py"], 

35 )