fastapi-cli 0.0.4__tar.gz → 0.0.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/PKG-INFO +44 -56
  2. fastapi_cli-0.0.6/README.md +94 -0
  3. fastapi_cli-0.0.6/pdm_build.py +20 -0
  4. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/pyproject.toml +14 -11
  5. fastapi_cli-0.0.6/requirements-github-actions.txt +1 -0
  6. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/requirements-tests.txt +2 -2
  7. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/requirements.txt +1 -1
  8. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/scripts/format.sh +1 -1
  9. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/scripts/test-cov-html.sh +1 -1
  10. fastapi_cli-0.0.6/src/fastapi_cli/__init__.py +1 -0
  11. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/src/fastapi_cli/cli.py +114 -43
  12. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/src/fastapi_cli/discover.py +38 -77
  13. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/src/fastapi_cli/logging.py +4 -2
  14. fastapi_cli-0.0.6/src/fastapi_cli/utils/cli.py +75 -0
  15. fastapi_cli-0.0.6/tests/assets/nested_package/__init__.py +0 -0
  16. fastapi_cli-0.0.6/tests/assets/nested_package/package/core/__init__.py +0 -0
  17. fastapi_cli-0.0.6/tests/assets/package/__init__.py +2 -0
  18. fastapi_cli-0.0.6/tests/assets/package/core/__init__.py +0 -0
  19. fastapi_cli-0.0.6/tests/assets/package/core/utils.py +2 -0
  20. fastapi_cli-0.0.6/tests/assets/package/mod/__init__.py +1 -0
  21. fastapi_cli-0.0.6/tests/assets/package/mod/api.py +24 -0
  22. fastapi_cli-0.0.6/tests/assets/package/mod/app.py +32 -0
  23. fastapi_cli-0.0.6/tests/assets/package/mod/other.py +16 -0
  24. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/test_cli.py +64 -24
  25. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/test_requirements.py +2 -2
  26. fastapi_cli-0.0.6/tests/test_utils_cli.py +35 -0
  27. fastapi_cli-0.0.6/tests/test_utils_default_dir.py +52 -0
  28. fastapi_cli-0.0.6/tests/test_utils_default_file.py +73 -0
  29. fastapi_cli-0.0.6/tests/test_utils_package.py +197 -0
  30. fastapi_cli-0.0.6/tests/test_utils_single_file.py +59 -0
  31. fastapi_cli-0.0.4/README.md +0 -107
  32. fastapi_cli-0.0.4/pdm_build.py +0 -39
  33. fastapi_cli-0.0.4/src/fastapi_cli/__init__.py +0 -1
  34. fastapi_cli-0.0.4/tests/test_utils_default_dir.py +0 -88
  35. fastapi_cli-0.0.4/tests/test_utils_default_file.py +0 -103
  36. fastapi_cli-0.0.4/tests/test_utils_package.py +0 -455
  37. fastapi_cli-0.0.4/tests/test_utils_single_file.py +0 -115
  38. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/LICENSE +0 -0
  39. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/scripts/lint.sh +0 -0
  40. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/scripts/test.sh +0 -0
  41. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/src/fastapi_cli/__main__.py +0 -0
  42. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/src/fastapi_cli/exceptions.py +0 -0
  43. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/src/fastapi_cli/py.typed +0 -0
  44. {fastapi_cli-0.0.4/tests → fastapi_cli-0.0.6/src/fastapi_cli/utils}/__init__.py +0 -0
  45. {fastapi_cli-0.0.4/tests/assets/default_files/default_app_dir_api/app → fastapi_cli-0.0.6/tests}/__init__.py +0 -0
  46. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/broken_package/mod/__init__.py +0 -0
  47. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/broken_package/mod/app.py +0 -0
  48. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/broken_package/utils.py +0 -0
  49. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_api/api.py +0 -0
  50. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_app/api.py +0 -0
  51. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_app/app.py +0 -0
  52. {fastapi_cli-0.0.4/tests/assets/default_files/default_app_dir_app → fastapi_cli-0.0.6/tests/assets/default_files/default_app_dir_api}/app/__init__.py +0 -0
  53. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_app_dir_api/app/api.py +0 -0
  54. {fastapi_cli-0.0.4/tests/assets/default_files/default_app_dir_main → fastapi_cli-0.0.6/tests/assets/default_files/default_app_dir_app}/app/__init__.py +0 -0
  55. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_app_dir_app/app/api.py +0 -0
  56. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_app_dir_app/app/app.py +0 -0
  57. {fastapi_cli-0.0.4/tests/assets/default_files/default_app_dir_non_default → fastapi_cli-0.0.6/tests/assets/default_files/default_app_dir_main}/app/__init__.py +0 -0
  58. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_app_dir_main/app/api.py +0 -0
  59. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_app_dir_main/app/app.py +0 -0
  60. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_app_dir_main/app/main.py +0 -0
  61. {fastapi_cli-0.0.4/tests/assets/package/core → fastapi_cli-0.0.6/tests/assets/default_files/default_app_dir_non_default/app}/__init__.py +0 -0
  62. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_app_dir_non_default/app/nondefault.py +0 -0
  63. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_main/api.py +0 -0
  64. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_main/app.py +0 -0
  65. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_main/main.py +0 -0
  66. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/non_default/nonstandard.py +0 -0
  67. {fastapi_cli-0.0.4/tests/assets → fastapi_cli-0.0.6/tests/assets/nested_package}/package/__init__.py +0 -0
  68. {fastapi_cli-0.0.4/tests/assets → fastapi_cli-0.0.6/tests/assets/nested_package}/package/core/utils.py +0 -0
  69. {fastapi_cli-0.0.4/tests/assets → fastapi_cli-0.0.6/tests/assets/nested_package}/package/mod/__init__.py +0 -0
  70. {fastapi_cli-0.0.4/tests/assets → fastapi_cli-0.0.6/tests/assets/nested_package}/package/mod/api.py +0 -0
  71. {fastapi_cli-0.0.4/tests/assets → fastapi_cli-0.0.6/tests/assets/nested_package}/package/mod/app.py +0 -0
  72. {fastapi_cli-0.0.4/tests/assets → fastapi_cli-0.0.6/tests/assets/nested_package}/package/mod/other.py +0 -0
  73. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/single_file_api.py +0 -0
  74. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/single_file_app.py +0 -0
  75. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/single_file_other.py +0 -0
  76. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/conftest.py +0 -0
  77. {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/utils.py +0 -0
@@ -1,8 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fastapi-cli
3
- Version: 0.0.4
3
+ Version: 0.0.6
4
4
  Summary: Run and manage FastAPI apps from the command line with FastAPI CLI. 🚀
5
- Home-page: https://github.com/tiangolo/fastapi-cli
6
5
  Author-Email: =?utf-8?q?Sebasti=C3=A1n_Ram=C3=ADrez?= <tiangolo@gmail.com>
7
6
  License: MIT
8
7
  Classifier: Intended Audience :: Information Technology
@@ -20,40 +19,42 @@ Classifier: Framework :: FastAPI
20
19
  Classifier: Intended Audience :: Developers
21
20
  Classifier: License :: OSI Approved :: MIT License
22
21
  Classifier: Programming Language :: Python :: 3 :: Only
23
- Classifier: Programming Language :: Python :: 3.7
24
22
  Classifier: Programming Language :: Python :: 3.8
25
23
  Classifier: Programming Language :: Python :: 3.9
26
24
  Classifier: Programming Language :: Python :: 3.10
27
25
  Classifier: Programming Language :: Python :: 3.11
28
26
  Classifier: Programming Language :: Python :: 3.12
29
27
  Classifier: License :: OSI Approved :: MIT License
30
- Project-URL: Documentation, https://fastapi.tiangolo.com
31
- Project-URL: Homepage, https://github.com/tiangolo/fastapi-cli
32
- Project-URL: Repository, https://github.com/tiangolo/fastapi-cli
28
+ Project-URL: Homepage, https://github.com/fastapi/fastapi-cli
29
+ Project-URL: Documentation, https://fastapi.tiangolo.com/fastapi-cli/
30
+ Project-URL: Repository, https://github.com/fastapi/fastapi-cli
31
+ Project-URL: Issues, https://github.com/fastapi/fastapi-cli/issues
32
+ Project-URL: Changelog, https://github.com/fastapi/fastapi-cli/blob/main/release-notes.md
33
33
  Requires-Python: >=3.8
34
34
  Requires-Dist: typer>=0.12.3
35
- Requires-Dist: fastapi; extra == "standard"
36
- Requires-Dist: uvicorn[standard]>=0.15.0; extra == "standard"
35
+ Requires-Dist: uvicorn[standard]>=0.15.0
36
+ Requires-Dist: rich-toolkit>=0.11.1
37
37
  Provides-Extra: standard
38
+ Requires-Dist: uvicorn[standard]>=0.15.0; extra == "standard"
38
39
  Description-Content-Type: text/markdown
39
40
 
40
41
  # FastAPI CLI
41
42
 
42
- <a href="https://github.com/tiangolo/fastapi-cli/actions/workflows/test.yml" target="_blank">
43
- <img src="https://github.com/tiangolo/fastapi-cli/actions/workflows/test.yml/badge.svg" alt="Test">
43
+ <a href="https://github.com/fastapi/fastapi-cli/actions/workflows/test.yml" target="_blank">
44
+ <img src="https://github.com/fastapi/fastapi-cli/actions/workflows/test.yml/badge.svg" alt="Test">
44
45
  </a>
45
- <a href="https://github.com/tiangolo/fastapi-cli/actions/workflows/publish.yml" target="_blank">
46
- <img src="https://github.com/tiangolo/fastapi-cli/actions/workflows/publish.yml/badge.svg" alt="Publish">
46
+ <a href="https://github.com/fastapi/fastapi-cli/actions/workflows/publish.yml" target="_blank">
47
+ <img src="https://github.com/fastapi/fastapi-cli/actions/workflows/publish.yml/badge.svg" alt="Publish">
47
48
  </a>
48
- <a href="https://coverage-badge.samuelcolvin.workers.dev/redirect/tiangolo/fastapi-cli" target="_blank">
49
- <img src="https://coverage-badge.samuelcolvin.workers.dev/tiangolo/fastapi-cli.svg" alt="Coverage">
49
+ <a href="https://coverage-badge.samuelcolvin.workers.dev/redirect/fastapi/fastapi-cli" target="_blank">
50
+ <img src="https://coverage-badge.samuelcolvin.workers.dev/fastapi/fastapi-cli.svg" alt="Coverage">
50
51
  <a href="https://pypi.org/project/fastapi-cli" target="_blank">
51
52
  <img src="https://img.shields.io/pypi/v/fastapi-cli?color=%2334D058&label=pypi%20package" alt="Package version">
52
53
  </a>
53
54
 
54
55
  ---
55
56
 
56
- **Source Code**: <a href="https://github.com/tiangolo/fastapi-cli" target="_blank">https://github.com/tiangolo/fastapi-cli</a>
57
+ **Source Code**: <a href="https://github.com/fastapi/fastapi-cli" target="_blank">https://github.com/fastapi/fastapi-cli</a>
57
58
 
58
59
  ---
59
60
 
@@ -63,7 +64,7 @@ Run and manage FastAPI apps from the command line with FastAPI CLI. 🚀
63
64
 
64
65
  **FastAPI CLI** is a command line program `fastapi` that you can use to serve your FastAPI app, manage your FastAPI project, and more.
65
66
 
66
- When you install FastAPI (e.g. with `pip install fastapi`), it includes a package called `fastapi-cli`, this package provides the `fastapi` command in the terminal.
67
+ When you install FastAPI (e.g. with `pip install "fastapi[standard]"`), it includes a package called `fastapi-cli`, this package provides the `fastapi` command in the terminal.
67
68
 
68
69
  To run your FastAPI app for development, you can use the `fastapi dev` command:
69
70
 
@@ -71,46 +72,33 @@ To run your FastAPI app for development, you can use the `fastapi dev` command:
71
72
 
72
73
  ```console
73
74
  $ fastapi dev main.py
74
- INFO Using path main.py
75
- INFO Resolved absolute path /home/user/code/awesomeapp/main.py
76
- INFO Searching for package file structure from directories with __init__.py files
77
- INFO Importing from /home/user/code/awesomeapp
78
-
79
- ╭─ Python module file ─╮
80
- │ │
81
- │ 🐍 main.py │
82
- │ │
83
- ╰──────────────────────╯
84
-
85
- INFO Importing module main
86
- INFO Found importable FastAPI app
87
-
88
- ╭─ Importable FastAPI app ─╮
89
- │ │
90
- │ from main import app │
91
- │ │
92
- ╰──────────────────────────╯
93
-
94
- INFO Using import string main:app
95
-
96
- ╭────────── FastAPI CLI - Development mode ───────────╮
97
- │ │
98
- │ Serving at: http://127.0.0.1:8000 │
99
- │ │
100
- │ API docs: http://127.0.0.1:8000/docs │
101
- │ │
102
- │ Running in development mode, for production use: │
103
- │ │
104
- │ fastapi run │
105
- │ │
106
- ╰─────────────────────────────────────────────────────╯
107
-
108
- INFO: Will watch for changes in these directories: ['/home/user/code/awesomeapp']
109
- INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
110
- INFO: Started reloader process [56345] using WatchFiles
111
- INFO: Started server process [56352]
112
- INFO: Waiting for application startup.
113
- INFO: Application startup complete.
75
+
76
+ FastAPI Starting development server 🚀
77
+
78
+ Searching for package file structure from directories with __init__.py files
79
+ Importing from /home/user/code/awesomeapp
80
+
81
+ module 🐍 main.py
82
+
83
+ code Importing the FastAPI app object from the module with the following code:
84
+
85
+ from main import app
86
+
87
+ app Using import string: main:app
88
+
89
+ server Server started at http://127.0.0.1:8000
90
+ server Documentation at http://127.0.0.1:8000/docs
91
+
92
+ tip Running in development mode, for production use: fastapi run
93
+
94
+ Logs:
95
+
96
+ INFO Will watch for changes in these directories: ['/home/user/code/awesomeapp']
97
+ INFO Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
98
+ INFO Started reloader process [4106097] using WatchFiles
99
+ INFO Started server process [4106120]
100
+ INFO Waiting for application startup.
101
+ INFO Application startup complete.
114
102
  ```
115
103
 
116
104
  </div>
@@ -0,0 +1,94 @@
1
+ # FastAPI CLI
2
+
3
+ <a href="https://github.com/fastapi/fastapi-cli/actions/workflows/test.yml" target="_blank">
4
+ <img src="https://github.com/fastapi/fastapi-cli/actions/workflows/test.yml/badge.svg" alt="Test">
5
+ </a>
6
+ <a href="https://github.com/fastapi/fastapi-cli/actions/workflows/publish.yml" target="_blank">
7
+ <img src="https://github.com/fastapi/fastapi-cli/actions/workflows/publish.yml/badge.svg" alt="Publish">
8
+ </a>
9
+ <a href="https://coverage-badge.samuelcolvin.workers.dev/redirect/fastapi/fastapi-cli" target="_blank">
10
+ <img src="https://coverage-badge.samuelcolvin.workers.dev/fastapi/fastapi-cli.svg" alt="Coverage">
11
+ <a href="https://pypi.org/project/fastapi-cli" target="_blank">
12
+ <img src="https://img.shields.io/pypi/v/fastapi-cli?color=%2334D058&label=pypi%20package" alt="Package version">
13
+ </a>
14
+
15
+ ---
16
+
17
+ **Source Code**: <a href="https://github.com/fastapi/fastapi-cli" target="_blank">https://github.com/fastapi/fastapi-cli</a>
18
+
19
+ ---
20
+
21
+ Run and manage FastAPI apps from the command line with FastAPI CLI. 🚀
22
+
23
+ ## Description
24
+
25
+ **FastAPI CLI** is a command line program `fastapi` that you can use to serve your FastAPI app, manage your FastAPI project, and more.
26
+
27
+ When you install FastAPI (e.g. with `pip install "fastapi[standard]"`), it includes a package called `fastapi-cli`, this package provides the `fastapi` command in the terminal.
28
+
29
+ To run your FastAPI app for development, you can use the `fastapi dev` command:
30
+
31
+ <div class="termy">
32
+
33
+ ```console
34
+ $ fastapi dev main.py
35
+
36
+ FastAPI Starting development server 🚀
37
+
38
+ Searching for package file structure from directories with __init__.py files
39
+ Importing from /home/user/code/awesomeapp
40
+
41
+ module 🐍 main.py
42
+
43
+ code Importing the FastAPI app object from the module with the following code:
44
+
45
+ from main import app
46
+
47
+ app Using import string: main:app
48
+
49
+ server Server started at http://127.0.0.1:8000
50
+ server Documentation at http://127.0.0.1:8000/docs
51
+
52
+ tip Running in development mode, for production use: fastapi run
53
+
54
+ Logs:
55
+
56
+ INFO Will watch for changes in these directories: ['/home/user/code/awesomeapp']
57
+ INFO Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
58
+ INFO Started reloader process [4106097] using WatchFiles
59
+ INFO Started server process [4106120]
60
+ INFO Waiting for application startup.
61
+ INFO Application startup complete.
62
+ ```
63
+
64
+ </div>
65
+
66
+ That command line program called `fastapi` is **FastAPI CLI**.
67
+
68
+ FastAPI CLI takes the path to your Python program and automatically detects the variable with the FastAPI (commonly named `app`) and how to import it, and then serves it.
69
+
70
+ For production you would use `fastapi run` instead. 🚀
71
+
72
+ Internally, **FastAPI CLI** uses <a href="https://www.uvicorn.org" class="external-link" target="_blank">Uvicorn</a>, a high-performance, production-ready, ASGI server. 😎
73
+
74
+ ## `fastapi dev`
75
+
76
+ When you run `fastapi dev`, it will run on development mode.
77
+
78
+ By default, it will have **auto-reload** enabled, so it will automatically reload the server when you make changes to your code. This is resource intensive and could be less stable than without it, you should only use it for development.
79
+
80
+ By default it will listen on the IP address `127.0.0.1`, which is the IP for your machine to communicate with itself alone (`localhost`).
81
+
82
+ ## `fastapi run`
83
+
84
+ When you run `fastapi run`, it will run on production mode by default.
85
+
86
+ It will have **auto-reload disabled** by default.
87
+
88
+ It will listen on the IP address `0.0.0.0`, which means all the available IP addresses, this way it will be publicly accessible to anyone that can communicate with the machine. This is how you would normally run it in production, for example, in a container.
89
+
90
+ In most cases you would (and should) have a "termination proxy" handling HTTPS for you on top, this will depend on how you deploy your application, your provider might do this for you, or you might need to set it up yourself. You can learn more about it in the <a href="https://fastapi.tiangolo.com/deployment/" class="external-link" target="_blank">FastAPI Deployment documentation</a>.
91
+
92
+ ## License
93
+
94
+ This project is licensed under the terms of the MIT license.
@@ -0,0 +1,20 @@
1
+ import os
2
+ from typing import Any, Dict
3
+
4
+ from pdm.backend.hooks import Context
5
+
6
+ TIANGOLO_BUILD_PACKAGE = os.getenv("TIANGOLO_BUILD_PACKAGE", "fastapi-cli")
7
+
8
+
9
+ def pdm_build_initialize(context: Context):
10
+ metadata = context.config.metadata
11
+ # Get custom config for the current package, from the env var
12
+ config: Dict[str, Any] = context.config.data["tool"]["tiangolo"][
13
+ "_internal-slim-build"
14
+ ]["packages"].get(TIANGOLO_BUILD_PACKAGE)
15
+ if not config:
16
+ return
17
+ project_config: Dict[str, Any] = config["project"]
18
+ # Override main [project] configs with custom configs for this package
19
+ for key, value in project_config.items():
20
+ metadata[key] = value
@@ -23,7 +23,6 @@ classifiers = [
23
23
  "Intended Audience :: Developers",
24
24
  "License :: OSI Approved :: MIT License",
25
25
  "Programming Language :: Python :: 3 :: Only",
26
- "Programming Language :: Python :: 3.7",
27
26
  "Programming Language :: Python :: 3.8",
28
27
  "Programming Language :: Python :: 3.9",
29
28
  "Programming Language :: Python :: 3.10",
@@ -33,22 +32,25 @@ classifiers = [
33
32
  ]
34
33
  dependencies = [
35
34
  "typer >= 0.12.3",
35
+ "uvicorn[standard] >= 0.15.0",
36
+ "rich-toolkit >= 0.11.1",
36
37
  ]
37
- version = "0.0.4"
38
+ version = "0.0.6"
38
39
 
39
40
  [project.license]
40
41
  text = "MIT"
41
42
 
42
43
  [project.optional-dependencies]
43
44
  standard = [
44
- "fastapi",
45
45
  "uvicorn[standard] >= 0.15.0",
46
46
  ]
47
47
 
48
48
  [project.urls]
49
- Documentation = "https://fastapi.tiangolo.com"
50
- homepage = "https://github.com/tiangolo/fastapi-cli"
51
- Repository = "https://github.com/tiangolo/fastapi-cli"
49
+ Homepage = "https://github.com/fastapi/fastapi-cli"
50
+ Documentation = "https://fastapi.tiangolo.com/fastapi-cli/"
51
+ Repository = "https://github.com/fastapi/fastapi-cli"
52
+ Issues = "https://github.com/fastapi/fastapi-cli/issues"
53
+ Changelog = "https://github.com/fastapi/fastapi-cli/blob/main/release-notes.md"
52
54
 
53
55
  [project.scripts]
54
56
  fastapi = "fastapi_cli.cli:main"
@@ -76,11 +78,6 @@ source-includes = [
76
78
  [tool.tiangolo._internal-slim-build.packages.fastapi-cli-slim.project]
77
79
  name = "fastapi-cli-slim"
78
80
 
79
- [tool.tiangolo._internal-slim-build.packages.fastapi-cli]
80
- include-optional-dependencies = []
81
-
82
- [tool.tiangolo._internal-slim-build.packages.fastapi-cli.project]
83
-
84
81
  [tool.pytest.ini_options]
85
82
  addopts = [
86
83
  "--strict-config",
@@ -97,11 +94,14 @@ source = [
97
94
  "tests",
98
95
  ]
99
96
  context = "${CONTEXT}"
97
+ dynamic_context = "test_function"
100
98
  omit = [
101
99
  "tests/assets/*",
102
100
  ]
103
101
 
104
102
  [tool.coverage.report]
103
+ show_missing = true
104
+ sort = "-Cover"
105
105
  exclude_lines = [
106
106
  "pragma: no cover",
107
107
  "@overload",
@@ -109,6 +109,9 @@ exclude_lines = [
109
109
  "if TYPE_CHECKING:",
110
110
  ]
111
111
 
112
+ [tool.coverage.html]
113
+ show_contexts = true
114
+
112
115
  [tool.mypy]
113
116
  strict = true
114
117
  exclude = [
@@ -0,0 +1 @@
1
+ smokeshow
@@ -2,8 +2,8 @@
2
2
 
3
3
  pytest >=4.4.0,<9.0.0
4
4
  coverage[toml] >=6.2,<8.0
5
- mypy ==1.10.0
6
- ruff ==0.4.3
5
+ mypy ==1.13.0
6
+ ruff ==0.5.5
7
7
  # Needed explicitly by fastapi-cli-slim
8
8
  fastapi-slim
9
9
  uvicorn
@@ -2,4 +2,4 @@
2
2
 
3
3
  -r requirements-tests.txt
4
4
 
5
- pre-commit >=2.17.0,<4.0.0
5
+ pre-commit >=2.17.0,<5.0.0
@@ -2,5 +2,5 @@
2
2
  set -x
3
3
  set -e
4
4
 
5
- ruff src tests scripts --fix
5
+ ruff check src tests scripts --fix
6
6
  ruff format src tests scripts
@@ -5,5 +5,5 @@ set -x
5
5
 
6
6
  bash scripts/test.sh ${@}
7
7
  coverage combine
8
- coverage report --show-missing
8
+ coverage report
9
9
  coverage html
@@ -0,0 +1 @@
1
+ __version__ = "0.0.6"
@@ -1,23 +1,23 @@
1
- from logging import getLogger
1
+ import logging
2
2
  from pathlib import Path
3
- from typing import Any, Union
3
+ from typing import Any, List, Union
4
4
 
5
5
  import typer
6
6
  from rich import print
7
- from rich.padding import Padding
8
- from rich.panel import Panel
7
+ from rich.tree import Tree
9
8
  from typing_extensions import Annotated
10
9
 
11
- from fastapi_cli.discover import get_import_string
10
+ from fastapi_cli.discover import get_import_data
12
11
  from fastapi_cli.exceptions import FastAPICLIException
13
12
 
14
13
  from . import __version__
15
14
  from .logging import setup_logging
15
+ from .utils.cli import get_rich_toolkit, get_uvicorn_log_config
16
16
 
17
17
  app = typer.Typer(rich_markup_mode="rich")
18
18
 
19
- setup_logging()
20
- logger = getLogger(__name__)
19
+ logger = logging.getLogger(__name__)
20
+
21
21
 
22
22
  try:
23
23
  import uvicorn
@@ -39,15 +39,41 @@ def callback(
39
39
  "--version", help="Show the version and exit.", callback=version_callback
40
40
  ),
41
41
  ] = None,
42
+ verbose: bool = typer.Option(False, help="Enable verbose output"),
42
43
  ) -> None:
43
44
  """
44
45
  FastAPI CLI - The [bold]fastapi[/bold] command line app. 😎
45
46
 
46
47
  Manage your [bold]FastAPI[/bold] projects, run your FastAPI apps, and more.
47
48
 
48
- Read more in the docs: [link]https://fastapi.tiangolo.com/fastapi-cli/[/link].
49
+ Read more in the docs: [link=https://fastapi.tiangolo.com/fastapi-cli/]https://fastapi.tiangolo.com/fastapi-cli/[/link].
49
50
  """
50
51
 
52
+ log_level = logging.DEBUG if verbose else logging.INFO
53
+
54
+ setup_logging(level=log_level)
55
+
56
+
57
+ def _get_module_tree(module_paths: List[Path]) -> Tree:
58
+ root = module_paths[0]
59
+ name = f"🐍 {root.name}" if root.is_file() else f"📁 {root.name}"
60
+
61
+ root_tree = Tree(name)
62
+
63
+ if root.is_dir():
64
+ root_tree.add("[dim]🐍 __init__.py[/dim]")
65
+
66
+ tree = root_tree
67
+ for sub_path in module_paths[1:]:
68
+ sub_name = (
69
+ f"🐍 {sub_path.name}" if sub_path.is_file() else f"📁 {sub_path.name}"
70
+ )
71
+ tree = tree.add(sub_name)
72
+ if sub_path.is_dir():
73
+ tree.add("[dim]🐍 __init__.py[/dim]")
74
+
75
+ return root_tree
76
+
51
77
 
52
78
  def _run(
53
79
  path: Union[Path, None] = None,
@@ -61,43 +87,88 @@ def _run(
61
87
  app: Union[str, None] = None,
62
88
  proxy_headers: bool = False,
63
89
  ) -> None:
64
- try:
65
- use_uvicorn_app = get_import_string(path=path, app_name=app)
66
- except FastAPICLIException as e:
67
- logger.error(str(e))
68
- raise typer.Exit(code=1) from None
69
- serving_str = f"[dim]Serving at:[/dim] [link]http://{host}:{port}[/link]\n\n[dim]API docs:[/dim] [link]http://{host}:{port}/docs[/link]"
70
-
71
- if command == "dev":
72
- panel = Panel(
73
- f"{serving_str}\n\n[dim]Running in development mode, for production use:[/dim] \n\n[b]fastapi run[/b]",
74
- title="FastAPI CLI - Development mode",
75
- expand=False,
76
- padding=(1, 2),
77
- style="black on yellow",
90
+ with get_rich_toolkit() as toolkit:
91
+ server_type = "development" if command == "dev" else "production"
92
+
93
+ toolkit.print_title(f"Starting {server_type} server 🚀", tag="FastAPI")
94
+ toolkit.print_line()
95
+
96
+ toolkit.print(
97
+ "Searching for package file structure from directories with [blue]__init__.py[/blue] files"
98
+ )
99
+
100
+ try:
101
+ import_data = get_import_data(path=path, app_name=app)
102
+ except FastAPICLIException as e:
103
+ toolkit.print_line()
104
+ toolkit.print(f"[error]{e}")
105
+ raise typer.Exit(code=1) from None
106
+
107
+ logger.debug(f"Importing from {import_data.module_data.extra_sys_path}")
108
+ logger.debug(f"Importing module {import_data.module_data.module_import_str}")
109
+
110
+ module_data = import_data.module_data
111
+ import_string = import_data.import_string
112
+
113
+ toolkit.print(f"Importing from {module_data.extra_sys_path}")
114
+ toolkit.print_line()
115
+
116
+ root_tree = _get_module_tree(module_data.module_paths)
117
+
118
+ toolkit.print(root_tree, tag="module")
119
+ toolkit.print_line()
120
+
121
+ toolkit.print(
122
+ "Importing the FastAPI app object from the module with the following code:",
123
+ tag="code",
78
124
  )
79
- else:
80
- panel = Panel(
81
- f"{serving_str}\n\n[dim]Running in production mode, for development use:[/dim] \n\n[b]fastapi dev[/b]",
82
- title="FastAPI CLI - Production mode",
83
- expand=False,
84
- padding=(1, 2),
85
- style="green",
125
+ toolkit.print_line()
126
+ toolkit.print(
127
+ f"[underline]from [bold]{module_data.module_import_str}[/bold] import [bold]{import_data.app_name}[/bold]"
128
+ )
129
+ toolkit.print_line()
130
+
131
+ toolkit.print(
132
+ f"Using import string: [blue]{import_string}[/]",
133
+ tag="app",
134
+ )
135
+
136
+ url = f"http://{host}:{port}"
137
+ url_docs = f"{url}/docs"
138
+
139
+ toolkit.print_line()
140
+ toolkit.print(
141
+ f"Server started at [link={url}]{url}[/]",
142
+ f"Documentation at [link={url_docs}]{url_docs}[/]",
143
+ tag="server",
144
+ )
145
+
146
+ if command == "dev":
147
+ toolkit.print_line()
148
+ toolkit.print(
149
+ "Running in development mode, for production use: [bold]fastapi run[/]",
150
+ tag="tip",
151
+ )
152
+
153
+ if not uvicorn:
154
+ raise FastAPICLIException(
155
+ "Could not import Uvicorn, try running 'pip install uvicorn'"
156
+ ) from None
157
+
158
+ toolkit.print_line()
159
+ toolkit.print("Logs:")
160
+ toolkit.print_line()
161
+
162
+ uvicorn.run(
163
+ app=import_string,
164
+ host=host,
165
+ port=port,
166
+ reload=reload,
167
+ workers=workers,
168
+ root_path=root_path,
169
+ proxy_headers=proxy_headers,
170
+ log_config=get_uvicorn_log_config(),
86
171
  )
87
- print(Padding(panel, 1))
88
- if not uvicorn:
89
- raise FastAPICLIException(
90
- "Could not import Uvicorn, try running 'pip install uvicorn'"
91
- ) from None
92
- uvicorn.run(
93
- app=use_uvicorn_app,
94
- host=host,
95
- port=port,
96
- reload=reload,
97
- workers=workers,
98
- root_path=root_path,
99
- proxy_headers=proxy_headers,
100
- )
101
172
 
102
173
 
103
174
  @app.command()