diff --git a/iticli/cli.py b/iticli/cli.py index 746a3ad..6505a53 100644 --- a/iticli/cli.py +++ b/iticli/cli.py @@ -156,11 +156,7 @@ def handle_run(args: argparse.Namespace) -> int: ctx = require_project() env_name, port = parse_run_args(args.env_or_port, args.port) env = {"APP_ENV": env_name} - - if ctx.kind == "framework": - cmd = ["uv", "run", "uvicorn", "iti.app:create_app", "--factory", "--port", port] - else: - cmd = ["uv", "run", "uvicorn", "main:app", "--port", port] + cmd = build_run_cmd(ctx, port) if env_name == "prod": cmd.extend(["--host", "0.0.0.0"]) @@ -170,6 +166,14 @@ def handle_run(args: argparse.Namespace) -> int: return run(cmd, ctx.root, extra_env=env) +def build_run_cmd(ctx: ProjectContext, port: str) -> list[str]: + if ctx.kind == "framework": + cmd = ["uv", "run", "python", "-m", "uvicorn", "iti.app:create_app", "--factory", "--port", port] + else: + cmd = ["uv", "run", "python", "-m", "uvicorn", "main:app", "--port", port] + return cmd + + def handle_migrate(args: argparse.Namespace) -> int: ctx = require_project() action = args.action diff --git a/tests/test_cli.py b/tests/test_cli.py index 5f59260..fabfe05 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -7,6 +7,7 @@ import pytest from iticli.cli import ( ProjectContext, alembic_base_cmd, + build_run_cmd, build_parser, detect_project, ensure_uv_no_sources_package, @@ -138,6 +139,15 @@ def test_parse_run_args_accepts_env_and_port() -> None: assert parse_run_args("default", None) == ("dev", "8000") +def test_build_run_cmd_uses_python_module() -> None: + framework = ProjectContext(Path("."), "framework", {}, False) + business = ProjectContext(Path("."), "business", {}, False) + + assert build_run_cmd(framework, "8000")[:5] == ["uv", "run", "python", "-m", "uvicorn"] + assert "iti.app:create_app" in build_run_cmd(framework, "8000") + assert "main:app" in build_run_cmd(business, "8000") + + def test_extract_message_accepts_remainder_flags() -> None: rest = ["-m", "alice add order table", "--head", "head"]