Spaces:
Running
Running
Commit ·
2b2ebe7
1
Parent(s): c43ae5c
Restore server folder and requirements.txt per user request
Browse files- server/__init__.py +6 -0
- server/app.py +49 -0
server/__init__.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Server package exposing ASGI app for `uvicorn server:app`."""
|
| 2 |
+
|
| 3 |
+
from server.app import app, main
|
| 4 |
+
|
| 5 |
+
__all__ = ["app", "main"]
|
| 6 |
+
|
server/app.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""ASGI app entrypoint expected by openenv validate."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import importlib.util
|
| 6 |
+
import os
|
| 7 |
+
import sys
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
from typing import NoReturn
|
| 10 |
+
|
| 11 |
+
import uvicorn
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def _load_impl_app() -> object:
|
| 15 |
+
"""Load FastAPI app from code-review-env/server.py."""
|
| 16 |
+
|
| 17 |
+
repo_root = Path(__file__).resolve().parents[1]
|
| 18 |
+
impl_root = repo_root / "code-review-env"
|
| 19 |
+
impl_server = impl_root / "server.py"
|
| 20 |
+
if not impl_server.exists():
|
| 21 |
+
raise RuntimeError("Implementation server not found at code-review-env/server.py")
|
| 22 |
+
if str(impl_root) not in sys.path:
|
| 23 |
+
sys.path.insert(0, str(impl_root))
|
| 24 |
+
spec = importlib.util.spec_from_file_location("code_review_env_impl_server", impl_server)
|
| 25 |
+
if spec is None or spec.loader is None:
|
| 26 |
+
raise RuntimeError("Failed to create module spec for implementation server")
|
| 27 |
+
module = importlib.util.module_from_spec(spec)
|
| 28 |
+
sys.modules["code_review_env_impl_server"] = module
|
| 29 |
+
spec.loader.exec_module(module)
|
| 30 |
+
if not hasattr(module, "app"):
|
| 31 |
+
raise RuntimeError("Implementation server module does not define app")
|
| 32 |
+
return getattr(module, "app")
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
app = _load_impl_app()
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def main() -> NoReturn:
|
| 39 |
+
"""Run the ASGI app with uvicorn on port 7860."""
|
| 40 |
+
|
| 41 |
+
host = os.getenv("HOST", "0.0.0.0")
|
| 42 |
+
port = int(os.getenv("PORT", "7860"))
|
| 43 |
+
uvicorn.run("server:app", host=host, port=port)
|
| 44 |
+
raise SystemExit(0)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
if __name__ == "__main__":
|
| 48 |
+
main()
|
| 49 |
+
|