feat: 改为安装包分发并使用动态端口
This commit is contained in:
+11
-1
@@ -45,6 +45,16 @@ async def health() -> dict:
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import os
|
||||
import socket
|
||||
|
||||
import uvicorn
|
||||
|
||||
uvicorn.run("app.main:app", host="127.0.0.1", port=8765)
|
||||
chosen = os.environ.get("NQI_PORT")
|
||||
if chosen:
|
||||
port = int(chosen)
|
||||
else:
|
||||
with socket.socket() as sock:
|
||||
sock.bind(("127.0.0.1", 0))
|
||||
port = sock.getsockname()[1]
|
||||
uvicorn.run("app.main:app", host="127.0.0.1", port=port)
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[3]
|
||||
DATA_ROOT = REPO_ROOT / "data"
|
||||
|
||||
def _data_root() -> Path:
|
||||
override = os.environ.get("NQI_DATA_DIR")
|
||||
if override:
|
||||
return Path(override)
|
||||
return Path(__file__).resolve().parents[3] / "data"
|
||||
|
||||
|
||||
DATA_ROOT = _data_root()
|
||||
DOWNLOAD_DIR = DATA_ROOT / "jobs"
|
||||
|
||||
Reference in New Issue
Block a user