diff --git a/src/isolate/backends/remote.py b/src/isolate/backends/remote.py index c522198..3105a5a 100644 --- a/src/isolate/backends/remote.py +++ b/src/isolate/backends/remote.py @@ -52,17 +52,20 @@ def create(self) -> List[EnvironmentDefinition]: for env in self.target_environments: if not env.get("kind") or not env.get("configuration"): raise RuntimeError(f"`kind` or `configuration` key missing in: {env}") - envs.append(EnvironmentDefinition( - kind=env["kind"], - configuration=interface.to_struct(env["configuration"]))) + envs.append( + EnvironmentDefinition( + kind=env["kind"], + configuration=interface.to_struct(env["configuration"]), + ) + ) return envs def exists(self) -> bool: return False def open_connection( - self, - connection_key: List[EnvironmentDefinition], + self, + connection_key: List[EnvironmentDefinition], ) -> IsolateServerConnection: return IsolateServerConnection(self, self.host, connection_key) @@ -100,7 +103,7 @@ def run( method=self.environment.settings.serialization_method, was_it_raised=False, ), - environments=self.definitions + environments=self.definitions, ) return_value = [] diff --git a/src/isolate/interface.py b/src/isolate/interface.py index 51aefeb..2a48b49 100644 --- a/src/isolate/interface.py +++ b/src/isolate/interface.py @@ -191,10 +191,7 @@ def wrap( # TODO: We should think of a way to set multiple environment definitions - target_list = [{ - "kind": kind, - "configuration": definition - }] + target_list = [{"kind": kind, "configuration": definition}] # Create a remote environment. return BoxedEnvironment( diff --git a/src/isolate/server/definitions/server_pb2.py b/src/isolate/server/definitions/server_pb2.py index 0d8522f..5b38a75 100644 --- a/src/isolate/server/definitions/server_pb2.py +++ b/src/isolate/server/definitions/server_pb2.py @@ -2,30 +2,33 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # source: server.proto """Generated protocol buffer code.""" -from google.protobuf.internal import builder as _builder from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder + # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() -from isolate.connections.grpc.definitions import common_pb2 as common__pb2 from google.protobuf import struct_pb2 as google_dot_protobuf_dot_struct__pb2 +from isolate.connections.grpc.definitions import common_pb2 as common__pb2 -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0cserver.proto\x1a\x0c\x63ommon.proto\x1a\x1cgoogle/protobuf/struct.proto\"b\n\rBoundFunction\x12,\n\x0c\x65nvironments\x18\x01 \x03(\x0b\x32\x16.EnvironmentDefinition\x12#\n\x08\x66unction\x18\x02 \x01(\x0b\x32\x11.SerializedObject\"U\n\x15\x45nvironmentDefinition\x12\x0c\n\x04kind\x18\x01 \x01(\t\x12.\n\rconfiguration\x18\x02 \x01(\x0b\x32\x17.google.protobuf.Struct27\n\x07Isolate\x12,\n\x03Run\x12\x0e.BoundFunction\x1a\x11.PartialRunResult\"\x00\x30\x01\x62\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile( + b'\n\x0cserver.proto\x1a\x0c\x63ommon.proto\x1a\x1cgoogle/protobuf/struct.proto"b\n\rBoundFunction\x12,\n\x0c\x65nvironments\x18\x01 \x03(\x0b\x32\x16.EnvironmentDefinition\x12#\n\x08\x66unction\x18\x02 \x01(\x0b\x32\x11.SerializedObject"U\n\x15\x45nvironmentDefinition\x12\x0c\n\x04kind\x18\x01 \x01(\t\x12.\n\rconfiguration\x18\x02 \x01(\x0b\x32\x17.google.protobuf.Struct27\n\x07Isolate\x12,\n\x03Run\x12\x0e.BoundFunction\x1a\x11.PartialRunResult"\x00\x30\x01\x62\x06proto3' +) _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'server_pb2', globals()) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, "server_pb2", globals()) if _descriptor._USE_C_DESCRIPTORS == False: - DESCRIPTOR._options = None - _BOUNDFUNCTION._serialized_start=60 - _BOUNDFUNCTION._serialized_end=158 - _ENVIRONMENTDEFINITION._serialized_start=160 - _ENVIRONMENTDEFINITION._serialized_end=245 - _ISOLATE._serialized_start=247 - _ISOLATE._serialized_end=302 + DESCRIPTOR._options = None + _BOUNDFUNCTION._serialized_start = 60 + _BOUNDFUNCTION._serialized_end = 158 + _ENVIRONMENTDEFINITION._serialized_start = 160 + _ENVIRONMENTDEFINITION._serialized_end = 245 + _ISOLATE._serialized_start = 247 + _ISOLATE._serialized_end = 302 # @@protoc_insertion_point(module_scope) diff --git a/src/isolate/server/definitions/server_pb2.pyi b/src/isolate/server/definitions/server_pb2.pyi index 5b67709..4e2b68f 100644 --- a/src/isolate/server/definitions/server_pb2.pyi +++ b/src/isolate/server/definitions/server_pb2.pyi @@ -25,17 +25,29 @@ class BoundFunction(google.protobuf.message.Message): ENVIRONMENTS_FIELD_NUMBER: builtins.int FUNCTION_FIELD_NUMBER: builtins.int @property - def environments(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___EnvironmentDefinition]: ... + def environments( + self, + ) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[ + global___EnvironmentDefinition + ]: ... @property def function(self) -> common_pb2.SerializedObject: ... def __init__( self, *, - environments: collections.abc.Iterable[global___EnvironmentDefinition] | None = ..., + environments: collections.abc.Iterable[global___EnvironmentDefinition] + | None = ..., function: common_pb2.SerializedObject | None = ..., ) -> None: ... - def HasField(self, field_name: typing_extensions.Literal["function", b"function"]) -> builtins.bool: ... - def ClearField(self, field_name: typing_extensions.Literal["environments", b"environments", "function", b"function"]) -> None: ... + def HasField( + self, field_name: typing_extensions.Literal["function", b"function"] + ) -> builtins.bool: ... + def ClearField( + self, + field_name: typing_extensions.Literal[ + "environments", b"environments", "function", b"function" + ], + ) -> None: ... global___BoundFunction = BoundFunction @@ -56,7 +68,14 @@ class EnvironmentDefinition(google.protobuf.message.Message): kind: builtins.str = ..., configuration: google.protobuf.struct_pb2.Struct | None = ..., ) -> None: ... - def HasField(self, field_name: typing_extensions.Literal["configuration", b"configuration"]) -> builtins.bool: ... - def ClearField(self, field_name: typing_extensions.Literal["configuration", b"configuration", "kind", b"kind"]) -> None: ... + def HasField( + self, field_name: typing_extensions.Literal["configuration", b"configuration"] + ) -> builtins.bool: ... + def ClearField( + self, + field_name: typing_extensions.Literal[ + "configuration", b"configuration", "kind", b"kind" + ], + ) -> None: ... global___EnvironmentDefinition = EnvironmentDefinition diff --git a/src/isolate/server/definitions/server_pb2_grpc.py b/src/isolate/server/definitions/server_pb2_grpc.py index f1b02da..58eebad 100644 --- a/src/isolate/server/definitions/server_pb2_grpc.py +++ b/src/isolate/server/definitions/server_pb2_grpc.py @@ -16,10 +16,10 @@ def __init__(self, channel): channel: A grpc.Channel. """ self.Run = channel.unary_stream( - '/Isolate/Run', - request_serializer=server__pb2.BoundFunction.SerializeToString, - response_deserializer=common__pb2.PartialRunResult.FromString, - ) + "/Isolate/Run", + request_serializer=server__pb2.BoundFunction.SerializeToString, + response_deserializer=common__pb2.PartialRunResult.FromString, + ) class IsolateServicer(object): @@ -30,40 +30,53 @@ def Run(self, request, context): and the result originating from that function. """ context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') + context.set_details("Method not implemented!") + raise NotImplementedError("Method not implemented!") def add_IsolateServicer_to_server(servicer, server): rpc_method_handlers = { - 'Run': grpc.unary_stream_rpc_method_handler( - servicer.Run, - request_deserializer=server__pb2.BoundFunction.FromString, - response_serializer=common__pb2.PartialRunResult.SerializeToString, - ), + "Run": grpc.unary_stream_rpc_method_handler( + servicer.Run, + request_deserializer=server__pb2.BoundFunction.FromString, + response_serializer=common__pb2.PartialRunResult.SerializeToString, + ), } generic_handler = grpc.method_handlers_generic_handler( - 'Isolate', rpc_method_handlers) + "Isolate", rpc_method_handlers + ) server.add_generic_rpc_handlers((generic_handler,)) - # This class is part of an EXPERIMENTAL API. +# This class is part of an EXPERIMENTAL API. class Isolate(object): """Missing associated documentation comment in .proto file.""" @staticmethod - def Run(request, + def Run( + request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None, + ): + return grpc.experimental.unary_stream( + request, target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_stream(request, target, '/Isolate/Run', + "/Isolate/Run", server__pb2.BoundFunction.SerializeToString, common__pb2.PartialRunResult.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + options, + channel_credentials, + insecure, + call_credentials, + compression, + wait_for_ready, + timeout, + metadata, + ) diff --git a/tests/test_server.py b/tests/test_server.py index 2f657e7..a8e6f32 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -242,7 +242,9 @@ def test_server_multiple_envs( requirements.append(f"{REPO_DIR}[grpc]") env_definition = define_environment("virtualenv", requirements=requirements) - xtra_env_definition = define_environment("virtualenv", requirements=xtra_requirements) + xtra_env_definition = define_environment( + "virtualenv", requirements=xtra_requirements + ) request = definitions.BoundFunction( function=to_serialized_object( partial(