Skip to content

Commit

Permalink
Merge pull request #142 from biosimulators/new-evalidate
Browse files Browse the repository at this point in the history
New evalidate
  • Loading branch information
luciansmith committed Jun 22, 2023
2 parents de844e7 + 4deb90b commit 3a512a7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion biosimulators_utils/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.180'
__version__ = '0.1.181'
10 changes: 6 additions & 4 deletions biosimulators_utils/sedml/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,12 @@ def compile_math(math):
.replace('^', '**')
)

math_node = evalidate.evalidate(math,
addnodes=VALID_MATH_EXPRESSION_NODES,
funcs=MATHEMATICAL_FUNCTIONS.keys())
compiled_math = compile(math_node, '<math>', 'eval')
model = evalidate.base_eval_model.clone()
model.nodes.extend(VALID_MATH_EXPRESSION_NODES)
model.allowed_functions.extend(MATHEMATICAL_FUNCTIONS.keys())

math_node = evalidate.Expr(math, model=model)
compiled_math = compile(math_node.node, '<math>', 'eval')
return compiled_math


Expand Down
4 changes: 2 additions & 2 deletions biosimulators_utils/sedml/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1771,8 +1771,8 @@ def validate_calculation(calculation):

try:
compiled_math = compile_math(calculation.math)
except TypeError:
errors.append(['The mathematical expression must be a `string`, not a `{}`.'.format(calculation.math.__class__)])
except TypeError as exception:
errors.append(['The mathematical expression must be a `string`, not a `{}`:'.format(calculation.math.__class__), [[str(exception)]]])
return (errors, warnings)
except (SyntaxError, CompilationException) as exception:
errors.append(['The syntax of the mathematical expression `{}` is invalid.'.format(calculation.math), [[str(exception)]]])
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
appdirs
biopython
cement
evalidate
evalidate >= 2.0.0
h5py
kisao >= 2.32
lxml
Expand Down

0 comments on commit 3a512a7

Please sign in to comment.