Skip to content

Commit 231da46

Browse files
authored
fix: remove duplicate import statement for google.longrunning.operations_pb2 (#1726)
Fixes #1727 🦕
1 parent b4146db commit 231da46

23 files changed

Lines changed: 52 additions & 21 deletions

File tree

packages/gapic-generator/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/transports/base.py.j2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ from google.auth import credentials as ga_credentials # type: ignore
1818
from google.oauth2 import service_account # type: ignore
1919

2020
{% filter sort_lines %}
21+
{% set import_ns = namespace(has_operations_mixin=false) %}
2122
{% for method in service.methods.values() %}
2223
{{ method.input.ident.python_import }}
24+
{% if method.output.ident|string() == "operations_pb2.Operation" %}
25+
{% set import_ns.has_operations_mixin = True %}
26+
{% else %}
2327
{{ method.output.ident.python_import }}
28+
{% endif %}
2429
{% endfor %}
2530
{% if opts.add_iam_methods or api.has_iam_mixin %}
2631
from google.iam.v1 import iam_policy_pb2 # type: ignore
@@ -30,6 +35,9 @@ from google.iam.v1 import policy_pb2 # type: ignore
3035
from google.cloud.location import locations_pb2 # type: ignore
3136
{% endif %}
3237
{% if api.has_operations_mixin %}
38+
{% set import_ns.has_operations_mixin = True %}
39+
{% endif %}
40+
{% if import_ns.has_operations_mixin %}
3341
from google.longrunning import operations_pb2 # type: ignore
3442
{% endif %}
3543
{% endfilter %}

packages/gapic-generator/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/transports/grpc.py.j2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ from google.auth.transport.grpc import SslCredentials # type: ignore
1717
import grpc # type: ignore
1818

1919
{% filter sort_lines %}
20+
{% set import_ns = namespace(has_operations_mixin=false) %}
2021
{% for method in service.methods.values() %}
2122
{{ method.input.ident.python_import }}
23+
{% if method.output.ident|string() == "operations_pb2.Operation" %}
24+
{% set import_ns.has_operations_mixin = True %}
25+
{% else %}
2226
{{ method.output.ident.python_import }}
27+
{% endif %}
2328
{% endfor %}
2429
{% if opts.add_iam_methods or api.has_iam_mixin %}
2530
from google.iam.v1 import iam_policy_pb2 # type: ignore
@@ -29,6 +34,9 @@ from google.iam.v1 import policy_pb2 # type: ignore
2934
from google.cloud.location import locations_pb2 # type: ignore
3035
{% endif %}
3136
{% if api.has_operations_mixin %}
37+
{% set import_ns.has_operations_mixin = True %}
38+
{% endif %}
39+
{% if import_ns.has_operations_mixin %}
3240
from google.longrunning import operations_pb2 # type: ignore
3341
{% endif %}
3442
{% endfilter %}

packages/gapic-generator/gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,11 @@ from google.api_core import path_template
4444
from google.api_core import future
4545
from google.api_core import operation
4646
from google.api_core import operations_v1
47-
from google.longrunning import operations_pb2 # type: ignore
4847
{% endif %}{# lro #}
4948
{% if api.has_location_mixin %}
5049
from google.cloud.location import locations_pb2
5150
{% endif %}
52-
{% if api.has_operations_mixin %}
51+
{% if api.has_operations_mixin or service.has_lro %}
5352
from google.longrunning import operations_pb2 # type: ignore
5453
{% endif %}
5554
from google.api_core import gapic_v1

packages/gapic-generator/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/base.py.j2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ from google.auth import credentials as ga_credentials # type: ignore
2020
from google.oauth2 import service_account # type: ignore
2121

2222
{% filter sort_lines %}
23+
{% set import_ns = namespace(has_operations_mixin=false) %}
2324
{% for method in service.methods.values() %}
2425
{{ method.input.ident.python_import }}
26+
{% if method.output.ident|string() == "operations_pb2.Operation" %}
27+
{% set import_ns.has_operations_mixin = True %}
28+
{% else %}
2529
{{ method.output.ident.python_import }}
30+
{% endif %}
2631
{% endfor %}
2732
{% if opts.add_iam_methods or api.has_iam_mixin %}
2833
from google.iam.v1 import iam_policy_pb2 # type: ignore
@@ -32,6 +37,9 @@ from google.iam.v1 import policy_pb2 # type: ignore
3237
from google.cloud.location import locations_pb2 # type: ignore
3338
{% endif %}
3439
{% if api.has_operations_mixin %}
40+
{% set import_ns.has_operations_mixin = True %}
41+
{% endif %}
42+
{% if import_ns.has_operations_mixin %}
3543
from google.longrunning import operations_pb2 # type: ignore
3644
{% endif %}
3745
{% endfilter %}

packages/gapic-generator/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/grpc.py.j2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ from google.auth.transport.grpc import SslCredentials # type: ignore
1717
import grpc # type: ignore
1818

1919
{% filter sort_lines %}
20+
{% set import_ns = namespace(has_operations_mixin=false) %}
2021
{% for method in service.methods.values() %}
2122
{{ method.input.ident.python_import }}
23+
{% if method.output.ident|string() == "operations_pb2.Operation" %}
24+
{% set import_ns.has_operations_mixin = True %}
25+
{% else %}
2226
{{ method.output.ident.python_import }}
27+
{% endif %}
2328
{% endfor %}
2429
{% if opts.add_iam_methods or api.has_iam_mixin %}
2530
from google.iam.v1 import iam_policy_pb2 # type: ignore
@@ -29,6 +34,9 @@ from google.iam.v1 import policy_pb2 # type: ignore
2934
from google.cloud.location import locations_pb2 # type: ignore
3035
{% endif %}
3136
{% if api.has_operations_mixin %}
37+
{% set import_ns.has_operations_mixin = True %}
38+
{% endif %}
39+
{% if import_ns.has_operations_mixin %}
3240
from google.longrunning import operations_pb2 # type: ignore
3341
{% endif %}
3442
{% endfilter %}

packages/gapic-generator/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/grpc_asyncio.py.j2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ import grpc # type: ignore
1717
from grpc.experimental import aio # type: ignore
1818

1919
{% filter sort_lines %}
20+
{% set import_ns = namespace(has_operations_mixin=false) %}
2021
{% for method in service.methods.values() %}
2122
{{ method.input.ident.python_import }}
23+
{% if method.output.ident|string() == "operations_pb2.Operation" %}
24+
{% set import_ns.has_operations_mixin = True %}
25+
{% else %}
2226
{{ method.output.ident.python_import }}
27+
{% endif %}
2328
{% endfor %}
2429
{% if opts.add_iam_methods or api.has_iam_mixin %}
2530
from google.iam.v1 import iam_policy_pb2 # type: ignore
@@ -29,6 +34,9 @@ from google.iam.v1 import policy_pb2 # type: ignore
2934
from google.cloud.location import locations_pb2 # type: ignore
3035
{% endif %}
3136
{% if api.has_operations_mixin %}
37+
{% set import_ns.has_operations_mixin = True %}
38+
{% endif %}
39+
{% if import_ns.has_operations_mixin %}
3240
from google.longrunning import operations_pb2 # type: ignore
3341
{% endif %}
3442
{% endfilter %}

packages/gapic-generator/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ from google.iam.v1 import policy_pb2 # type: ignore
2626
{% if api.has_location_mixin %}
2727
from google.cloud.location import locations_pb2 # type: ignore
2828
{% endif %}
29+
{% set import_ns = namespace(has_operations_mixin=false) %}
2930
{% if api.has_operations_mixin %}
30-
from google.longrunning import operations_pb2 # type: ignore
31+
{% set import_ns.has_operations_mixin = True %}
3132
{% endif %}
3233
from requests import __version__ as requests_version
3334
import dataclasses
@@ -45,13 +46,20 @@ except AttributeError: # pragma: NO COVER
4546
{% filter sort_lines %}
4647
{% for method in service.methods.values() %}
4748
{{method.input.ident.python_import}}
49+
{% if method.output.ident|string() == "operations_pb2.Operation" %}
50+
{% set import_ns.has_operations_mixin = True %}
51+
{% else %}
4852
{{method.output.ident.python_import}}
53+
{% endif %}
4954
{% endfor %}
5055
{% if opts.add_iam_methods %}
5156
from google.iam.v1 import iam_policy_pb2 # type: ignore
5257
from google.iam.v1 import policy_pb2 # type: ignore
5358
{% endif %}
5459
{% endfilter %}
60+
{% if import_ns.has_operations_mixin %}
61+
from google.longrunning import operations_pb2 # type: ignore
62+
{% endif %}
5563

5664
from .base import {{service.name}}Transport, DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO
5765

packages/gapic-generator/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,11 @@ from google.api_core import future
5252
{% if service.has_lro %}
5353
from google.api_core import operation
5454
from google.api_core import operations_v1
55-
from google.longrunning import operations_pb2 # type: ignore
5655
{% endif %}{# lro #}
5756
{% if api.has_location_mixin %}
5857
from google.cloud.location import locations_pb2
5958
{% endif %}
60-
{% if api.has_operations_mixin %}
59+
{% if api.has_operations_mixin or service.has_lro %}
6160
from google.longrunning import operations_pb2 # type: ignore
6261
{% endif %}
6362
from google.api_core import gapic_v1

packages/gapic-generator/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from google.oauth2 import service_account # type: ignore
2929

3030
from google.cloud.asset_v1.types import asset_service
31-
from google.longrunning import operations_pb2 # type: ignore
3231
from google.longrunning import operations_pb2 # type: ignore
3332
from google.protobuf import empty_pb2 # type: ignore
3433

packages/gapic-generator/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/grpc.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import grpc # type: ignore
2727

2828
from google.cloud.asset_v1.types import asset_service
29-
from google.longrunning import operations_pb2 # type: ignore
3029
from google.longrunning import operations_pb2 # type: ignore
3130
from google.protobuf import empty_pb2 # type: ignore
3231
from .base import AssetServiceTransport, DEFAULT_CLIENT_INFO

0 commit comments

Comments
 (0)