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.
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/PKG-INFO +44 -56
- fastapi_cli-0.0.6/README.md +94 -0
- fastapi_cli-0.0.6/pdm_build.py +20 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/pyproject.toml +14 -11
- fastapi_cli-0.0.6/requirements-github-actions.txt +1 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/requirements-tests.txt +2 -2
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/requirements.txt +1 -1
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/scripts/format.sh +1 -1
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/scripts/test-cov-html.sh +1 -1
- fastapi_cli-0.0.6/src/fastapi_cli/__init__.py +1 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/src/fastapi_cli/cli.py +114 -43
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/src/fastapi_cli/discover.py +38 -77
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/src/fastapi_cli/logging.py +4 -2
- fastapi_cli-0.0.6/src/fastapi_cli/utils/cli.py +75 -0
- fastapi_cli-0.0.6/tests/assets/nested_package/__init__.py +0 -0
- fastapi_cli-0.0.6/tests/assets/nested_package/package/core/__init__.py +0 -0
- fastapi_cli-0.0.6/tests/assets/package/__init__.py +2 -0
- fastapi_cli-0.0.6/tests/assets/package/core/__init__.py +0 -0
- fastapi_cli-0.0.6/tests/assets/package/core/utils.py +2 -0
- fastapi_cli-0.0.6/tests/assets/package/mod/__init__.py +1 -0
- fastapi_cli-0.0.6/tests/assets/package/mod/api.py +24 -0
- fastapi_cli-0.0.6/tests/assets/package/mod/app.py +32 -0
- fastapi_cli-0.0.6/tests/assets/package/mod/other.py +16 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/test_cli.py +64 -24
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/test_requirements.py +2 -2
- fastapi_cli-0.0.6/tests/test_utils_cli.py +35 -0
- fastapi_cli-0.0.6/tests/test_utils_default_dir.py +52 -0
- fastapi_cli-0.0.6/tests/test_utils_default_file.py +73 -0
- fastapi_cli-0.0.6/tests/test_utils_package.py +197 -0
- fastapi_cli-0.0.6/tests/test_utils_single_file.py +59 -0
- fastapi_cli-0.0.4/README.md +0 -107
- fastapi_cli-0.0.4/pdm_build.py +0 -39
- fastapi_cli-0.0.4/src/fastapi_cli/__init__.py +0 -1
- fastapi_cli-0.0.4/tests/test_utils_default_dir.py +0 -88
- fastapi_cli-0.0.4/tests/test_utils_default_file.py +0 -103
- fastapi_cli-0.0.4/tests/test_utils_package.py +0 -455
- fastapi_cli-0.0.4/tests/test_utils_single_file.py +0 -115
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/LICENSE +0 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/scripts/lint.sh +0 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/scripts/test.sh +0 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/src/fastapi_cli/__main__.py +0 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/src/fastapi_cli/exceptions.py +0 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/src/fastapi_cli/py.typed +0 -0
- {fastapi_cli-0.0.4/tests → fastapi_cli-0.0.6/src/fastapi_cli/utils}/__init__.py +0 -0
- {fastapi_cli-0.0.4/tests/assets/default_files/default_app_dir_api/app → fastapi_cli-0.0.6/tests}/__init__.py +0 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/broken_package/mod/__init__.py +0 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/broken_package/mod/app.py +0 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/broken_package/utils.py +0 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_api/api.py +0 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_app/api.py +0 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_app/app.py +0 -0
- {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
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_app_dir_api/app/api.py +0 -0
- {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
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_app_dir_app/app/api.py +0 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_app_dir_app/app/app.py +0 -0
- {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
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_app_dir_main/app/api.py +0 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_app_dir_main/app/app.py +0 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_app_dir_main/app/main.py +0 -0
- {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
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_app_dir_non_default/app/nondefault.py +0 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_main/api.py +0 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_main/app.py +0 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/default_main/main.py +0 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/default_files/non_default/nonstandard.py +0 -0
- {fastapi_cli-0.0.4/tests/assets → fastapi_cli-0.0.6/tests/assets/nested_package}/package/__init__.py +0 -0
- {fastapi_cli-0.0.4/tests/assets → fastapi_cli-0.0.6/tests/assets/nested_package}/package/core/utils.py +0 -0
- {fastapi_cli-0.0.4/tests/assets → fastapi_cli-0.0.6/tests/assets/nested_package}/package/mod/__init__.py +0 -0
- {fastapi_cli-0.0.4/tests/assets → fastapi_cli-0.0.6/tests/assets/nested_package}/package/mod/api.py +0 -0
- {fastapi_cli-0.0.4/tests/assets → fastapi_cli-0.0.6/tests/assets/nested_package}/package/mod/app.py +0 -0
- {fastapi_cli-0.0.4/tests/assets → fastapi_cli-0.0.6/tests/assets/nested_package}/package/mod/other.py +0 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/single_file_api.py +0 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/single_file_app.py +0 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/assets/single_file_other.py +0 -0
- {fastapi_cli-0.0.4 → fastapi_cli-0.0.6}/tests/conftest.py +0 -0
- {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.
|
|
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:
|
|
31
|
-
Project-URL:
|
|
32
|
-
Project-URL: Repository, https://github.com/
|
|
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:
|
|
36
|
-
Requires-Dist:
|
|
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/
|
|
43
|
-
<img src="https://github.com/
|
|
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/
|
|
46
|
-
<img src="https://github.com/
|
|
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/
|
|
49
|
-
<img src="https://coverage-badge.samuelcolvin.workers.dev/
|
|
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/
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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.
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
Repository = "https://github.com/
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.0.6"
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
|
|
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.
|
|
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
|
|
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
|
-
|
|
20
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
f"
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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()
|