Skip to content

Commit cd37a8e

Browse files
authored
🚸 Show tip on how to configure entrypoint in pyproject.toml (#389)
1 parent 8c4ab66 commit cd37a8e

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

‎src/fastapi_cli/cli.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import typer
66
from pydantic import ValidationError
77
from rich import print
8+
from rich.syntax import Syntax
89
from rich.tree import Tree
910

1011
from fastapi_cli.config import FastAPIConfig
@@ -224,6 +225,24 @@ def _run(
224225
toolkit.print(f" • Module: {mod_source_desc}")
225226
toolkit.print(f" • App name: {app_source_desc}")
226227

228+
if import_data.module_config_source == "auto-discovery":
229+
toolkit.print_line()
230+
toolkit.print(
231+
"You can configure an entrypoint in [blue]pyproject.toml[/] for this app with:",
232+
tag="tip",
233+
)
234+
toolkit.print_line()
235+
toolkit.print(
236+
Syntax(
237+
(
238+
"[tool.fastapi]\n"
239+
f'entrypoint = "{import_data.module_data.module_import_str}:{import_data.app_name}"'
240+
),
241+
"toml",
242+
theme="ansi_light",
243+
)
244+
)
245+
227246
url = f"http://{host}:{port}"
228247
url_docs = f"{url}/docs"
229248

‎tests/test_cli.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def test_dev() -> None:
3838
assert "Configuration sources:" in result.output
3939
assert "Module: path CLI argument" in result.output
4040
assert "App name: auto-discovery" in result.output
41+
assert "You can configure an entrypoint in pyproject.toml" not in result.output
4142
assert "Starting development server 🚀" in result.output
4243
assert "Server started at http://127.0.0.1:8000" in result.output
4344
assert "Documentation at http://127.0.0.1:8000/docs" in result.output
@@ -64,6 +65,9 @@ def test_dev_no_args_auto_discovery() -> None:
6465
assert "Using import string: main:app" in result.output
6566
assert "Configuration sources:" in result.output
6667
assert "Import string: auto-discovery" in result.output
68+
assert "You can configure an entrypoint in pyproject.toml" in result.output
69+
assert "[tool.fastapi]" in result.output
70+
assert 'entrypoint = "main:app"' in result.output
6771

6872

6973
def test_dev_package() -> None:
@@ -88,6 +92,7 @@ def test_dev_package() -> None:
8892
assert "Using import string: nested_package.package:app" in result.output
8993
assert "Module: path CLI argument" in result.output
9094
assert "App name: auto-discovery" in result.output
95+
assert "You can configure an entrypoint in pyproject.toml" not in result.output
9196
assert "Starting development server 🚀" in result.output
9297
assert "Server started at http://127.0.0.1:8000" in result.output
9398
assert "Documentation at http://127.0.0.1:8000/docs" in result.output
@@ -140,6 +145,7 @@ def test_dev_args() -> None:
140145
assert "Using import string: single_file_app:api" in result.output
141146
assert "Module: path CLI argument" in result.output
142147
assert "App name: --app CLI option" in result.output
148+
assert "You can configure an entrypoint in pyproject.toml" not in result.output
143149
assert "Starting development server 🚀" in result.output
144150
assert "Server started at http://192.168.0.2:8080" in result.output
145151
assert "Documentation at http://192.168.0.2:8080/docs" in result.output
@@ -173,6 +179,7 @@ def test_dev_env_vars() -> None:
173179
assert "Using import string: single_file_app:app" in result.output
174180
assert "Module: path CLI argument" in result.output
175181
assert "App name: auto-discovery" in result.output
182+
assert "You can configure an entrypoint in pyproject.toml" not in result.output
176183
assert "Starting development server 🚀" in result.output
177184
assert "Server started at http://127.0.0.1:8111" in result.output
178185
assert "Documentation at http://127.0.0.1:8111/docs" in result.output
@@ -213,6 +220,7 @@ def test_dev_env_vars_and_args() -> None:
213220
assert "Using import string: single_file_app:app" in result.output
214221
assert "Module: path CLI argument" in result.output
215222
assert "App name: auto-discovery" in result.output
223+
assert "You can configure an entrypoint in pyproject.toml" not in result.output
216224
assert "Starting development server 🚀" in result.output
217225
assert "Server started at http://127.0.0.1:8080" in result.output
218226
assert "Documentation at http://127.0.0.1:8080/docs" in result.output
@@ -261,6 +269,7 @@ def test_run() -> None:
261269
assert "Using import string: single_file_app:app" in result.output
262270
assert "Module: path CLI argument" in result.output
263271
assert "App name: auto-discovery" in result.output
272+
assert "You can configure an entrypoint in pyproject.toml" not in result.output
264273
assert "Starting production server 🚀" in result.output
265274
assert "Server started at http://0.0.0.0:8000" in result.output
266275
assert "Documentation at http://0.0.0.0:8000/docs" in result.output
@@ -338,6 +347,7 @@ def test_run_args() -> None:
338347
assert "Using import string: single_file_app:api" in result.output
339348
assert "Module: path CLI argument" in result.output
340349
assert "App name: --app CLI option" in result.output
350+
assert "You can configure an entrypoint in pyproject.toml" not in result.output
341351
assert "Starting production server 🚀" in result.output
342352
assert "Server started at http://192.168.0.2:8080" in result.output
343353
assert "Documentation at http://192.168.0.2:8080/docs" in result.output
@@ -371,6 +381,7 @@ def test_run_env_vars() -> None:
371381
assert "Using import string: single_file_app:app" in result.output
372382
assert "Module: path CLI argument" in result.output
373383
assert "App name: auto-discovery" in result.output
384+
assert "You can configure an entrypoint in pyproject.toml" not in result.output
374385
assert "Starting production server 🚀" in result.output
375386
assert "Server started at http://0.0.0.0:8111" in result.output
376387
assert "Documentation at http://0.0.0.0:8111/docs" in result.output
@@ -407,6 +418,7 @@ def test_run_env_vars_and_args() -> None:
407418
assert "Using import string: single_file_app:app" in result.output
408419
assert "Module: path CLI argument" in result.output
409420
assert "App name: auto-discovery" in result.output
421+
assert "You can configure an entrypoint in pyproject.toml" not in result.output
410422
assert "Starting production server 🚀" in result.output
411423
assert "Server started at http://0.0.0.0:8080" in result.output
412424
assert "Documentation at http://0.0.0.0:8080/docs" in result.output
@@ -521,6 +533,7 @@ def test_dev_with_import_string() -> None:
521533
}
522534
assert "Using import string: single_file_app:api" in result.output
523535
assert "Import string: --entrypoint CLI option" in result.output
536+
assert "You can configure an entrypoint in pyproject.toml" not in result.output
524537

525538

526539
def test_run_with_import_string() -> None:
@@ -544,6 +557,7 @@ def test_run_with_import_string() -> None:
544557
}
545558
assert "Using import string: single_file_app:app" in result.output
546559
assert "Import string: --entrypoint CLI option" in result.output
560+
assert "You can configure an entrypoint in pyproject.toml" not in result.output
547561

548562

549563
def test_script() -> None:

0 commit comments

Comments
 (0)