Skip to content

Commit 1feed0c

Browse files
committed
✨ Add support for retrieving app name from pyproject.toml
1 parent e19a14e commit 1feed0c

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ dependencies = [
3737
"pydantic[email] >= 2.0",
3838
"sentry-sdk >= 2.20.0",
3939
"fastar >= 0.8.0",
40+
"tomli; python_version < '3.11'",
4041
]
4142

4243
[project.optional-dependencies]

src/fastapi_cloud_cli/commands/deploy.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
from rich.text import Text
1818
from rich_toolkit import RichToolkit
1919
from rich_toolkit.menu import Option
20+
try:
21+
import tomllib
22+
except ModuleNotFoundError:
23+
import tomli as tomllib
2024

2125
from fastapi_cloud_cli.commands.login import login
2226
from fastapi_cloud_cli.utils.api import APIClient, StreamLogError, TooManyRetriesError
@@ -39,9 +43,32 @@ def _cancel_upload(deployment_id: str) -> None:
3943
except Exception as e:
4044
logger.debug("Failed to notify server about upload cancellation: %s", e)
4145

46+
def _project_name_from_pyproject(path: Path) -> str:
47+
if not path.exists():
48+
return ""
49+
50+
try:
51+
with path.open("rb") as f:
52+
data = tomllib.load(f)
53+
54+
project_name = data.get("project", {}).get("name")
55+
if project_name:
56+
return project_name
57+
58+
poetry_name = data.get("tool", {}).get("poetry", {}).get("name")
59+
if poetry_name:
60+
return poetry_name
61+
62+
except Exception:
63+
return ""
64+
65+
return ""
4266

4367
def _get_app_name(path: Path) -> str:
44-
# TODO: use pyproject.toml to get the app name
68+
pyproject_path = path / "pyproject.toml"
69+
name = _project_name_from_pyproject(pyproject_path)
70+
if name:
71+
return name
4572
return path.name
4673

4774

0 commit comments

Comments
 (0)