示例#1
0
        def bound_callable(*args, **kwargs):
            # This function's signature is rewritten below using
            # `decorator.decorator`. When the signature is rewritten,
            # args[0] is the function whose signature was used to rewrite
            # this function's signature.
            args = args[1:]
            ctx = context_factory()
            # Set up a scope under which we can track destructable references
            # if something goes wrong, the __exit__ handler of this context
            # manager will clean up. (It also cleans up when things go right)
            with ctx as scope:
                provenance = self._ProvCaptureCls(self.type, self.package,
                                                  self.id)
                scope.add_reference(provenance)

                # Collate user arguments
                user_input = {
                    name: value
                    for value, name in zip(args,
                                           self.signature.signature_order)
                }
                user_input.update(kwargs)

                # Type management
                self.signature.check_types(**user_input)
                output_types = self.signature.solve_output(**user_input)
                callable_args = {}

                # Record parameters
                for name, spec in self.signature.parameters.items():
                    parameter = callable_args[name] = user_input[name]
                    provenance.add_parameter(name, spec.qiime_type, parameter)

                # Record and transform inputs
                for name, spec in self.signature.inputs.items():
                    artifact = user_input[name]
                    provenance.add_input(name, artifact)
                    if artifact is None:
                        callable_args[name] = None
                    elif spec.has_view_type():
                        recorder = provenance.transformation_recorder(name)
                        if qtype.is_collection_type(spec.qiime_type):
                            # Always put in a list. Sometimes the view isn't
                            # hashable, which isn't relevant, but would break
                            # a Set[SomeType].
                            callable_args[name] = [
                                a._view(spec.view_type, recorder)
                                for a in user_input[name]
                            ]
                        else:
                            callable_args[name] = artifact._view(
                                spec.view_type, recorder)
                    else:
                        callable_args[name] = artifact

                # Execute
                outputs = self._callable_executor_(scope, callable_args,
                                                   output_types, provenance)

                if len(outputs) != len(self.signature.outputs):
                    raise ValueError(
                        "Number of callable outputs must match number of "
                        "outputs defined in signature: %d != %d" %
                        (len(outputs), len(self.signature.outputs)))

                # Wrap in a Results object mapping output name to value so
                # users have access to outputs by name or position.
                return qiime2.sdk.Results(self.signature.outputs.keys(),
                                          outputs)
示例#2
0
 def test_set_primitive_type(self):
     self.assertTrue(is_collection_type(Set[Int % Range(5)]))
     self.assertTrue(is_primitive_type(Set[Int % Range(5)]))
     self.assertFalse(is_semantic_type(Set[Int % Range(5)]))
示例#3
0
    def test_set_semantic_type(self):
        Foo = SemanticType('Foo')

        self.assertTrue(is_collection_type(Set[Foo]))
        self.assertTrue(is_semantic_type(Set[Foo]))
        self.assertFalse(is_primitive_type(Set[Foo]))
示例#4
0
文件: action.py 项目: jakereps/qiime2
        def bound_callable(*args, **kwargs):
            # This function's signature is rewritten below using
            # `decorator.decorator`. When the signature is rewritten,
            # args[0] is the function whose signature was used to rewrite
            # this function's signature.
            args = args[1:]
            ctx = context_factory()
            # Set up a scope under which we can track destructable references
            # if something goes wrong, the __exit__ handler of this context
            # manager will clean up. (It also cleans up when things go right)
            with ctx as scope:
                provenance = self._ProvCaptureCls(
                    self.type, self.package, self.id)
                scope.add_reference(provenance)

                # Collate user arguments
                user_input = {name: value for value, name in
                              zip(args, self.signature.signature_order)}
                user_input.update(kwargs)

                # Type management
                self.signature.check_types(**user_input)
                output_types = self.signature.solve_output(**user_input)
                callable_args = {}

                # Record parameters
                for name, spec in self.signature.parameters.items():
                    parameter = callable_args[name] = user_input[name]
                    provenance.add_parameter(name, spec.qiime_type, parameter)

                # Record and transform inputs
                for name, spec in self.signature.inputs.items():
                    artifact = user_input[name]
                    provenance.add_input(name, artifact)
                    if artifact is None:
                        callable_args[name] = None
                    elif spec.has_view_type():
                        recorder = provenance.transformation_recorder(name)
                        if qtype.is_collection_type(spec.qiime_type):
                            # Always put in a list. Sometimes the view isn't
                            # hashable, which isn't relevant, but would break
                            # a Set[SomeType].
                            callable_args[name] = [
                                a._view(spec.view_type, recorder)
                                for a in user_input[name]]
                        else:
                            callable_args[name] = artifact._view(
                                spec.view_type, recorder)
                    else:
                        callable_args[name] = artifact

                # Execute
                outputs = self._callable_executor_(scope, callable_args,
                                                   output_types, provenance)

                if len(outputs) != len(self.signature.outputs):
                    raise ValueError(
                        "Number of callable outputs must match number of "
                        "outputs defined in signature: %d != %d" %
                        (len(outputs), len(self.signature.outputs)))

                # Wrap in a Results object mapping output name to value so
                # users have access to outputs by name or position.
                return qiime2.sdk.Results(self.signature.outputs.keys(),
                                          outputs)
示例#5
0
 def test_set_primitive_type(self):
     self.assertTrue(is_collection_type(Set[Int % Range(5)]))
     self.assertTrue(is_primitive_type(Set[Int % Range(5)]))
     self.assertFalse(is_semantic_type(Set[Int % Range(5)]))
示例#6
0
    def test_set_semantic_type(self):
        Foo = SemanticType('Foo')

        self.assertTrue(is_collection_type(Set[Foo]))
        self.assertTrue(is_semantic_type(Set[Foo]))
        self.assertFalse(is_primitive_type(Set[Foo]))