Coverage for /usr/local/lib/python3.10/site-packages/opal_server-0.0.0-py3.10.egg/opal_server/cli.py: 0%

37 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-10 11:54 +0000

1import os 

2import sys 

3 

4import typer 

5from click.core import Context 

6from fastapi.applications import FastAPI 

7from typer.main import Typer 

8 

9# Add parent path to use local src as package for tests 

10root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)) 

11sys.path.append(root_dir) 

12 

13from opal_common.cli.docs import MainTexts 

14from opal_common.cli.typer_app import get_typer_app 

15from opal_common.config import opal_common_config 

16from opal_common.corn_utils import run_gunicorn, run_uvicorn 

17from opal_server.config import opal_server_config 

18 

19app = get_typer_app() 

20 

21 

22@app.command() 

23def run(engine_type: str = typer.Option("uvicron", help="uvicorn or gunicorn")): 

24 """Run the server as a daemon.""" 

25 typer.echo(f"-- Starting OPAL Server (with {engine_type}) --") 

26 

27 if engine_type == "gunicorn": 

28 app: FastAPI 

29 from opal_server.main import app 

30 

31 run_gunicorn( 

32 app, 

33 opal_server_config.SERVER_WORKER_COUNT, 

34 host=opal_server_config.SERVER_HOST, 

35 port=opal_server_config.SERVER_BIND_PORT, 

36 ) 

37 else: 

38 run_uvicorn( 

39 "opal_server.main:app", 

40 workers=opal_server_config.SERVER_WORKER_COUNT, 

41 host=opal_server_config.SERVER_HOST, 

42 port=opal_server_config.SERVER_BIND_PORT, 

43 ) 

44 

45 

46@app.command() 

47def print_config(): 

48 """To test config values, print the configuration parsed from ENV and 

49 CMD.""" 

50 typer.echo("Printing configuration values") 

51 typer.echo(str(opal_server_config)) 

52 typer.echo(str(opal_common_config)) 

53 

54 

55def cli(): 

56 main_texts = MainTexts("💎 OPAL-SERVER 💎", "server") 

57 

58 def on_start(ctx: Context, **kwargs): 

59 if ctx.invoked_subcommand is None or ctx.invoked_subcommand == "run": 

60 typer.secho(main_texts.header, bold=True, fg=typer.colors.MAGENTA) 

61 if ctx.invoked_subcommand is None: 

62 typer.echo(ctx.get_usage()) 

63 typer.echo(main_texts.docs) 

64 

65 opal_server_config.cli( 

66 [opal_common_config], typer_app=app, help=main_texts.docs, on_start=on_start 

67 ) 

68 

69 

70if __name__ == "__main__": 

71 cli()