示例#1
0
    def arguments(self):
        "The arguments of the Job, as a dict of names to Python primitives or Workflows objects."
        if self.version != __version__:
            raise NotImplementedError(
                f"Accessing the `arguments` of a Job from a different version is not supported. "
                f"This Job {self.id!r} was created by client version {self.version!r}, "
                f"but you're currently running {__version__!r}.")

        if self._arguments is None:
            if len(self._message.arguments) == 0:
                arg_grafts = {}
            else:
                arg_grafts = {}
                kwarg_types = self.object.kwarg_types
                for name, json_graft in self._message.arguments.items():
                    try:
                        graft = json.loads(json_graft)
                    except json.JSONDecodeError as e:
                        raise ValueError(
                            f"Invalid JSON in graft for argument {name!r}: {e}. Value: {json_graft!r}."
                        )

                    obj = (kwarg_types.get(name, Any)._from_graft(
                        graft_client.isolate_keys(graft)) if
                           not (graft_syntax.is_literal(graft) or
                                graft_syntax.is_quoted_json(graft)) else graft)
                    arg_grafts[name] = obj

            self._arguments = arg_grafts

        return self._arguments
    def object(self) -> Proxytype:
        """
        Proxytype: The stored proxy object.

        Note that if this was originally constructed from a Workflows object that depended on parameters,
        then this `object` property won't hold the same object, but rather a `.Function` which takes
        those parameters and returns that object.

        Raises ValueError if not compatible with the current channel.
        """
        if self.channel != self._client._wf_channel:
            raise ValueError(
                f"This client is compatible with channel {self._client._wf_channel!r}, "
                f"but the {type(self).__name__} is only defined for channel {self.channel!r}."
            )
        if self._object is None:
            proxy_type = deserialize_typespec(self._message.typespec)
            graft = json.loads(self._message.serialized_graft)
            isolated = graft_client.isolate_keys(graft)
            proxy_obj = proxy_type._from_graft(isolated)
            # ^ NOTE: `proxy_obj` never gets params, because if `proxy_obj` is a Function
            # it doesn't need params, and if it's not, then `self.params` should be empty.
            self._object = proxy_obj

        return self._object
示例#3
0
def _proxy_object_from_message(message):
    typespec = message.typespec
    proxytype = deserialize_typespec(typespec)
    graft = json.loads(message.serialized_graft)
    isolated = graft_client.isolate_keys(graft)
    # TODO what about params? Job doesn't store them right now.
    # Anything that had params would have become a Function anyway.
    return proxytype._from_graft(isolated)
示例#4
0
    def geoctx(self):
        "The Workflows `~.geospatial.GeoContext` the Job was run within, or None"
        graft_json = self._message.geoctx_graft
        if not graft_json:
            return None

        return GeoContext._from_graft(
            graft_client.isolate_keys(json.loads(graft_json)))
示例#5
0
 def object(self):
     "Proxytype: The proxy object this Job computes."
     if self._object is None:
         typespec = json.loads(self._message.serialized_typespec)
         proxytype = deserialize_typespec(typespec)
         graft = json.loads(self._message.serialized_graft)
         isolated = graft_client.isolate_keys(graft)
         self._object = proxytype._from_graft(isolated)
     return self._object
示例#6
0
    def _from_proto(cls, message, client=None):
        typespec = json.loads(message.serialized_typespec)
        proxytype = deserialize_typespec(typespec)

        if message.serialized_graft:
            graft = json.loads(message.serialized_graft)
            isolated = graft_client.isolate_keys(graft)
            obj = proxytype._from_graft(isolated)
        else:
            obj = proxytype._from_apply("Workflow.use", workflow_id=message.id)

        return cls(obj, message, client=client)
示例#7
0
    def _from_proto(cls, message, client=None):
        typespec = json.loads(message.serialized_typespec)
        proxytype = deserialize_typespec(typespec)

        if message.serialized_graft:
            graft = json.loads(message.serialized_graft)
            isolated = graft_client.isolate_keys(graft)
            obj = proxytype._from_graft(isolated)
        else:
            raise AttributeError(
                ("The serialized graft attribute does not exist or "
                 "acces is not authorized for XYZ '{}'. To share "
                 "objects with others, please use a Workflow instead.").format(
                     message.id))

        return cls(obj, message, client=client)
示例#8
0
    def object(self):
        """
        Proxytype: The proxy object of this Workflow.

        Raises ValueError if the VersionedGraft is not compatible with the current channel.
        """
        if self.channel != _channel.__channel__:
            raise ValueError(
                "This client is compatible with channel '{}', "
                "but the VersionedGraft is only defined for channel '{}'.".
                format(_channel.__channel__, self.channel))
        if self._object is None:
            proxy_type = deserialize_typespec(self._message.typespec)
            graft = json.loads(self._message.serialized_graft)
            isolated = graft_client.isolate_keys(graft)
            proxy_obj = proxy_type._from_graft(isolated)
            self._object = proxy_obj

        return self._object
示例#9
0
    def test_func_params_generated(self, mock_gggc, func, names):
        pub = SubPublished(func)

        assert pub.object is func
        assert [p._name for p in pub.params] == names
        assert tuple(type(p) for p in pub.params) == func.all_arg_types

        # test proto set correctly by forcing reconstruction
        pub._object = None
        pub._params = None

        with graft_client.consistent_guid():
            isolated = graft_client.isolate_keys(func.graft)
        with graft_client.consistent_guid():
            pub.object

        assert pub.object.graft == isolated
        assert pub.type is type(func)

        assert [p._name for p in pub.params] == names
        assert tuple(type(p) for p in pub.params) == func.all_arg_types
示例#10
0
def _proxy_object_from_message(message):
    typespec = message.typespec
    proxytype = deserialize_typespec(typespec)
    graft = json.loads(message.serialized_graft)
    isolated = graft_client.isolate_keys(graft)
    return proxytype._from_graft(isolated)