def target_signature(self, mode='any'): # we are supposed to get signature of the library, but we cannot return textMD5(repr(self._library))
def execute_scratch_cell(code, raw_args, kernel): # we then have to change the parse to disable args.workflow when # there is no workflow option. raw_args = shlex.split(raw_args) if isinstance(raw_args, str) else raw_args if code is None or '-h' in raw_args: parser = get_run_parser(interactive=True, with_workflow=True) parser.print_help() return if raw_args and raw_args[0].lstrip().startswith('-'): parser = get_run_parser(interactive=True, with_workflow=False) parser.error = _parse_error args, workflow_args = parser.parse_known_args(raw_args) args.workflow = None else: parser = get_run_parser(interactive=True, with_workflow=True) parser.error = _parse_error args, workflow_args = parser.parse_known_args(raw_args) if not code.strip(): return # for reporting purpose sys.argv = ['%run'] + raw_args env.verbosity = args.verbosity if not any( isinstance(x, NotebookLoggingHandler) for x in env.logger.handlers): env.logger.handlers = [ x for x in env.logger.handlers if type(x) is not logging.StreamHandler ] levels = { 0: logging.ERROR, 1: logging.WARNING, 2: logging.INFO, 3: logging.DEBUG, 4: logging.DEBUG, None: logging.INFO } env.logger.addHandler( NotebookLoggingHandler(levels[env.verbosity], kernel, title=' '.join(sys.argv))) else: env.logger.handers[0].setTitle(' '.join(sys.argv)) global last_cell_id # we retain step_input etc only when we step through a cell #256 if kernel and kernel.cell_id != last_cell_id: # clear __step_input__, __step_output__ etc because there is # no concept of passing input/outputs across cells. env.sos_dict.set('__step_output__', sos_targets([])) for k in [ '__step_input__', '__default_output__', 'step_input', 'step_output', 'step_depends', '_input', '_output', '_depends' ]: env.sos_dict.pop(k, None) last_cell_id = kernel.cell_id config = { 'config_file': args.__config__, 'default_queue': args.__queue__, 'run_mode': 'dryrun' if args.dryrun else 'interactive', # issue 230, ignore sig mode in interactive mode 'sig_mode': 'ignore', 'verbosity': args.verbosity, # for backward compatibility, we try both args.__worker_procs__ and args.__max_procs__ 'worker_procs': args.__worker_procs__ if hasattr(args, '__worker_procs__') else args.__max_procs__, 'max_running_jobs': args.__max_running_jobs__, # for infomration and resume only 'workdir': os.getcwd(), 'workflow': args.workflow, 'targets': args.__targets__, 'workflow_args': workflow_args, 'workflow_id': textMD5(code), # interactive work is also a slave of the controller 'slave_id': kernel.cell_id, } env.sos_dict.set('workflow_id', config['workflow_id']) env.config.update(config) try: if not any([ SOS_SECTION_HEADER.match(line) or line.startswith('%from') or line.startswith('%include') for line in code.splitlines() ]): code = f'[cell_{str(kernel.cell_id)[:8] if kernel and kernel.cell_id else "0"}]\n' + code script = SoS_Script(content=code) else: return workflow = script.workflow(args.workflow) section = workflow.sections[0] res = analyze_section(section) env.sos_dict.quick_update({ '__signature_vars__': res['signature_vars'], '__environ_vars__': res['environ_vars'], '__changed_vars__': res['changed_vars'] }) executor = Interactive_Step_Executor(section, mode='interactive') ret = executor.run() try: return ret['__last_res__'] except Exception as e: raise RuntimeError( f'Unknown result returned from executor {ret}: {e}') except (UnknownTarget, RemovedTarget) as e: raise RuntimeError(f'Unavailable target {e.target}') except TerminateExecution as e: return except SystemExit: # this happens because the executor is in resume mode but nothing # needs to be resumed, we simply pass return except Exception: env.log_to_file('PROCESS', get_traceback()) raise
def target_signature(self, mode='any'): # we are supposed to get signature of the module, but we cannot return textMD5('Python module ' + self._module)