Skip to content

Commit

Permalink
rename __wrap_libsbml() parameters to avoid namespace collision; don'…
Browse files Browse the repository at this point in the history
…t expect this to help circleCI run however
  • Loading branch information
artgoldberg committed Oct 7, 2017
1 parent 0e5645e commit c488fc0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion wc_lang/core.py
Expand Up @@ -706,7 +706,7 @@ def add_to_sbml_doc(self, sbml_document):
:obj:`LibSBMLError`: if calling `libsbml` raises an error
"""
sbml_model = wrap_libsbml("sbml_document.getModel()")
wrap_libsbml("sbml_model.setIdAttribute({})".format(self.id))
wrap_libsbml("sbml_model.setIdAttribute('{}')".format(self.id))
wrap_libsbml("sbml_model.setName(self.name)")
# compartment, objective_function, and parameters are created separately
if self.comments:
Expand Down
38 changes: 19 additions & 19 deletions wc_lang/sbml/util.py
Expand Up @@ -148,60 +148,60 @@ def _create_sbml_parameter(sbml_model, id, name=None, value=None, units=None, co
create_sbml_unit = LibsbmlInterface._create_sbml_unit
create_sbml_parameter = LibsbmlInterface._create_sbml_parameter

def __wrap_libsbml(call, globals, locals, returns_int=False, debug=False):
def __wrap_libsbml(_call, _globals, _locals, _returns_int=False, _debug=False):
""" Wrap a libsbml method and properly handle errors.
Unfortunately, libsbml methods that do not return data usually handle errors via return codes,
instead of exceptions, and the generic return codes contain virtually no information.
This function wraps these methods and raises useful exceptions when errors occur.
Args:
call (:obj:`str`): a libsbml expression to execute
globals (:obj:`namespace`): the global namespace
locals (:obj:`namespace`): the local namespace at the calling code
returns_int (:obj:`bool`, optional): whether the method returns an int
debug (:obj:`bool`, optional): whether to print debug output
_call (:obj:`str`): a libsbml expression to execute
_globals (:obj:`namespace`): the global namespace
_locals (:obj:`namespace`): the local namespace at the calling code
_returns_int (:obj:`bool`, optional): whether the method returns an int
_debug (:obj:`bool`, optional): whether to print debug output
Returns:
:obj:`obj` or `int`: return the value returned by the libsbml method, either
an object that has been created or retrieved, or an integer return code
Raises:
:obj:`LibSBMLError`: if `call` contains an error, or the libsbml call returns None,
:obj:`LibSBMLError`: if `_call` contains an error, or the libsbml call returns None,
or the libsbml call return a code != LIBSBML_OPERATION_SUCCESS
"""
if debug:
print('libsbml call:', call)
if _debug:
print('libsbml call:', _call)
try:
rc = eval(call, globals, locals)
rc = eval(_call, _globals, _locals)
except SyntaxError as error:
raise LibSBMLError("Syntax error in libsbml method call '{}'.".format(call))
raise LibSBMLError("Syntax error in libsbml method call '{}'.".format(_call))
except NameError as error:
raise LibSBMLError("NameError '{}' in libsbml method call '{}'.".format(error, call))
raise LibSBMLError("NameError '{}' in libsbml method call '{}'.".format(error, _call))
except Exception as error:
raise LibSBMLError("Error '{}' in libsbml method call '{}'.".format(error, call))
raise LibSBMLError("Error '{}' in libsbml method call '{}'.".format(error, _call))
if rc == None:
raise LibSBMLError("libsbml returned None when executing '{}'.".format(call))
raise LibSBMLError("libsbml returned None when executing '{}'.".format(_call))
elif type(rc) is int:
if rc == LIBSBML_OPERATION_SUCCESS:
if debug:
if _debug:
print('libsbml returns: LIBSBML_OPERATION_SUCCESS')
return rc
else:
error_code = OperationReturnValue_toString(rc)
# Handle libsbml methods that return int as values
# TODO: handle this more gracefully
if error_code is None or returns_int:
if debug:
if error_code is None or _returns_int:
if _debug:
print("libsbml returns:", rc)
return rc
else:
raise LibSBMLError("LibSBML returned error code '{}' "
"when executing '{}'.\nWARNING: if the libsbml call above returns an int, then this "
"error may be incorrect; pass 'returns_int=True' to wrap_libsbml().".format(error_code, call))
"error may be incorrect; pass 'returns_int=True' to wrap_libsbml().".format(error_code, _call))
else:
# return data provided by libsbml method
if debug:
if _debug:
print('libsbml returns:', rc)
return rc

Expand Down

0 comments on commit c488fc0

Please sign in to comment.