Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of StubDataClayObject #55

Merged
merged 15 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dataclay-common
19 changes: 19 additions & 0 deletions examples/stub/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from dataclay import Client, StubDataClayObject
from dataclay.contrib.modeltest.family import Person

client = Client(host="127.0.0.1")
client.start()

# PersonStub = StubDataClayObject["dataclay.contrib.modeltest.family.Person"]
PersonStub = StubDataClayObject[
"dataclay.contrib.modeltest.family.Person", ["name", "age"], ["add_year"]
]

p = PersonStub(name="Alice", age=30)
# p = PersonStub.get_by_alias("Alice")


# print(p.name) # Alice
# p.age = 31

# p.add_year()
13 changes: 10 additions & 3 deletions src/dataclay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@

from dataclay.client.api import Client
from dataclay.dataclay_object import DataClayObject, activemethod

from dataclay.alien import AlienDataClayObject # isort: skip
from dataclay.alien import AlienDataClayObject
from dataclay.stub import StubDataClayObject

StorageObject = DataClayObject

__version__ = "4.2.0.dev"
__all__ = ["Client", "DataClayObject", "AlienDataClayObject", "activemethod", "StorageObject"]
__all__ = [
"Client",
"DataClayObject",
"AlienDataClayObject",
"StubDataClayObject",
"activemethod",
"StorageObject",
]
6 changes: 6 additions & 0 deletions src/dataclay/backend/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,9 @@ async def stop(self):
@grpc_aio_error_handler
async def drain(self):
await self.stub.Drain(empty_pb2.Empty())

@grpc_aio_error_handler
async def get_class_info(self, class_name):
request = backend_pb2.GetClassInfoRequest(class_name=class_name)
response = await self.stub.GetClassInfo(request, metadata=self.metadata_call)
return response.properties, response.activemethods
7 changes: 7 additions & 0 deletions src/dataclay/backend/servicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
)
from grpc_health.v1 import health, health_pb2, health_pb2_grpc

from dataclay import utils
from dataclay.backend.api import BackendAPI
from dataclay.config import session_var, settings
from dataclay.event_loop import get_dc_event_loop, set_dc_event_loop
Expand Down Expand Up @@ -339,3 +340,9 @@ async def NewObjectReplica(self, request, context):
request.remotes,
)
return Empty()

@ServicerMethod(backend_pb2.GetClassInfoResponse)
async def GetClassInfo(self, request, context):
cls = utils.get_class_by_name(request.class_name)
properties, activemethods = utils.get_class_info(cls)
return backend_pb2.GetClassInfoResponse(properties=properties, activemethods=activemethods)
24 changes: 19 additions & 5 deletions src/dataclay/proto/backend/backend_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 45 additions & 7 deletions src/dataclay/proto/backend/backend_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb2
from google.protobuf import wrappers_pb2 as google_dot_protobuf_dot_wrappers__pb2

GRPC_GENERATED_VERSION = '1.64.1'
GRPC_GENERATED_VERSION = '1.70.0'
GRPC_VERSION = grpc.__version__
EXPECTED_ERROR_RELEASE = '1.65.0'
SCHEDULED_RELEASE_DATE = 'June 25, 2024'
_version_not_supported = False

try:
Expand All @@ -20,15 +18,12 @@
_version_not_supported = True

if _version_not_supported:
warnings.warn(
raise RuntimeError(
f'The grpc package installed is at version {GRPC_VERSION},'
+ f' but the generated code in dataclay/proto/backend/backend_pb2_grpc.py depends on'
+ f' grpcio>={GRPC_GENERATED_VERSION}.'
+ f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}'
+ f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.'
+ f' This warning will become an error in {EXPECTED_ERROR_RELEASE},'
+ f' scheduled for release on {SCHEDULED_RELEASE_DATE}.',
RuntimeWarning
)


Expand Down Expand Up @@ -126,6 +121,11 @@ def __init__(self, channel):
request_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString,
response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
_registered_method=True)
self.GetClassInfo = channel.unary_unary(
'/dataclay.proto.backend.BackendService/GetClassInfo',
request_serializer=dataclay_dot_proto_dot_backend_dot_backend__pb2.GetClassInfoRequest.SerializeToString,
response_deserializer=dataclay_dot_proto_dot_backend_dot_backend__pb2.GetClassInfoResponse.FromString,
_registered_method=True)


class BackendServiceServicer(object):
Expand Down Expand Up @@ -233,6 +233,12 @@ def Drain(self, request, context):
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def GetClassInfo(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')


def add_BackendServiceServicer_to_server(servicer, server):
rpc_method_handlers = {
Expand Down Expand Up @@ -321,6 +327,11 @@ def add_BackendServiceServicer_to_server(servicer, server):
request_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
response_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString,
),
'GetClassInfo': grpc.unary_unary_rpc_method_handler(
servicer.GetClassInfo,
request_deserializer=dataclay_dot_proto_dot_backend_dot_backend__pb2.GetClassInfoRequest.FromString,
response_serializer=dataclay_dot_proto_dot_backend_dot_backend__pb2.GetClassInfoResponse.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(
'dataclay.proto.backend.BackendService', rpc_method_handlers)
Expand Down Expand Up @@ -790,3 +801,30 @@ def Drain(request,
timeout,
metadata,
_registered_method=True)

@staticmethod
def GetClassInfo(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_unary(
request,
target,
'/dataclay.proto.backend.BackendService/GetClassInfo',
dataclay_dot_proto_dot_backend_dot_backend__pb2.GetClassInfoRequest.SerializeToString,
dataclay_dot_proto_dot_backend_dot_backend__pb2.GetClassInfoResponse.FromString,
options,
channel_credentials,
insecure,
call_credentials,
compression,
wait_for_ready,
timeout,
metadata,
_registered_method=True)
12 changes: 11 additions & 1 deletion src/dataclay/proto/common/common_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading