Skip to content

Commit 62cc317

Browse files
feat(backend): add solver detection and PEP 723 metadata
1 parent ecb395e commit 62cc317

6 files changed

Lines changed: 430 additions & 0 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
!uv.lock
1515
!.python-version
1616
!run.sh
17+
!hosting_instructions.md
18+
!temoa_runner.py
19+
!frontend/wrangler.toml
20+
!.github/
1721
!.pre-commit-config.yaml
1822
!.coderabbit.yaml
1923

backend/main.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# /// script
2+
# requires-python = ">=3.12"
3+
# dependencies = [
4+
# "temoa>=4.0.0a1",
5+
# "fastapi",
6+
# "uvicorn[standard]",
7+
# "tomlkit",
8+
# "websockets",
9+
# ]
10+
# ///
11+
112
import asyncio
213
import logging
314
import sys
@@ -120,6 +131,42 @@ def list_files(path: str = "."):
120131
raise HTTPException(status_code=500, detail=str(e))
121132

122133

134+
@app.get("/api/solvers")
135+
def list_solvers():
136+
"""Detect available solvers on the local system."""
137+
try:
138+
import pyomo.environ as pyo
139+
140+
# List of solvers we want to check for
141+
common_solvers = [
142+
"appsi_highs",
143+
"highs",
144+
"cbc",
145+
"glpk",
146+
"ipopt",
147+
"gurobi",
148+
"cplex",
149+
]
150+
available = []
151+
for s in common_solvers:
152+
try:
153+
# Some solvers might throw errors even on check if not installed correctly
154+
factory = pyo.SolverFactory(s)
155+
if factory.available():
156+
available.append(s)
157+
except Exception:
158+
continue
159+
160+
# Ensure we return at least a sensible default if detection fails but temoa is present
161+
if not available:
162+
return ["appsi_highs", "cbc"]
163+
164+
return available
165+
except ImportError:
166+
# Fallback if pyomo is somehow missing
167+
return ["appsi_highs", "cbc"]
168+
169+
123170
@app.get("/api/results/{run_id}")
124171
async def get_results(run_id: str):
125172
run_dir = output_path / run_id

pyproject.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,16 @@ dependencies = [
1212
"datasette",
1313
"websockets",
1414
]
15+
16+
[tool.pytest.ini_options]
17+
pythonpath = ["."]
18+
testpaths = ["backend/tests"]
19+
filterwarnings = [
20+
"ignore:.*deprecated - use.*:pyparsing.PyparsingDeprecationWarning",
21+
]
22+
23+
[dependency-groups]
24+
dev = [
25+
"httpx>=0.28.1",
26+
"pytest>=9.0.2",
27+
]

run.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
uv sync
55
uv add "uvicorn[standard]" websockets
66

7+
# Cleanup existing processes if running
8+
echo "Cleaning up stale processes..."
9+
fuser -k 8000/tcp 2>/dev/null
10+
fuser -k 8001/tcp 2>/dev/null
11+
sleep 1
12+
713
# Start FastAPI backend in background
814
echo "Starting backend..."
915
uv run python backend/main.py &

0 commit comments

Comments
 (0)