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

Refactor to support the finalized-ish input format. #6

Merged
merged 22 commits into from
Jul 13, 2018

Conversation

lukesneeringer
Copy link
Contributor

@lukesneeringer lukesneeringer commented Jul 12, 2018

This is a refactor to support the input format we landed on.

It does a lot of things:

  • Uses the new annotations.
  • Moves templates to templates/ in the project root.
  • Removes support for flat files, which are no longer needed with @garrettjonesgoogle's package generation work.
  • It refactors the API class to maintain some separation between the source proto files. (I want this because I eventually may want some per-proto functionality.)
  • API and Proto are now frozen dataclasses. In order to support this, there are build class methods on both.
  • A new Naming class is added, and naming-based things are moved there (from API).
  • Updates documentation to be current.
  • Officially supports Python 3.7.

@codecov
Copy link

codecov bot commented Jul 12, 2018

Codecov Report

Merging #6 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master     #6   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          13     14    +1     
  Lines         316    378   +62     
  Branches       44     58   +14     
=====================================
+ Hits          316    378   +62
Impacted Files Coverage Δ
api_factory/schema/naming.py 100% <100%> (ø)
api_factory/schema/api.py 100% <100%> (ø) ⬆️
api_factory/generator/generator.py 100% <100%> (ø) ⬆️
api_factory/utils/cache.py 100% <100%> (ø) ⬆️
api_factory/schema/wrappers.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e3ae3e6...39cd08f. Read the comment docs.

Copy link

@pongad pongad left a 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

@@ -40,7 +42,12 @@ def generate(

# Translate into a protobuf CodeGeneratorResponse;
# if there are issues, error out appropriately.

This comment was marked as spam.

Copy link

@landrito landrito left a 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?

@lukesneeringer
Copy link
Contributor Author

The wrapper classes generally have "their name" and nothing else. This has a bunch of names and variants.

Copy link

@landrito landrito left a 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.

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.

This comment was marked as spam.

@@ -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.

This comment was marked as spam.

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.

This comment was marked as spam.

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.

This comment was marked as spam.

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.

@lukesneeringer
Copy link
Contributor Author

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?

I use @cached_property if something non-trivial is being computed, or in cases where we return instances and it matters that the instances be the same object rather than an equivalent copy.

# 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.

This comment was marked as spam.

"""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.

This comment was marked as spam.

This comment was marked as spam.

@@ -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.

This comment was marked as spam.

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.

assert args[1] == pb._load_service


def test_not_taget_file():

This comment was marked as spam.

Copy link

@landrito landrito left a 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

@lukesneeringer lukesneeringer merged commit 71845cd into master Jul 13, 2018
@lukesneeringer lukesneeringer deleted the input-refactor branch July 13, 2018 18:05
#
# 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.
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants