GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — feat: add rest transport generation for clients with optional flag by yon-mg · Pull Request #688 · googleapis/gapic-generator-python
This repository was archived by the owner on Aug 25, 2026. It is now read-only.
Conversation
|
|
|
||
|
|
||
| {%- for method in service.methods.values() %} | ||
| {# TODO(yonmg): consider using enums #} |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
+1 for using enums.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| {%- if ns.http.get != '' %} | ||
| {%- set ns.httpMethod = {'method':'get','url':ns.http.get} %} | ||
| {%- elif ns.http.put != '' %} | ||
| {%- set ns.httpMethod = {'method':'put','url':ns.http.put} %} | ||
| {%- elif ns.http.post != '' %} | ||
| {%- set ns.httpMethod = {'method':'post','url':ns.http.post} %} | ||
| {%- elif ns.http.delete != '' %} | ||
| {%- set ns.httpMethod = {'method':'delete','url':ns.http.delete} %} | ||
| {%- elif ns.http.patch != '' %} | ||
| {%- set ns.httpMethod = {'method':'patch','url':ns.http.patch} %} | ||
| {%- elif ns.http.custom != '' %} | ||
| {%- set ns.httpMethod = {'method':'custom','url':ns.http.custom} %} | ||
| {%- else %} | ||
| {%- set ns.httpMethod = None %} | ||
| {%- endif %} |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'm leaning towards anything that involves state modification living in the generator datatypes. It's easier to test and easier to change if we need to.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand what you mean by generator datatypes. Could you clarify?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The gapic/schema/wrappers.py:{MessageType,Service,Method} classes. The auxiliary datastructures that the generate creates before iterating over the templates.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Is the REST transport going to be added in one PR? If not, can we maintain a long-running branch and merge to it instead? The microgenerator is now relied on by Cloud clients at GA stability so I'd prefer not to to surface this until it is somewhat stable. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This sounds reasonable to me. I'll defer to the other reviewers on what the best practice should be. @software-dov @vam-google @vchudnov-g |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
If it's not too much work, I think I'd be more in favor of feature toggles and small PRs instead of having a long-running branch. It's easier to do merging. If that seems like too much work, I'm okay with a long-running branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I agree with this somewhat but for consistency across other languages, flag arguments and regapic design specs, I think it's more appropriate to name it Rest. In addition, it's because it's possible to do protobuf over http that naming it such may be ambiguous. Rest seems to me more clearly defined. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a few things.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| lazy_import: bool = False | ||
| old_naming: bool = False | ||
| add_iam_methods: bool = False | ||
| # TODO(yonmg): should there be an enum for transport type? |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
+1 for using an enum
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Codecov Report
@@ Coverage Diff @@ ## master #688 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 26 26 Lines 1560 1578 +18 Branches 316 320 +4 ========================================= + Hits 1560 1578 +18
Continue to review full report at Codecov.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just two minor nits.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| ] | ||
| with mock.patch.object(jinja2.Environment, "get_template") as gt: | ||
| gt.return_value = jinja2.Template("Service: {{ service.name }}") | ||
| cgr = g.get_response(api_schema=make_api( |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Formatting nit: putting this on a new line makes it slightly easier to read the entire thing.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| 'transport' in template_name | ||
| and not self._is_desired_transport(template_name, opts) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Can you put parentheses around this chunk, just to make it clear that it's a cohesive unit?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| from collections import defaultdict | ||
| from os import path | ||
| from typing import Any, DefaultDict, Dict, FrozenSet, List, Optional, Tuple | ||
| from typing import Any, DefaultDict, Dict, FrozenSet, List, Optional, Tuple, Set |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Is Set used somewhere?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM
All the comments are minor. Please address them and then push the changes (please use squash and merge button). Thanks @software-dov for sharing your expertise in Python review!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| '{{ enum.name }}': '{{ enum.ident.package|join('.') }}.types.{{enum.ident.module }}', | ||
| {%- endfor %} | ||
|
|
||
| {# TODO(yonmg): add rest transport service once I know what this is #} |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Please use your github id for TODOs (here and in the other places)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
+1
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| server='stream' if self.server_streaming else 'unary', | ||
| ) | ||
|
|
||
| # TODO(yonmg): figure out why idempotent is reliant on http annotation |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
http GET requests are automatically considered idempotent because they do not change data on the server. Post requests are usually non-idempotent, because it is usually unsafe retry write operation if it failed, because it may lead for example into writing the same information twice on the server.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I get that GET is idempotent but couldn't there be methods without an http annotation that are also idempotent? are grpc only methods inherently not so?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # Sanity check: Only create a new client if we do not already have one. | ||
| if 'operations_client' not in self.__dict__: | ||
| self.__dict__['operations_client'] = operations_v1.OperationsClient( | ||
| if self._operations_client is None: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
won't if not self._operation_client work? I thought it was more idiomatic for python.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It's a little bit complicated. Some values can be falsy even if they are non-null, e.g. empty lists and strings.
In this particular case, it's slightly more idiomatic to do if self._operations_client, but I personally am fine with explicit checks in cases like this.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| """Create and return a gRPC channel object. | ||
| Args: | ||
| address (Optionsl[str]): The host for the channel to use. | ||
| address (Optional[str]): The host for the channel to use. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Why was this changed (looks unrelated to your changes)?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Typo
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I approve of fixing typos on the fly!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # Sanity check: Only create a new client if we do not already have one. | ||
| if 'operations_client' not in self.__dict__: | ||
| self.__dict__['operations_client'] = operations_v1.OperationsAsyncClient( | ||
| if self._operations_client is None: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Why are you changing this code (looks unrelated to http transport stuff)?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
#688 (comment)
I decided to update the other templates as well for consistency.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
+1 for consistency
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| __all__ = ( | ||
| '{{ service.name }}RestTransport', | ||
| ) | ||
| {% endblock %} No newline at end of file |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Please add new line
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Only minor comments. Nice job! Very excited to have this in!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| '{{ enum.name }}': '{{ enum.ident.package|join('.') }}.types.{{enum.ident.module }}', | ||
| {%- endfor %} | ||
|
|
||
| {# TODO(yonmg): add rest transport service once I know what this is #} |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
+1
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| # Pull apart arguments in the request. | ||
| opts = Options.build(req.parameter) | ||
|
|
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
nit: I like having the blank line here for readability.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # Return the usual output. | ||
| return self.output | ||
|
|
||
| # TODO(yonmg): remove or rewrite. don't think it performs as intended |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
nit: Suggest adding just a tiny bit more detail. It often happens that the person working on the TODO is not the person who wrote it, so adding some context is a helpful practice.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
| if len(http) > 1: | ||
| http_opt = http[1] | ||
| answer[http_opt[0].name] = http_opt[1] |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
For clarity I would suggest
body_spec = http[1]
answer[body_spec[0].name] = body_spec[1]
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| http_method = http[0] | ||
| answer: Dict[str, str] = { | ||
| 'method': http_method[0].name, |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Based on our offline discussion, let's s/'method'/'verb'/, since "method" is overloaded (service method, object method, HTTP method)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
If this be madness, there be method to it! 💀
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @property | ||
| def http_opt(self) -> Optional[Dict[str, str]]: | ||
| """Return the http option for this method.""" | ||
| http = self.options.Extensions[annotations_pb2.http].ListFields() |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I do think a type declaration or a comment saying this is a List[Tuple[FieldDescriptor, str]] would be helpful.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| """Create and return a gRPC channel object. | ||
| Args: | ||
| address (Optionsl[str]): The host for the channel to use. | ||
| address (Optional[str]): The host for the channel to use. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I approve of fixing typos on the fly!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
🤖 I have created a release \*beep\* \*boop\* --- ## [0.36.0](https://www.github.com/googleapis/gapic-generator-python/compare/v0.35.11...v0.36.0) (2020-11-14) ### Features * add rest transport generation for clients with optional transport flag ([#688](https://www.github.com/googleapis/gapic-generator-python/issues/688)) ([af59c2c](https://www.github.com/googleapis/gapic-generator-python/commit/af59c2c3c3d6b7e1f626c3fbc2c03f99ca31b4a4)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please).
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Re-add HTTP transport and make it the fallback
There was an error while loading. Please reload this page.