-
Notifications
You must be signed in to change notification settings - Fork 66
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
Refactor to support the finalized-ish input format. #6
Conversation
Codecov Report
@@ Coverage Diff @@
## master #6 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 13 14 +1
Lines 316 378 +62
Branches 44 58 +14
=====================================
+ Hits 316 378 +62
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know enough Python to comment on most of this :P
api_factory/cli/generate.py
Outdated
@@ -40,7 +42,12 @@ def generate( | |||
|
|||
# Translate into a protobuf CodeGeneratorResponse; | |||
# if there are issues, error out appropriately. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Naming
class seems inconsistent. The wrapper classes have their naming methods included in the class itself without adding a new naming class. Can you provide more context around adding the Naming class?
The wrapper classes generally have "their name" and nothing else. This has a bunch of names and variants. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a lot of frozen dataclasses that are using the @Property annotation rather than the @cached_property annotation. What is your threshold for using @cached_property?
the messages for which being laoded. In other words, this is | ||
the segment of the source info that has paths matching | ||
or within ``children``. | ||
path (Tuple[int]): The location path up to this point. This is |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
address: metadata.Address, info: dict) -> None: | ||
"""Load arbitrary children from a Descriptor. | ||
|
||
def _load_children(self, children: Sequence, loader: Callable, *, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -258,34 +317,34 @@ def _load_descriptor(self, message_pb: descriptor_pb2.DescriptorProto, | |||
fields = self._get_fields( | |||
message_pb.field, | |||
address=nested_addr, | |||
info=info.get(2, {}), | |||
path=path + (2,), | |||
) | |||
fields.update(self._get_fields( |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
self._load_children(message_pb.enum_type, address=nested_addr, | ||
loader=self._load_enum, info=info.get(4, {})) | ||
loader=self._load_enum, path=path + (4,)) | ||
# self._load_children(message.oneof_decl, loader=self._load_field, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
answer[meth_pb.name] = wrappers.Method( | ||
input=self.all_messages[meth_pb.input_type.lstrip('.')], | ||
lro_metadata=self.all_messages.get(types.metadata, None), | ||
lro_payload=self.all_messages.get(types.response, None), |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
docs/api-configuration.rst
Outdated
This is rolled up into a strcuture spelled ``Client``, and the annotation | ||
is defined in `google/api/experimental/client.proto`_. | ||
This is rolled up into a strcuture spelled ``Metadata``, and the annotation | ||
is defined in `google/api/metadata.proto`_. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
I use |
api_factory/schema/naming.py
Outdated
# This code may look counter-intuitive (why not use ? to make it | ||
# optional), but the engine's greediness routine will decide that | ||
# the version is the name, which is not what we want. | ||
version = r'\.(?P<version>v[0-9]+(p[0-9]+)?((alpha|beta|test)[0-9])*)' |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
"""Return the field headers defined for this method.""" | ||
http = self.options.Extensions[annotations_pb2.http] | ||
if http.get: | ||
return tuple(re.findall(r'\{([a-z][\w\d_.]+)=', http.get)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -88,7 +88,12 @@ class {{ service.name }}HttpTransport({{ service.name }}Transport): | |||
|
|||
# Send the request. | |||
response = self._session.post( | |||
f'https://{self.SERVICE_ADDRESS}/$rpc/{{ '.'.join(method.meta.address.package) }}.{{ service.name }}/{{ method.name }}', | |||
'https://{host}/$rpc/{package}.{service}/{method}'.format( |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
library will work. | ||
|
||
Look for values enclosed by ``<<<`` and ``>>>`` to quickly spot these. | ||
As of this writing, these are the ``SERVICE_ADDRESS`` and ``OAUTH_SCOPES`` |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
tests/unit/schema/test_api.py
Outdated
assert args[1] == pb._load_service | ||
|
||
|
||
def test_not_taget_file(): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after the following issues are filed:
- regex on the version matcher
- LRO silent failure
# | ||
# This code may look counter-intuitive (why not use ? to make it | ||
# optional), but the engine's greediness routine will decide that | ||
# the version is the name, which is not what we want. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: the engine's greediness can be limited by appending ?
to +
or *
. If the namespace pattern is changed to (?P<namespace>[a-z0-9_.]+?)
it will never eat more than it's supposed to.
This is a refactor to support the input format we landed on.
It does a lot of things:
templates/
in the project root.API
class to maintain some separation between the source proto files. (I want this because I eventually may want some per-proto functionality.)API
andProto
are now frozen dataclasses. In order to support this, there arebuild
class methods on both.Naming
class is added, and naming-based things are moved there (fromAPI
).