Skip to content

Commit e7cbd61

Browse files
committed
✨ Allow to specify application directory
Shortcake-Parent: improve-how-we-handle-invalid-tokens
1 parent ba30f49 commit e7cbd61

6 files changed

Lines changed: 33 additions & 9 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ dependencies = [
3333
"uvicorn[standard] >= 0.15.0",
3434
"rignore >= 0.5.1",
3535
"httpx >= 0.27.0",
36-
"rich-toolkit >= 0.14.5",
36+
"rich-toolkit >= 0.19.2",
3737
"pydantic[email] >= 2.0",
3838
"sentry-sdk >= 2.20.0",
3939
"fastar >= 0.8.0",

src/fastapi_cloud_cli/commands/deploy.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,23 @@ def _configure_app(toolkit: RichToolkit, path_to_deploy: Path) -> AppConfig:
332332

333333
toolkit.print_line()
334334

335+
directory_input = toolkit.input(
336+
title="Path to the directory containing your app",
337+
tag="dir",
338+
default="",
339+
placeholder="[italic]Leave empty if it's the current directory[/italic]",
340+
)
341+
342+
directory: Optional[str] = directory_input if directory_input else None
343+
344+
toolkit.print_line()
345+
335346
toolkit.print("Deployment configuration:", tag="summary")
336347
toolkit.print_line()
337348
toolkit.print(f"Team: [bold]{team.name}[/bold]")
338349
toolkit.print(f"App name: [bold]{app_name}[/bold]")
350+
if directory:
351+
toolkit.print(f"Directory: [bold]{directory}[/bold]")
339352
toolkit.print_line()
340353

341354
choice = toolkit.ask(
@@ -361,7 +374,7 @@ def _configure_app(toolkit: RichToolkit, path_to_deploy: Path) -> AppConfig:
361374

362375
progress.log(f"App created successfully! App slug: {app.slug}")
363376

364-
app_config = AppConfig(app_id=app.id, team_id=team.id)
377+
app_config = AppConfig(app_id=app.id, team_id=team.id, directory=directory)
365378

366379
write_app_config(path_to_deploy, app_config)
367380

@@ -674,7 +687,12 @@ def deploy(
674687
with tempfile.TemporaryDirectory() as temp_dir:
675688
logger.debug("Creating archive for deployment")
676689
archive_path = Path(temp_dir) / "archive.tar"
677-
archive(path or Path.cwd(), archive_path)
690+
691+
deploy_path = path or Path.cwd()
692+
if app_config and app_config.directory:
693+
deploy_path = deploy_path / app_config.directory
694+
695+
archive(deploy_path, archive_path)
678696

679697
with (
680698
toolkit.progress(title="Creating deployment") as progress,

src/fastapi_cloud_cli/utils/apps.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
class AppConfig(BaseModel):
1111
app_id: str
1212
team_id: str
13+
directory: Optional[str] = None
1314

1415

1516
def get_app_config(path_to_deploy: Path) -> Optional[AppConfig]:
@@ -32,6 +33,7 @@ def get_app_config(path_to_deploy: Path) -> Optional[AppConfig]:
3233
The "cloud.json" file contains:
3334
- The ID of the FastAPI app that you linked ("app_id")
3435
- The ID of the team your FastAPI Cloud project is owned by ("team_id")
36+
- Optionally, the directory within your repo that contains the app ("directory")
3537
3638
> Should I commit the ".fastapicloud" folder?
3739
No, you should not commit the ".fastapicloud" folder to your version control system.

src/fastapi_cloud_cli/utils/cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@ def get_rich_toolkit(minimal: bool = False) -> RichToolkit:
5656
theme={
5757
"tag.title": "white on #009485",
5858
"tag": "white on #007166",
59-
"placeholder": "grey85",
59+
"placeholder": "grey62",
6060
"text": "white",
6161
"selected": "#007166",
6262
"result": "grey85",
6363
"progress": "on #007166",
6464
"error": "red",
65+
"cancelled": "indian_red italic",
6566
},
6667
)
6768

tests/test_cli_deploy.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def test_asks_for_app_name_after_team(
318318
def test_creates_app_on_backend(
319319
logged_in_cli: None, tmp_path: Path, respx_mock: respx.MockRouter
320320
) -> None:
321-
steps = [Keys.ENTER, Keys.ENTER, *"demo", Keys.ENTER, Keys.ENTER]
321+
steps = [Keys.ENTER, Keys.ENTER, *"demo", Keys.ENTER, Keys.ENTER, Keys.ENTER]
322322

323323
team = _get_random_team()
324324

@@ -355,6 +355,7 @@ def test_cancels_deployment_when_user_selects_no(
355355
Keys.ENTER,
356356
*"demo",
357357
Keys.ENTER,
358+
Keys.ENTER,
358359
Keys.DOWN_ARROW,
359360
Keys.ENTER,
360361
]
@@ -420,6 +421,7 @@ def test_exits_successfully_when_deployment_is_done(
420421
*"demo",
421422
Keys.ENTER,
422423
Keys.ENTER,
424+
Keys.ENTER,
423425
]
424426

425427
team_data = _get_random_team()
@@ -671,6 +673,7 @@ def _deploy_without_waiting(respx_mock: respx.MockRouter, tmp_path: Path) -> Res
671673
*"demo",
672674
Keys.ENTER,
673675
Keys.ENTER,
676+
Keys.ENTER,
674677
]
675678

676679
team_data = _get_random_team()

uv.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)