diff --git a/pyproject.toml b/pyproject.toml index 1b552c2..1ef4968 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,6 +37,7 @@ dependencies = [ "pydantic[email] >= 2.0", "sentry-sdk >= 2.20.0", "fastar >= 0.8.0", + "tomli; python_version < '3.11'", ] [project.optional-dependencies] diff --git a/src/fastapi_cloud_cli/commands/deploy.py b/src/fastapi_cloud_cli/commands/deploy.py index e94c3f8..44edaa1 100644 --- a/src/fastapi_cloud_cli/commands/deploy.py +++ b/src/fastapi_cloud_cli/commands/deploy.py @@ -17,6 +17,10 @@ from rich.text import Text from rich_toolkit import RichToolkit from rich_toolkit.menu import Option +try: + import tomllib +except ModuleNotFoundError: + import tomli as tomllib from fastapi_cloud_cli.commands.login import login from fastapi_cloud_cli.utils.api import APIClient, StreamLogError, TooManyRetriesError @@ -39,9 +43,32 @@ def _cancel_upload(deployment_id: str) -> None: except Exception as e: logger.debug("Failed to notify server about upload cancellation: %s", e) +def _project_name_from_pyproject(path: Path) -> str: + if not path.exists(): + return "" + + try: + with path.open("rb") as f: + data = tomllib.load(f) + + project_name = data.get("project", {}).get("name") + if project_name: + return project_name + + poetry_name = data.get("tool", {}).get("poetry", {}).get("name") + if poetry_name: + return poetry_name + + except Exception: + return "" + + return "" def _get_app_name(path: Path) -> str: - # TODO: use pyproject.toml to get the app name + pyproject_path = path / "pyproject.toml" + name = _project_name_from_pyproject(pyproject_path) + if name: + return name return path.name diff --git a/uv.lock b/uv.lock index f1b7518..402b2df 100644 --- a/uv.lock +++ b/uv.lock @@ -364,6 +364,7 @@ dependencies = [ { name = "rich-toolkit" }, { name = "rignore" }, { name = "sentry-sdk" }, + { name = "tomli", marker = "python_full_version < '3.11'" }, { name = "typer" }, { name = "uvicorn", extra = ["standard"] }, ] @@ -393,6 +394,7 @@ requires-dist = [ { name = "rich-toolkit", specifier = ">=0.14.5" }, { name = "rignore", specifier = ">=0.5.1" }, { name = "sentry-sdk", specifier = ">=2.20.0" }, + { name = "tomli", marker = "python_full_version < '3.11'" }, { name = "typer", specifier = ">=0.12.3" }, { name = "uvicorn", extras = ["standard"], specifier = ">=0.15.0" }, { name = "uvicorn", extras = ["standard"], marker = "extra == 'standard'", specifier = ">=0.15.0" },