def _addMacro(self, macro_info): macro_name = str(macro_info.name) # IPython < 1 magic commands have different API if genutils.get_ipython_version_list() < [1, 0]: def macro_fn(shell, parameter_s='', name=macro_name): door = genutils.get_door() ms = genutils.get_macro_server() params_def = ms.getMacroInfoObj(name).parameters parameters = split_macro_parameters(parameter_s, params_def) door.runMacro(macro_name, parameters, synch=True) macro = door.getLastRunningMacro() if macro is not None: # maybe none if macro was aborted return macro.getResult() else: def macro_fn(parameter_s='', name=macro_name): door = genutils.get_door() ms = genutils.get_macro_server() params_def = ms.getMacroInfoObj(name).parameters parameters = split_macro_parameters(parameter_s, params_def) door.runMacro(macro_name, parameters, synch=True) macro = door.getLastRunningMacro() if macro is not None: # maybe none if macro was aborted return macro.getResult() macro_fn.func_name = macro_name macro_fn.__doc__ = macro_info.doc + "\nWARNING: do not rely on the" \ " file path below\n" # register magic command genutils.expose_magic(macro_name, macro_fn) self._local_magic[macro_name] = macro_fn return macro_info
def _addMacro(self, macro_info): macro_name = str(macro_info.name) # IPython < 1 magic commands have different API if genutils.get_ipython_version_list() < [1, 0]: def macro_fn(shell, parameter_s='', name=macro_name): parameters = split_macro_parameters(parameter_s) door = genutils.get_door() door.runMacro(macro_name, parameters, synch=True) macro = door.getLastRunningMacro() if macro is not None: # maybe none if macro was aborted return macro.getResult() else: def macro_fn(parameter_s='', name=macro_name): parameters = split_macro_parameters(parameter_s) door = genutils.get_door() door.runMacro(macro_name, parameters, synch=True) macro = door.getLastRunningMacro() if macro is not None: # maybe none if macro was aborted return macro.getResult() macro_fn.func_name = macro_name macro_fn.__doc__ = macro_info.doc # register magic command genutils.expose_magic(macro_name, macro_fn) self._local_magic[macro_name] = macro_fn return macro_info