diff --git a/CHANGELOG.md b/CHANGELOG.md index 00fde0c8d8..74f499bd5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +### [0.46.2](https://www.github.com/googleapis/gapic-generator-python/compare/v0.46.1...v0.46.2) (2021-05-12) + + +### Bug Fixes + +* fix incorrectly referenced exceptions, add missing port to tests ([#873](https://www.github.com/googleapis/gapic-generator-python/issues/873)) ([40078c4](https://www.github.com/googleapis/gapic-generator-python/commit/40078c46b21a0dfa489d4cd80ed7d95bb542f3c3)), closes [#872](https://www.github.com/googleapis/gapic-generator-python/issues/872) + ### [0.46.1](https://www.github.com/googleapis/gapic-generator-python/compare/v0.46.0...v0.46.1) (2021-05-07) diff --git a/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/transports/base.py.j2 b/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/transports/base.py.j2 index d630c8f023..82ab146438 100644 --- a/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/transports/base.py.j2 +++ b/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/transports/base.py.j2 @@ -91,7 +91,7 @@ class {{ service.name }}Transport(metaclass=abc.ABCMeta): {% if method.retry.backoff_multiplier %}multiplier={{ method.retry.backoff_multiplier }},{% endif %} predicate=retries.if_exception_type( {% for ex in method.retry.retryable_exceptions|sort(attribute='__name__') %} - exceptions.{{ ex.__name__ }}, + core_exceptions.{{ ex.__name__ }}, {% endfor %} ), deadline={{ method.timeout }}, diff --git a/gapic/generator/generator.py b/gapic/generator/generator.py index 362753ff2d..3014719c17 100644 --- a/gapic/generator/generator.py +++ b/gapic/generator/generator.py @@ -89,7 +89,7 @@ def get_response( sample_templates, client_templates = utils.partition( lambda fname: os.path.basename( fname) == samplegen.DEFAULT_TEMPLATE_NAME, - self._env.loader.list_templates(), + self._env.loader.list_templates(), # type: ignore ) # Iterate over each template and add the appropriate output files @@ -113,7 +113,7 @@ def get_response( sample_output = self._generate_samples_and_manifest( api_schema, self._env.get_template(sample_templates[0]), opts=opts, - ) + ) output_files.update(sample_output) # Return the CodeGeneratorResponse output. @@ -286,10 +286,10 @@ def _render_template( for service in api_schema.services.values(): if ( (skip_subpackages - and service.meta.address.subpackage != api_schema.subpackage_view) + and service.meta.address.subpackage != api_schema.subpackage_view) or ('transport' in template_name - and not self._is_desired_transport(template_name, opts)) + 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 diff --git a/gapic/schema/metadata.py b/gapic/schema/metadata.py index e14190d007..91e6905777 100644 --- a/gapic/schema/metadata.py +++ b/gapic/schema/metadata.py @@ -84,17 +84,17 @@ def __str__(self) -> str: if self.module: module_name = self.module + # If collisions are registered and conflict with our module, + # use the module alias instead. + if self.module_alias: + module_name = self.module_alias + # This module is from a different proto package # Most commonly happens for a common proto # https://pypi.org/project/googleapis-common-protos/ if not self.proto_package.startswith(self.api_naming.proto_package): module_name = f'{self.module}_pb2' - # If collisions are registered and conflict with our module, - # use the module alias instead. - if self.module_alias: - module_name = self.module_alias - # Return the dot-separated Python identifier. return '.'.join((module_name,) + self.parent + (self.name,)) diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 index f5d60d8e60..3c5988073c 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 @@ -253,7 +253,7 @@ class {{ service.async_client_name }}: {% if method.retry.backoff_multiplier %}multiplier={{ method.retry.backoff_multiplier }},{% endif %} predicate=retries.if_exception_type( {% for ex in method.retry.retryable_exceptions|sort(attribute="__name__") %} - exceptions.{{ ex.__name__ }}, + core_exceptions.{{ ex.__name__ }}, {% endfor %} ), deadline={{ method.timeout }}, diff --git a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 index 3227b7b340..f6ef2fba9b 100644 --- a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 +++ b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 @@ -1665,7 +1665,7 @@ def test_{{ service.name|snake_case }}_transport_create_channel_old_api_core(tra {% with host = (service.host|default('localhost', true)) %} create_channel.assert_called_with( - "{{ host }}", + "{{ host }}{% if ":" not in service.host %}:443{% endif %}", credentials=creds, credentials_file=None, quota_project_id="octopus", @@ -1703,7 +1703,7 @@ def test_{{ service.name|snake_case }}_transport_create_channel_user_scopes(tran transport_class(quota_project_id="octopus", scopes=["1", "2"]) create_channel.assert_called_with( - "{{ host }}", + "{{ host }}{% if ":" not in service.host %}:443{% endif %}", credentials=creds, credentials_file=None, quota_project_id="octopus", diff --git a/requirements.txt b/requirements.txt index 43ad012986..ee93fbbd14 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,8 @@ -click==7.1.2 +click==8.0.0 google-api-core==1.26.3 googleapis-common-protos==1.53.0 -jinja2==2.11.3 -MarkupSafe==1.1.1 +jinja2==3.0.0 +MarkupSafe==2.0.0 protobuf==3.16.0 pypandoc==1.5 PyYAML==5.4.1 diff --git a/tests/unit/schema/test_metadata.py b/tests/unit/schema/test_metadata.py index c778000c7c..179361e039 100644 --- a/tests/unit/schema/test_metadata.py +++ b/tests/unit/schema/test_metadata.py @@ -49,6 +49,17 @@ def test_address_str_different_proto_package(): assert str(addr) == 'options_pb2.GetPolicyOptions' +def test_address_str_different_proto_package_with_collision(): + addr = metadata.Address( + package=('google', 'rpc'), + module='status', + name='Status', + api_naming=naming.NewNaming(proto_package='foo.bar.baz.v1') + ).with_context(collisions=frozenset({'status'})) + # the module alias should be ignored for _pb2 types + assert str(addr) == 'status_pb2.Status' + + def test_address_proto(): addr = metadata.Address(package=('foo', 'bar'), module='baz', name='Bacon') assert addr.proto == 'foo.bar.Bacon'