Skip to content

Commit

Permalink
Merge pull request #68 from wesky93/viridianforge/0.1.15-prep
Browse files Browse the repository at this point in the history
Viridianforge/0.1.15 prep
  • Loading branch information
ViridianForge authored Feb 18, 2024
2 parents 19283dc + 99c2e55 commit 762c46a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 14 additions & 3 deletions src/grpc_requests/aio.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import sys
import warnings
from enum import Enum
from functools import partial
from typing import (
Expand Down Expand Up @@ -452,12 +453,22 @@ 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)
Expand Down Expand Up @@ -488,9 +499,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)
Expand Down
18 changes: 14 additions & 4 deletions src/grpc_requests/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,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 a future release. Use describe_request() instead.",
"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))
Expand Down Expand Up @@ -472,12 +472,22 @@ 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)
Expand Down Expand Up @@ -508,9 +518,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)
Expand Down
2 changes: 1 addition & 1 deletion src/grpc_requests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down

0 comments on commit 762c46a

Please sign in to comment.