From 82c2d40966bf8eb22ce305862fe4b985d90a3f8f Mon Sep 17 00:00:00 2001 From: Wayne Manselle Date: Sat, 17 Feb 2024 20:04:30 -0800 Subject: [PATCH 1/2] Documentation and Deprecations --- CHANGELOG.md | 11 +++++++++++ src/examples/README.md | 7 ++++--- src/grpc_requests/aio.py | 15 ++++++++++++--- src/grpc_requests/client.py | 18 +++++++++++++----- src/grpc_requests/utils.py | 2 +- 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fd8079..ac8b8d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.1.15](https://github.com/wesky93/grpc_requests/releases/tag/v0.1.15) - 2024-02-17 + +## Added + +- Add methods to return FileDescriptors and their transistive dependencies as requested by either a name or symbol + +## Deprecated + +- Due to the possibility of transient dependencies being missed, or other name or symbol collisions, methods to access singular FileDescriptors are deprecated and will be removed in version 0.1.17 +- The method to retrieve fields of a method's descriptor input type alone will be removed in version 0.1.17 + ## [0.1.14](https://github.com/wesky93/grpc_requests/releases/tag/v0.1.14) - 2024-01-06 ## Added diff --git a/src/examples/README.md b/src/examples/README.md index 151bb65..151db87 100644 --- a/src/examples/README.md +++ b/src/examples/README.md @@ -141,9 +141,10 @@ client = Client("localhost:50051") greeterServiceDescriptor = client.get_service_descriptor("helloworld.Greeter") sayHelloDescriptor = client.get_method_descriptor("helloworld.Greeter","SayHello") -#As of 0.1.14 FileDescriptor Methods are only exposed on Reflection Clients -fileDescriptorByName = client.get_file_descriptor_by_name("helloworld.proto") -fileDescriptorBySymbol = client.get_file_descriptor_by_symbol("helloworld.Greeter") +# As of 0.1.14 FileDescriptor Methods are only exposed on Reflection Clients +# As of 0.1.15 all descriptors related to the name or symbol will be returned as a list +helloworldFileDescriptors = client.get_file_descriptors_by_name("helloworld.proto") +greeterServiceFileDescriptors = client.get_file_descriptors_by_symbol("helloworld.Greeter") ``` ### Method Metadata diff --git a/src/grpc_requests/aio.py b/src/grpc_requests/aio.py index 07298b4..0f920b9 100644 --- a/src/grpc_requests/aio.py +++ b/src/grpc_requests/aio.py @@ -1,5 +1,6 @@ import logging import sys +import warnings from enum import Enum from functools import partial from typing import ( @@ -452,12 +453,20 @@ async def _get_service_names(self): services = tuple([s.name for s in resp.list_services_response.service]) return services + warnings.warn( + "This function is deprecated, and will be removed in the 0.1.17 release. Use get_file_descriptors_by_name() instead.", + DeprecationWarning, + ) async def get_file_descriptor_by_name(self, name): request = reflection_pb2.ServerReflectionRequest(file_by_filename=name) result = await self._reflection_single_request(request) proto = result.file_descriptor_response.file_descriptor_proto[0] return descriptor_pb2.FileDescriptorProto.FromString(proto) + warnings.warn( + "This function is deprecated, and will be removed in the 0.1.17 release. Use get_file_descriptors_by_symbol() instead.", + DeprecationWarning, + ) async def get_file_descriptor_by_symbol(self, symbol): request = reflection_pb2.ServerReflectionRequest(file_containing_symbol=symbol) result = await self._reflection_single_request(request) @@ -488,9 +497,9 @@ def _is_descriptor_registered(self, filename): except KeyError: return False - # In practice it always seems like descriptors are returned in an order that makes sense for dependency - # registration, but i can't find a guarantee in the spec - # Because of this, go one by one and register, using the other returned descriptors as possible dependencies + # Iterate over descriptors for registration, including returned descriptors as possible dependencies. + # This is necessary as while in practice descriptors appear to be returned in an order that works for dependency + # registration, this is not guaranteed in the reflection specification. async def register_file_descriptors(self, file_descriptors): for file_descriptor in file_descriptors: await self._register_file_descriptor(file_descriptor, file_descriptors) diff --git a/src/grpc_requests/client.py b/src/grpc_requests/client.py index ffa170d..d998c9a 100644 --- a/src/grpc_requests/client.py +++ b/src/grpc_requests/client.py @@ -392,8 +392,8 @@ def get_service_descriptor(self, service): def describe_method_request(self, service, method): warnings.warn( - "This function is deprecated, and will be removed in a future release. Use describe_request() instead.", - DeprecationWarning, + "This function is deprecated, and will be removed in the 0.1.17 release. Use describe_descriptor() instead.", + DeprecationWarning, ) return describe_request(self.get_method_descriptor(service, method)) @@ -472,12 +472,20 @@ def _get_service_names(self): services = tuple([s.name for s in resp.list_services_response.service]) return services + warnings.warn( + "This function is deprecated, and will be removed in the 0.1.17 release. Use get_file_descriptors_by_name() instead.", + DeprecationWarning, + ) def get_file_descriptor_by_name(self, name): request = reflection_pb2.ServerReflectionRequest(file_by_filename=name) result = self._reflection_single_request(request) proto = result.file_descriptor_response.file_descriptor_proto[0] return descriptor_pb2.FileDescriptorProto.FromString(proto) + warnings.warn( + "This function is deprecated, and will be removed in the 0.1.17 release. Use get_file_descriptors_by_symbol() instead.", + DeprecationWarning, + ) def get_file_descriptor_by_symbol(self, symbol): request = reflection_pb2.ServerReflectionRequest(file_containing_symbol=symbol) result = self._reflection_single_request(request) @@ -508,9 +516,9 @@ def _is_descriptor_registered(self, filename): except KeyError: return False - # In practice it always seems like descriptors are returned in an order that makes sense for dependency - # registration, but i can't find a guarantee in the spec - # Because of this, go one by one and register, using the other returned descriptors as possible dependencies + # Iterate over descriptors for registration, including returned descriptors as possible dependencies. + # This is necessary as while in practice descriptors appear to be returned in an order that works for dependency + # registration, this is not guaranteed in the reflection specification. def register_file_descriptors(self, file_descriptors): for file_descriptor in file_descriptors: self._register_file_descriptor(file_descriptor, file_descriptors) diff --git a/src/grpc_requests/utils.py b/src/grpc_requests/utils.py index 2502741..b84c0c3 100644 --- a/src/grpc_requests/utils.py +++ b/src/grpc_requests/utils.py @@ -45,7 +45,7 @@ def describe_request(method_descriptor: MethodDescriptor) -> dict: :return: dict - a mapping of field names to their types """ warnings.warn( - "This function is deprecated, and will be removed in a future release. Use describe_descriptor() instead.", + "This function is deprecated, and will be removed in the 0.1.17 release. Use describe_descriptor() instead.", DeprecationWarning, ) description = {} From 99c2e55c7287f482c35ea721cde5580ea2a4581c Mon Sep 17 00:00:00 2001 From: Wayne Manselle Date: Sat, 17 Feb 2024 20:15:41 -0800 Subject: [PATCH 2/2] Run formatter --- src/grpc_requests/aio.py | 2 ++ src/grpc_requests/client.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/grpc_requests/aio.py b/src/grpc_requests/aio.py index 0f920b9..7a03e68 100644 --- a/src/grpc_requests/aio.py +++ b/src/grpc_requests/aio.py @@ -457,6 +457,7 @@ async def _get_service_names(self): "This function is deprecated, and will be removed in the 0.1.17 release. Use get_file_descriptors_by_name() instead.", DeprecationWarning, ) + async def get_file_descriptor_by_name(self, name): request = reflection_pb2.ServerReflectionRequest(file_by_filename=name) result = await self._reflection_single_request(request) @@ -467,6 +468,7 @@ async def get_file_descriptor_by_name(self, name): "This function is deprecated, and will be removed in the 0.1.17 release. Use get_file_descriptors_by_symbol() instead.", DeprecationWarning, ) + async def get_file_descriptor_by_symbol(self, symbol): request = reflection_pb2.ServerReflectionRequest(file_containing_symbol=symbol) result = await self._reflection_single_request(request) diff --git a/src/grpc_requests/client.py b/src/grpc_requests/client.py index d998c9a..f9d3467 100644 --- a/src/grpc_requests/client.py +++ b/src/grpc_requests/client.py @@ -393,7 +393,7 @@ def get_service_descriptor(self, service): def describe_method_request(self, service, method): warnings.warn( "This function is deprecated, and will be removed in the 0.1.17 release. Use describe_descriptor() instead.", - DeprecationWarning, + DeprecationWarning, ) return describe_request(self.get_method_descriptor(service, method)) @@ -476,6 +476,7 @@ def _get_service_names(self): "This function is deprecated, and will be removed in the 0.1.17 release. Use get_file_descriptors_by_name() instead.", DeprecationWarning, ) + def get_file_descriptor_by_name(self, name): request = reflection_pb2.ServerReflectionRequest(file_by_filename=name) result = self._reflection_single_request(request) @@ -486,6 +487,7 @@ def get_file_descriptor_by_name(self, name): "This function is deprecated, and will be removed in the 0.1.17 release. Use get_file_descriptors_by_symbol() instead.", DeprecationWarning, ) + def get_file_descriptor_by_symbol(self, symbol): request = reflection_pb2.ServerReflectionRequest(file_containing_symbol=symbol) result = self._reflection_single_request(request)