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

fix: updating testing, rest-only generation, & minor bug-fixes #716

Merged
merged 40 commits into from
Dec 30, 2020
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
c1a6f89
feat: add rest transport generation for clients
yon-mg Nov 2, 2020
bd7c32d
feat: add rest transport generation for clients
yon-mg Nov 2, 2020
cd3a7f1
Merge branch 'master' of github.com:yon-mg/gapic-generator-python
yon-mg Nov 2, 2020
b41db31
feat: add transport flag
yon-mg Nov 6, 2020
ce69e7d
refactor: moved template logic outside
yon-mg Nov 6, 2020
89fa08b
fix: small fixes in transport option logic
yon-mg Nov 9, 2020
86f3a9c
test: added unit test for transport flag
yon-mg Nov 9, 2020
234cc09
test: add unit test for http option method
yon-mg Nov 11, 2020
35ac276
test: add unit test for http option method branch
yon-mg Nov 11, 2020
c8155a5
fix: fix import paths
yon-mg Nov 11, 2020
55a815c
fix: style check issues
yon-mg Nov 11, 2020
ac0bdef
fix: more style check issues
yon-mg Nov 11, 2020
e79e8c7
fix: addressing pr reviews
yon-mg Nov 13, 2020
824ad11
fix: typo in test_method
yon-mg Nov 13, 2020
2d11e19
fix: style check fixes
yon-mg Nov 13, 2020
b5c6d06
Merge branch 'master' into master
yon-mg Nov 14, 2020
221cd44
feat: add proper handling of query/path/body parameters for rest tran…
yon-mg Nov 20, 2020
475f903
Merge branch 'master' of github.com:yon-mg/gapic-generator-python
yon-mg Nov 20, 2020
f08ca32
Merge remote-tracking branch 'upstream/master'
yon-mg Nov 20, 2020
efa0ed6
fix: typing errors
yon-mg Nov 20, 2020
d3e08c0
Update case.py
software-dov Nov 20, 2020
df88ef9
fix: minor changes adding a test, refactor and style check
yon-mg Nov 30, 2020
67c6bd1
Merge branch 'master' of github.com:yon-mg/gapic-generator-python
yon-mg Nov 30, 2020
37e3d28
fix: camel_case bug with constant case
yon-mg Nov 30, 2020
c964fba
fix: to_camel_case to produce lower camel case instead of PascalCase …
yon-mg Dec 1, 2020
85be88d
fix: addressing pr comments
yon-mg Dec 3, 2020
5d1c6a3
fix: adding appropriate todos, addressing comments
yon-mg Dec 4, 2020
f6c64cc
fix: dataclass dependency issue
yon-mg Dec 8, 2020
a4f34e7
Update wrappers.py
software-dov Dec 8, 2020
df8124b
Merge remote-tracking branch 'upstream/master'
yon-mg Dec 18, 2020
3715876
Merge branch 'master' of github.com:yon-mg/gapic-generator-python
yon-mg Dec 18, 2020
872e01d
fix: updating testing, rest-only generation, & minor bug-fixes
yon-mg Dec 18, 2020
0f8a903
test: test async client generation
yon-mg Dec 21, 2020
cc5ae23
fix: fixed reserved keyword bug, fixed bugs in gapic tests
yon-mg Dec 22, 2020
34b4b5d
fix: reverted bug causing change to , refactored template tests
yon-mg Dec 23, 2020
06bfd2e
fix: return type mismatch
yon-mg Dec 23, 2020
53771e9
fix: reserved keyword issue in
yon-mg Dec 23, 2020
85a983d
fix: replace bad regex checks with checks against field_pb type
yon-mg Dec 28, 2020
638a639
Update gapic/templates/noxfile.py.j2
yon-mg Dec 30, 2020
7058f62
Merge branch 'master' into master
yon-mg Dec 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions gapic/generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ def _render_template(
or
('transport' in template_name
and not self._is_desired_transport(template_name, opts))
or
# TODO(yon-mg) - remove when rest async implementation resolved
# temporarily stop async client gen while rest async is unkown
('async' in template_name and 'grpc' not in opts.transport)
):
continue

Expand Down
3 changes: 2 additions & 1 deletion gapic/schema/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@ def get_field(self, *field_path: str,
collisions = collisions or self.meta.address.collisions

# Get the first field in the path.
cursor = self.fields[field_path[0]]
first_field = field_path[0]
cursor = self.fields[first_field+('_' if first_field in utils.RESERVED_NAMES else '')]

# Base case: If this is the last field in the path, return it outright.
if len(field_path) == 1:
Expand Down
4 changes: 4 additions & 0 deletions gapic/templates/%namespace/%name/__init__.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ from {% if api.naming.module_namespace %}{{ api.naming.module_namespace|join('.'
if service.meta.address.subpackage == api.subpackage_view -%}
from {% if api.naming.module_namespace %}{{ api.naming.module_namespace|join('.') }}.{% endif -%}
{{ api.naming.versioned_module_name }}.services.{{ service.name|snake_case }}.client import {{ service.client_name }}
{%- if 'grpc' in opts.transport %}
from {% if api.naming.module_namespace %}{{ api.naming.module_namespace|join('.') }}.{% endif -%}
{{ api.naming.versioned_module_name }}.services.{{ service.name|snake_case }}.async_client import {{ service.async_client_name }}
{%- endif %}
{% endfor -%}

{# Import messages and enums from each proto.
Expand Down Expand Up @@ -50,7 +52,9 @@ __all__ = (
{% for service in api.services.values()|sort(attribute='name')
if service.meta.address.subpackage == api.subpackage_view -%}
'{{ service.client_name }}',
{%- if 'grpc' in opts.transport %}
'{{ service.async_client_name }}',
{%- endif %}
{% endfor -%}
{% for proto in api.protos.values()|sort(attribute='module_name')
if proto.meta.address.subpackage == api.subpackage_view -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

{% block content %}
from .client import {{ service.client_name }}
{%- if 'grpc' in opts.transport %}
from .async_client import {{ service.async_client_name }}
{%- endif %}

__all__ = (
'{{ service.client_name }}',
{%- if 'grpc' in opts.transport %}
'{{ service.async_client_name }}',
{%- endif %}
)
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ class {{ service.name }}RestTransport({{ service.name }}Transport):
Generally, you only need to set this if you're developing
your own client library.
"""
super().__init__(host=host, credentials=credentials)
# Run the base constructor
# TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc.
super().__init__(
host=host,
credentials=credentials,
client_info=client_info,
)
self._session = AuthorizedSession(self._credentials)
{%- if service.has_lro %}
self._operations_client = None
Expand Down Expand Up @@ -180,10 +186,8 @@ class {{ service.name }}RestTransport({{ service.name }}Transport):
# TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here
# discards default values
# TODO(yon-mg): add test for proper url encoded strings
query_params = ((k, v) for k, v in query_params.items() if v)
for i, (param_name, param_value) in enumerate(query_params):
q = '?' if i == 0 else '&'
url += "{q}{name}={value}".format(q=q, name=param_name, value=param_value.replace(' ', '+'))
query_params = ['{k}={v}'.format(k=k, v=v) for k, v in query_params.items() if v]
url += '?{}'.format('&'.join(query_params)).replace(' ', '+')
Comment on lines +189 to +190
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be easier to use urllib.parse.urlencode here (It will create the k=v structure and glue the pairs together with & characters).

https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlencode
https://docs.python.org/3/library/urllib.request.html#urllib-examples

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how I missed this. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, I'll leave this out for now so I don't accidentally break anything but I'll update in the subsequent PR


# Send the request
{% if not method.void %}response = {% endif %}self._session.{{ method.http_opt['verb'] }}(
Expand Down
Loading