Corin1998 commited on
Commit
96bcd77
·
verified ·
1 Parent(s): b964992

Create run.py

Browse files
Files changed (1) hide show
  1. run.py +33 -0
run.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # run.py
2
+ """
3
+ Uvicorn 起動用エントリ。
4
+ - 優先して irpr.main を読み込む
5
+ - なければ app.main をフォールバックで読み込む
6
+ """
7
+
8
+ import os
9
+ import sys
10
+ import importlib
11
+
12
+ # /code(リポジトリルート)をパスに追加
13
+ ROOT = os.path.dirname(os.path.abspath(__file__))
14
+ if ROOT not in sys.path:
15
+ sys.path.insert(0, ROOT)
16
+
17
+ last_err = None
18
+ app = None
19
+
20
+ for target in ("irpr.main", "app.main"):
21
+ try:
22
+ mod = importlib.import_module(target)
23
+ app = getattr(mod, "app")
24
+ break
25
+ except Exception as e:
26
+ last_err = e
27
+ continue
28
+
29
+ if app is None:
30
+ raise RuntimeError(
31
+ "Failed to import FastAPI app from irpr.main or app.main. "
32
+ "Make sure one of them exists and defines `app = FastAPI(...)`."
33
+ ) from last_err