def check_port_spec(module, port_name, port_type, descriptor=None, sigstring=None): basic_pkg = get_vistrails_basic_pkg_id() reg = get_module_registry() found = False try: if descriptor is not None: s = reg.get_port_spec_from_descriptor(descriptor, port_name, port_type) found = True spec_tuples = parse_port_spec_string(sigstring, basic_pkg) for i in xrange(len(spec_tuples)): spec_tuple = spec_tuples[i] port_pkg = reg.get_package_by_name(spec_tuple[0]) if port_pkg.identifier != spec_tuple[0]: # we have an old identifier spec_tuples[i] = (port_pkg.identifier,) + spec_tuple[1:] sigstring = create_port_spec_string(spec_tuples) # sigstring = expand_port_spec_string(sigstring, basic_pkg) if s.sigstring != sigstring: msg = ('%s port "%s" of module "%s" exists, but ' 'signatures differ "%s" != "%s"') % \ (port_type.capitalize(), port_name, module.name, s.sigstring, sigstring) raise UpgradeWorkflowError(msg, module, port_name, port_type) except MissingPort: pass if not found and \ not module.has_portSpec_with_name((port_name, port_type)): msg = '%s port "%s" of module "%s" does not exist.' % \ (port_type.capitalize(), port_name, module.name) raise UpgradeWorkflowError(msg, module, port_name, port_type)
def get_items_from_sigstring(self, sigstring, *attrs): ps_items = [] specs_list = parse_port_spec_string(sigstring) if len(specs_list) == 0: return ps_items self._resize_attrs(specs_list, *attrs) for i, item_tuple in enumerate(izip(specs_list, *attrs)): kwargs = self._set_attrs(None, *item_tuple[1:]) ps_item = PortSpecItem(pos=i, package=item_tuple[0][0], module=item_tuple[0][1], namespace=item_tuple[0][2], **kwargs) ps_items.append(ps_item) return ps_items
def execute(self, *args, **kwargs): """Execute the pipeline. Positional arguments are either input values (created from ``module == value``, where `module` is a Module from the pipeline and `value` is some value or Function instance) for the pipeline's InputPorts, or Module instances (to select sink modules). Keyword arguments are also used to set InputPort by looking up inputs by name. Example:: input_bound = pipeline.get_input('higher_bound') input_url = pipeline.get_input('url') sinkmodule = pipeline.get_module(32) pipeline.execute(sinkmodule, input_bound == vt.Function(Integer, 10), input_url == 'http://www.vistrails.org/', resolution=15) # kwarg: only one equal sign """ sinks = set() inputs = {} reg = get_module_registry() InputPort_desc = reg.get_descriptor_by_name( get_vistrails_basic_pkg_id(), 'InputPort') # Read args for arg in args: if isinstance(arg, ModuleValuePair): if arg.module.id in inputs: raise ValueError("Multiple values set for InputPort %r" % get_inputoutput_name(arg.module)) if not reg.is_descriptor_subclass(arg.module.module_descriptor, InputPort_desc): raise ValueError("Module %d is not an InputPort" % arg.module.id) inputs[arg.module.id] = arg.value elif isinstance(arg, Module): sinks.add(arg.module_id) # Read kwargs for key, value in kwargs.iteritems(): key = self.get_input(key) # Might raise KeyError if key.module_id in inputs: raise ValueError("Multiple values set for InputPort %r" % get_inputoutput_name(key.module)) inputs[key.module_id] = value reason = "API pipeline execution" sinks = sinks or None # Use controller only if no inputs were passed in if (not inputs and self.vistrail is not None and self.vistrail.current_version == self.version): controller = self.vistrail.controller results, changed = controller.execute_workflow_list([[ controller.locator, # locator self.version, # version self.pipeline, # pipeline DummyView(), # view None, # custom_aliases None, # custom_params reason, # reason sinks, # sinks None, # extra_info ]]) result, = results else: pipeline = self.pipeline if inputs: id_scope = IdScope(1) pipeline = pipeline.do_copy(False, id_scope) # A hach to get ids from id_scope that we know won't collide: # make them negative id_scope.getNewId = lambda t, g=id_scope.getNewId: -g(t) create_module = \ VistrailController.create_module_from_descriptor_static create_function = VistrailController.create_function_static create_connection = VistrailController.create_connection_static # Fills in the ExternalPipe ports for module_id, values in inputs.iteritems(): module = pipeline.modules[module_id] if not isinstance(values, (list, tuple)): values = [values] # Guess the type of the InputPort _, sigstrings, _, _, _ = get_port_spec_info( pipeline, module) sigstrings = parse_port_spec_string(sigstrings) # Convert whatever we got to a list of strings, for the # pipeline values = [ reg.convert_port_val(val, sigstring, None) for val, sigstring in izip(values, sigstrings) ] if len(values) == 1: # Create the constant module constant_desc = reg.get_descriptor_by_name( *sigstrings[0]) constant_mod = create_module(id_scope, constant_desc) func = create_function(id_scope, constant_mod, 'value', values) constant_mod.add_function(func) pipeline.add_module(constant_mod) # Connect it to the ExternalPipe port conn = create_connection(id_scope, constant_mod, 'value', module, 'ExternalPipe') pipeline.db_add_connection(conn) else: raise RuntimeError("TODO : create tuple") interpreter = get_default_interpreter() result = interpreter.execute(pipeline, reason=reason, sinks=sinks) if result.errors: raise ExecutionErrors(self, result) else: return ExecutionResults(self, result)
def execute(self, *args, **kwargs): """Execute the pipeline. Positional arguments are either input values (created from ``module == value``, where `module` is a Module from the pipeline and `value` is some value or Function instance) for the pipeline's InputPorts, or Module instances (to select sink modules). Keyword arguments are also used to set InputPort by looking up inputs by name. Example:: input_bound = pipeline.get_input('higher_bound') input_url = pipeline.get_input('url') sinkmodule = pipeline.get_module(32) pipeline.execute(sinkmodule, input_bound == vt.Function(Integer, 10), input_url == 'http://www.vistrails.org/', resolution=15) # kwarg: only one equal sign """ sinks = set() inputs = {} reg = get_module_registry() InputPort_desc = reg.get_descriptor_by_name( get_vistrails_basic_pkg_id(), 'InputPort') # Read args for arg in args: if isinstance(arg, ModuleValuePair): if arg.module.id in inputs: raise ValueError( "Multiple values set for InputPort %r" % get_inputoutput_name(arg.module)) if not reg.is_descriptor_subclass(arg.module.module_descriptor, InputPort_desc): raise ValueError("Module %d is not an InputPort" % arg.module.id) inputs[arg.module.id] = arg.value elif isinstance(arg, Module): sinks.add(arg.module_id) # Read kwargs for key, value in kwargs.iteritems(): key = self.get_input(key) # Might raise KeyError if key.module_id in inputs: raise ValueError("Multiple values set for InputPort %r" % get_inputoutput_name(key.module)) inputs[key.module_id] = value reason = "API pipeline execution" sinks = sinks or None # Use controller only if no inputs were passed in if (not inputs and self.vistrail is not None and self.vistrail.current_version == self.version): controller = self.vistrail.controller results, changed = controller.execute_workflow_list([[ controller.locator, # locator self.version, # version self.pipeline, # pipeline DummyView(), # view None, # custom_aliases None, # custom_params reason, # reason sinks, # sinks None, # extra_info ]]) result, = results else: pipeline = self.pipeline if inputs: id_scope = IdScope(1) pipeline = pipeline.do_copy(False, id_scope) # A hach to get ids from id_scope that we know won't collide: # make them negative id_scope.getNewId = lambda t, g=id_scope.getNewId: -g(t) create_module = \ VistrailController.create_module_from_descriptor_static create_function = VistrailController.create_function_static create_connection = VistrailController.create_connection_static # Fills in the ExternalPipe ports for module_id, values in inputs.iteritems(): module = pipeline.modules[module_id] if not isinstance(values, (list, tuple)): values = [values] # Guess the type of the InputPort _, sigstrings, _, _, _ = get_port_spec_info(pipeline, module) sigstrings = parse_port_spec_string(sigstrings) # Convert whatever we got to a list of strings, for the # pipeline values = [reg.convert_port_val(val, sigstring, None) for val, sigstring in izip(values, sigstrings)] if len(values) == 1: # Create the constant module constant_desc = reg.get_descriptor_by_name( *sigstrings[0]) constant_mod = create_module(id_scope, constant_desc) func = create_function(id_scope, constant_mod, 'value', values) constant_mod.add_function(func) pipeline.add_module(constant_mod) # Connect it to the ExternalPipe port conn = create_connection(id_scope, constant_mod, 'value', module, 'ExternalPipe') pipeline.db_add_connection(conn) else: raise RuntimeError("TODO : create tuple") interpreter = get_default_interpreter() result = interpreter.execute(pipeline, reason=reason, sinks=sinks) if result.errors: raise ExecutionErrors(self, result) else: return ExecutionResults(self, result)