From c488fc0260ac412a6d9df157338ac8c35d43ec52 Mon Sep 17 00:00:00 2001 From: Arthur Goldberg Date: Fri, 6 Oct 2017 22:43:09 -0400 Subject: [PATCH] rename __wrap_libsbml() parameters to avoid namespace collision; don't expect this to help circleCI run however --- wc_lang/core.py | 2 +- wc_lang/sbml/util.py | 38 +++++++++++++++++++------------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/wc_lang/core.py b/wc_lang/core.py index 897e978..aa3eccd 100644 --- a/wc_lang/core.py +++ b/wc_lang/core.py @@ -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: diff --git a/wc_lang/sbml/util.py b/wc_lang/sbml/util.py index cebbd53..9e247fb 100644 --- a/wc_lang/sbml/util.py +++ b/wc_lang/sbml/util.py @@ -148,7 +148,7 @@ 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, @@ -156,52 +156,52 @@ def __wrap_libsbml(call, globals, locals, returns_int=False, debug=False): 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