Skip to content

Commit ed9e701

Browse files
Merge pull request #160 from festim-dev/fix-flask
Removed flask in pathview package
2 parents 4f7fbd2 + 57639ae commit ed9e701

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

src/python/pathsim_utils.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
FestimWall,
5555
Integrator,
5656
)
57-
from flask import jsonify
5857
import inspect
5958

6059
NAME_TO_SOLVER = {
@@ -275,32 +274,25 @@ def make_solver_params(solver_prms, eval_namespace=None):
275274

276275
for k, v in solver_prms.items():
277276
if k not in ["Solver", "log"]:
278-
try:
279-
if v == "":
280-
# TODO get the default from pathsim._constants
281-
solver_prms[k] = None
282-
else:
283-
solver_prms[k] = eval(v, eval_namespace)
284-
except Exception as e:
285-
return jsonify(
286-
{"error": f"Invalid value for {k}: {v}. Error: {str(e)}"}
287-
), 400
277+
if v == "":
278+
# TODO get the default from pathsim._constants
279+
solver_prms[k] = None
280+
else:
281+
solver_prms[k] = eval(v, eval_namespace)
288282
elif k == "log":
289283
if v == "true":
290284
solver_prms[k] = True
291285
elif v == "false":
292286
solver_prms[k] = False
293287
else:
294-
return jsonify(
295-
{"error": f"Invalid value for {k}: {v}. Must be 'true' or 'false'."}
296-
), 400
288+
raise ValueError(
289+
f"Invalid value for {k}: {v}. Must be 'true' or 'false'."
290+
)
297291
elif k == "Solver":
298292
if v not in NAME_TO_SOLVER:
299-
return jsonify(
300-
{
301-
"error": f"Invalid solver: {v}. Must be one of {list(NAME_TO_SOLVER.keys())}."
302-
}
303-
), 400
293+
raise ValueError(
294+
f"Invalid solver: {v}. Must be one of {list(NAME_TO_SOLVER.keys())}."
295+
)
304296
solver_prms[k] = NAME_TO_SOLVER[v]
305297

306298
# remove solver duration from solver parameters
@@ -777,7 +769,7 @@ def make_pathsim_model(graph_data: dict) -> tuple[Simulation, float]:
777769
try:
778770
exec(python_code, eval_namespace)
779771
except Exception as e:
780-
return jsonify({"error": f"Error executing Python code: {str(e)}"}), 400
772+
raise ValueError(f"Error executing custom Python code: {str(e)}")
781773

782774
solver_prms, extra_params, duration = make_solver_params(
783775
solver_prms, eval_namespace

0 commit comments

Comments
 (0)