Skip to content

Commit 9cd2078

Browse files
committed
chore: lint (ruff) fixes
Signed-off-by: Amit Oren <amoren@redhat.com>
1 parent 2eb667f commit 9cd2078

17 files changed

Lines changed: 362 additions & 279 deletions

src/neuralnav/api/routes/configuration.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ async def deploy_model(request: DeploymentRequest):
106106
except Exception as e:
107107
logger.error(f"YAML validation failed: {e}")
108108
raise HTTPException(
109-
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Generated YAML validation failed: {str(e)}"
109+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
110+
detail=f"Generated YAML validation failed: {str(e)}",
110111
) from e
111112

112113
return DeploymentResponse(
@@ -120,7 +121,8 @@ async def deploy_model(request: DeploymentRequest):
120121
except Exception as e:
121122
logger.error(f"Failed to generate deployment: {e}", exc_info=True)
122123
raise HTTPException(
123-
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Failed to generate deployment: {str(e)}"
124+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
125+
detail=f"Failed to generate deployment: {str(e)}",
124126
) from e
125127

126128

@@ -206,7 +208,9 @@ async def get_deployment_status(deployment_id: str):
206208

207209
except Exception as e:
208210
logger.error(f"Failed to get deployment status: {e}")
209-
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Deployment not found: {deployment_id}") from e
211+
raise HTTPException(
212+
status_code=status.HTTP_404_NOT_FOUND, detail=f"Deployment not found: {deployment_id}"
213+
) from e
210214

211215

212216
@router.post("/deploy-to-cluster")
@@ -247,7 +251,8 @@ async def deploy_to_cluster(request: DeploymentRequest):
247251
except Exception as e:
248252
logger.error(f"YAML validation failed: {e}")
249253
raise HTTPException(
250-
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Generated YAML validation failed: {str(e)}"
254+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
255+
detail=f"Generated YAML validation failed: {str(e)}",
251256
) from e
252257

253258
# Step 3: Deploy to cluster
@@ -258,7 +263,8 @@ async def deploy_to_cluster(request: DeploymentRequest):
258263
if not deployment_result["success"]:
259264
logger.error(f"Deployment failed: {deployment_result['errors']}")
260265
raise HTTPException(
261-
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Deployment failed: {deployment_result['errors']}"
266+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
267+
detail=f"Deployment failed: {deployment_result['errors']}",
262268
)
263269

264270
logger.info(f"Successfully deployed {deployment_id} to cluster")
@@ -276,7 +282,10 @@ async def deploy_to_cluster(request: DeploymentRequest):
276282
raise
277283
except Exception as e:
278284
logger.error(f"Failed to deploy to cluster: {e}", exc_info=True)
279-
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Failed to deploy to cluster: {str(e)}") from e
285+
raise HTTPException(
286+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
287+
detail=f"Failed to deploy to cluster: {str(e)}",
288+
) from e
280289

281290

282291
@router.get("/cluster-status")
@@ -333,7 +342,8 @@ async def get_k8s_deployment_status(deployment_id: str):
333342
except Exception as e:
334343
logger.error(f"Failed to get K8s deployment status: {e}", exc_info=True)
335344
raise HTTPException(
336-
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Failed to get deployment status: {str(e)}"
345+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
346+
detail=f"Failed to get deployment status: {str(e)}",
337347
) from e
338348

339349

@@ -362,7 +372,8 @@ async def get_deployment_yaml(deployment_id: str):
362372

363373
if not yaml_files:
364374
raise HTTPException(
365-
status_code=status.HTTP_404_NOT_FOUND, detail=f"No YAML files found for deployment {deployment_id}"
375+
status_code=status.HTTP_404_NOT_FOUND,
376+
detail=f"No YAML files found for deployment {deployment_id}",
366377
)
367378

368379
return {"deployment_id": deployment_id, "files": yaml_files, "count": len(yaml_files)}
@@ -372,7 +383,8 @@ async def get_deployment_yaml(deployment_id: str):
372383
except Exception as e:
373384
logger.error(f"Failed to retrieve YAML files: {e}", exc_info=True)
374385
raise HTTPException(
375-
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Failed to retrieve YAML files: {str(e)}"
386+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
387+
detail=f"Failed to retrieve YAML files: {str(e)}",
376388
) from e
377389

378390

@@ -407,7 +419,10 @@ async def delete_deployment(deployment_id: str):
407419
raise
408420
except Exception as e:
409421
logger.error(f"Failed to delete deployment: {e}", exc_info=True)
410-
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Failed to delete deployment: {str(e)}") from e
422+
raise HTTPException(
423+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
424+
detail=f"Failed to delete deployment: {str(e)}",
425+
) from e
411426

412427

413428
@router.get("/deployments")
@@ -442,4 +457,7 @@ async def list_all_deployments():
442457

443458
except Exception as e:
444459
logger.error(f"Failed to list deployments: {e}", exc_info=True)
445-
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Failed to list deployments: {str(e)}") from e
460+
raise HTTPException(
461+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
462+
detail=f"Failed to list deployments: {str(e)}",
463+
) from e

src/neuralnav/api/routes/database.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ async def db_status():
4242
conn.close()
4343
except Exception as e:
4444
logger.error(f"Failed to get DB status: {e}")
45-
raise HTTPException(status_code=status.HTTP_503_SERVICE_UNAVAILABLE, detail=f"Database not accessible: {e}") from e
45+
raise HTTPException(
46+
status_code=status.HTTP_503_SERVICE_UNAVAILABLE, detail=f"Database not accessible: {e}"
47+
) from e
4648

4749

4850
@router.post("/db/upload-benchmarks")
@@ -57,13 +59,17 @@ async def upload_benchmarks(file: UploadFile = File(...)):
5759
curl -X POST -F 'file=@benchmarks.json' http://host/api/v1/db/upload-benchmarks
5860
"""
5961
if not file.filename or not file.filename.endswith(".json"):
60-
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="File must be a .json file")
62+
raise HTTPException(
63+
status_code=status.HTTP_400_BAD_REQUEST, detail="File must be a .json file"
64+
)
6165

6266
try:
6367
content = await file.read()
6468
data = json.loads(content)
6569
except json.JSONDecodeError as e:
66-
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=f"Invalid JSON: {e}") from e
70+
raise HTTPException(
71+
status_code=status.HTTP_400_BAD_REQUEST, detail=f"Invalid JSON: {e}"
72+
) from e
6773

6874
benchmarks = data.get("benchmarks", [])
6975
if not benchmarks:
@@ -90,7 +96,10 @@ async def upload_benchmarks(file: UploadFile = File(...)):
9096
conn.close()
9197
except Exception as e:
9298
logger.error(f"Failed to load benchmarks: {e}")
93-
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Failed to load benchmarks: {e}") from e
99+
raise HTTPException(
100+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
101+
detail=f"Failed to load benchmarks: {e}",
102+
) from e
94103

95104

96105
@router.post("/db/reset")
@@ -118,4 +127,7 @@ async def reset_database():
118127
conn.close()
119128
except Exception as e:
120129
logger.error(f"Failed to reset database: {e}")
121-
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Failed to reset database: {e}") from e
130+
raise HTTPException(
131+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
132+
detail=f"Failed to reset database: {e}",
133+
) from e

src/neuralnav/api/routes/recommendation.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ async def simple_recommend(request: SimpleRecommendationRequest):
143143
except Exception as e:
144144
logger.error(f"Failed to generate recommendation: {e}", exc_info=True)
145145
raise HTTPException(
146-
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Failed to generate recommendation: {str(e)}"
146+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
147+
detail=f"Failed to generate recommendation: {str(e)}",
147148
) from e
148149

149150

@@ -248,7 +249,8 @@ async def ranked_recommend_from_spec(request: RankedRecommendationFromSpecReques
248249
except Exception as e:
249250
logger.error(f"Failed to generate ranked recommendations from spec: {e}", exc_info=True)
250251
raise HTTPException(
251-
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Failed to generate ranked recommendations: {str(e)}"
252+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
253+
detail=f"Failed to generate ranked recommendations: {str(e)}",
252254
) from e
253255

254256

src/neuralnav/api/routes/reference_data.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ async def get_benchmarks():
6666

6767
if not csv_path.exists():
6868
logger.error(f"Benchmark CSV not found at: {csv_path}")
69-
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Benchmark data file not found")
69+
raise HTTPException(
70+
status_code=status.HTTP_404_NOT_FOUND, detail="Benchmark data file not found"
71+
)
7072

7173
# Read CSV using built-in csv module
7274
records = []
@@ -84,7 +86,10 @@ async def get_benchmarks():
8486
raise
8587
except Exception as e:
8688
logger.error(f"Failed to load benchmarks: {e}", exc_info=True)
87-
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Failed to load benchmarks: {str(e)}") from e
89+
raise HTTPException(
90+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
91+
detail=f"Failed to load benchmarks: {str(e)}",
92+
) from e
8893

8994

9095
@router.get("/priority-weights")
@@ -99,7 +104,10 @@ async def get_priority_weights():
99104

100105
if not json_path.exists():
101106
logger.error(f"Priority weights config not found at: {json_path}")
102-
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Priority weights configuration not found")
107+
raise HTTPException(
108+
status_code=status.HTTP_404_NOT_FOUND,
109+
detail="Priority weights configuration not found",
110+
)
103111

104112
with open(json_path) as f:
105113
data = json.load(f)
@@ -142,7 +150,8 @@ async def get_weighted_scores(use_case: str):
142150
if not csv_path.exists():
143151
logger.error(f"Weighted scores CSV not found at: {csv_path}")
144152
raise HTTPException(
145-
status_code=status.HTTP_404_NOT_FOUND, detail=f"Weighted scores file not found for use case: {use_case}"
153+
status_code=status.HTTP_404_NOT_FOUND,
154+
detail=f"Weighted scores file not found for use case: {use_case}",
146155
)
147156

148157
# Read CSV using built-in csv module
@@ -160,5 +169,6 @@ async def get_weighted_scores(use_case: str):
160169
except Exception as e:
161170
logger.error(f"Failed to load weighted scores: {e}", exc_info=True)
162171
raise HTTPException(
163-
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Failed to load weighted scores: {str(e)}"
172+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
173+
detail=f"Failed to load weighted scores: {str(e)}",
164174
) from e

src/neuralnav/api/routes/specification.py

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ def _calculate_percentile_value(min_val: int, max_val: int, percentile: float =
2424

2525
def _get_slo_workload_path() -> Path:
2626
"""Get path to the SLO workload config file."""
27-
return Path(__file__).parent.parent.parent.parent.parent / "data" / "configuration" / "usecase_slo_workload.json"
27+
return (
28+
Path(__file__).parent.parent.parent.parent.parent
29+
/ "data"
30+
/ "configuration"
31+
/ "usecase_slo_workload.json"
32+
)
2833

2934

3035
@router.get("/slo-defaults/{use_case}")
@@ -39,14 +44,18 @@ async def get_slo_defaults(use_case: str):
3944

4045
if not json_path.exists():
4146
logger.error(f"SLO workload config not found at: {json_path}")
42-
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="SLO workload configuration not found")
47+
raise HTTPException(
48+
status_code=status.HTTP_404_NOT_FOUND, detail="SLO workload configuration not found"
49+
)
4350

4451
with open(json_path) as f:
4552
data = json.load(f)
4653

4754
use_case_data = data.get("use_case_slo_workload", {}).get(use_case)
4855
if not use_case_data:
49-
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Use case '{use_case}' not found")
56+
raise HTTPException(
57+
status_code=status.HTTP_404_NOT_FOUND, detail=f"Use case '{use_case}' not found"
58+
)
5059

5160
slo_targets = use_case_data.get("slo_targets", {})
5261

@@ -81,7 +90,9 @@ async def get_slo_defaults(use_case: str):
8190
raise
8291
except KeyError as e:
8392
logger.error(f"Missing SLO data for {use_case}: {e}")
84-
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Missing SLO data: {e}") from e
93+
raise HTTPException(
94+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Missing SLO data: {e}"
95+
) from e
8596
except Exception as e:
8697
logger.error(f"Failed to get SLO defaults for {use_case}: {e}")
8798
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e)) from e
@@ -99,14 +110,18 @@ async def get_workload_profile(use_case: str):
99110

100111
if not json_path.exists():
101112
logger.error(f"SLO workload config not found at: {json_path}")
102-
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="SLO workload configuration not found")
113+
raise HTTPException(
114+
status_code=status.HTTP_404_NOT_FOUND, detail="SLO workload configuration not found"
115+
)
103116

104117
with open(json_path) as f:
105118
data = json.load(f)
106119

107120
use_case_data = data.get("use_case_slo_workload", {}).get(use_case)
108121
if not use_case_data:
109-
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Use case '{use_case}' not found")
122+
raise HTTPException(
123+
status_code=status.HTTP_404_NOT_FOUND, detail=f"Use case '{use_case}' not found"
124+
)
110125

111126
workload = use_case_data.get("workload", {})
112127

@@ -136,7 +151,9 @@ async def get_workload_profile(use_case: str):
136151
raise
137152
except KeyError as e:
138153
logger.error(f"Missing workload data for {use_case}: {e}")
139-
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Missing workload data: {e}") from e
154+
raise HTTPException(
155+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Missing workload data: {e}"
156+
) from e
140157
except Exception as e:
141158
logger.error(f"Failed to get workload profile for {use_case}: {e}")
142159
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e)) from e
@@ -157,14 +174,18 @@ async def get_expected_rps(use_case: str, user_count: int = 1000):
157174

158175
if not json_path.exists():
159176
logger.error(f"SLO workload config not found at: {json_path}")
160-
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="SLO workload configuration not found")
177+
raise HTTPException(
178+
status_code=status.HTTP_404_NOT_FOUND, detail="SLO workload configuration not found"
179+
)
161180

162181
with open(json_path) as f:
163182
data = json.load(f)
164183

165184
use_case_data = data.get("use_case_slo_workload", {}).get(use_case)
166185
if not use_case_data:
167-
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Use case '{use_case}' not found")
186+
raise HTTPException(
187+
status_code=status.HTTP_404_NOT_FOUND, detail=f"Use case '{use_case}' not found"
188+
)
168189

169190
workload = use_case_data.get("workload", {})
170191

@@ -201,7 +222,9 @@ async def get_expected_rps(use_case: str, user_count: int = 1000):
201222
raise
202223
except KeyError as e:
203224
logger.error(f"Missing workload data for {use_case}: {e}")
204-
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Missing workload data: {e}") from e
225+
raise HTTPException(
226+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Missing workload data: {e}"
227+
) from e
205228
except Exception as e:
206229
logger.error(f"Failed to calculate expected RPS for {use_case}: {e}")
207230
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e)) from e

0 commit comments

Comments
 (0)