File size: 795 Bytes
96bcd77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# run.py
"""
Uvicorn 起動用エントリ。
- 優先して irpr.main を読み込む
- なければ app.main をフォールバックで読み込む
"""

import os
import sys
import importlib

# /code(リポジトリルート)をパスに追加
ROOT = os.path.dirname(os.path.abspath(__file__))
if ROOT not in sys.path:
    sys.path.insert(0, ROOT)

last_err = None
app = None

for target in ("irpr.main", "app.main"):
    try:
        mod = importlib.import_module(target)
        app = getattr(mod, "app")
        break
    except Exception as e:
        last_err = e
        continue

if app is None:
    raise RuntimeError(
        "Failed to import FastAPI app from irpr.main or app.main. "
        "Make sure one of them exists and defines `app = FastAPI(...)`."
    ) from last_err