-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
50 lines (38 loc) · 1.33 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
This file allows you to run the app programmatically,
and also enables debugging if this file is run as the main
"""
import sys
from pathlib import Path
import uvicorn
from SBDY_app import options
from SBDY_app.app import app # for uvicorn.run
from SBDY_app.logger import CONFIG, LOGFILE, UVICORN_CONFIG
DEBUGGING = "debugpy" in sys.modules
def run(host: str = "localhost") -> None:
config = UVICORN_CONFIG
if not options.DEV_MODE:
config = CONFIG
LOGFILE.open(mode="a", encoding="utf-8").write("\n")
file = Path(__file__)
uvicorn.run(
f"{file.stem}:app",
app_dir=str(file.parent.absolute()),
host=host,
port=80,
reload=options.RELOAD,
log_level="info",
log_config=config,
use_colors=options.DEV_MODE,
)
if __name__ in ("__mp_main__", "__main__"):
options.DEV_MODE = True
# if this file is launched directly, this is a sign that it is a dev,
# therefore, if we are not debugging, which requires RELOAD == False,
# we set the RELOAD to True to simplify the development
if not DEBUGGING:
options.RELOAD = True
if __name__ == "__main__":
run()
# run without reloading but with stdout log
# py -3.10 -c "from SBDY_app import run, options;options.RELOAD = False;options.DEV_MODE = True;run('0.0.0.0')" # noqa: E501