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

feat: adds support for MixIns. #1240

Merged
merged 29 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f61cfb4
feat: adds starter code for mixins.
atulep Mar 17, 2022
21441d0
Merge branch 'main' into mixins
atulep Mar 17, 2022
b993847
chore: fixes some bugs and adds mixins to async client.
atulep Mar 18, 2022
38781ce
chore: increases coverage in templates.
atulep Mar 21, 2022
039b35d
chore: fixes bugs.
atulep Mar 21, 2022
3894b82
chore: fix some tests.
atulep Mar 21, 2022
3b82548
chore: adds tests.
atulep Mar 22, 2022
e4dba51
chore: runs formatter.
atulep Mar 22, 2022
4587109
chore: fixes coverage.
atulep Mar 23, 2022
7a2cc89
chore: fixes tests.
atulep Mar 23, 2022
8059123
chore: fixes mypy.
atulep Mar 23, 2022
c625994
feat: adds iam overrides check.
atulep Mar 24, 2022
aed677c
feat: adds code to ads.
atulep Mar 24, 2022
508fc81
chore: remove print statement.
atulep Mar 24, 2022
1530958
fix: fixes path.
atulep Mar 24, 2022
285c110
chore: remove lro mixin, adds TODO comments.
atulep Mar 31, 2022
baa02a9
chore: address pr feedback.
atulep Apr 6, 2022
e1c7101
Merge branch 'master' into mixins
atulep Apr 7, 2022
3b2400f
chore: fix stylecheck.
atulep Apr 7, 2022
fdba35f
feat: adds mixins ci checks.
atulep Apr 7, 2022
87c73e6
chore: fix bug.
atulep Apr 7, 2022
0cd3440
chore: fix bug.
atulep Apr 7, 2022
c9c7ae0
chore: fix another bug.
atulep Apr 7, 2022
b05e530
chore: fix bugs.
atulep Apr 7, 2022
304f800
chore: more bugs..
atulep Apr 7, 2022
9483f59
chore: bugsss.
atulep Apr 7, 2022
3be4886
chore: bugs..
atulep Apr 7, 2022
aa08353
chore: update golds.
atulep Apr 8, 2022
a73f2d6
Merge branch 'main' into mixins
atulep Apr 8, 2022
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: 3 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,12 @@ jobs:
strategy:
matrix:
python: ["3.6", "3.7", "3.8", "3.9", "3.10"]
variant: ['', _alternative_templates]
variant: ['', _alternative_templates, _mixins, _alternative_templates_mixins]
exclude:
- python: "3.6"
variant: _alternative_templates
- python: "3.6"
variant: _alternative_templates_mixins
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ py_binary(
requirement("MarkupSafe"),
requirement("pypandoc"),
requirement("PyYAML"),
requirement("grpc-google-iam-v1"),
] + select({
":gapic_gen_python_3_6": [requirement("dataclasses")],
"//conditions:default": [],
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ except AttributeError: # pragma: NO COVER
{{ ref_type.ident.python_import }}
{% endfor %}
{% endfor %}
{% if opts.add_iam_methods %}
{% if opts.add_iam_methods or api.has_iam_mixin %}
from google.iam.v1 import iam_policy_pb2 # type: ignore
from google.iam.v1 import policy_pb2 # type: ignore
{% endif %}
{% if api.has_location_mixin %}
from google.cloud.location import locations_pb2 # type: ignore
{% endif %}
{% endfilter %}
from .transports.base import {{ service.name }}Transport, DEFAULT_CLIENT_INFO
{% if 'grpc' in opts.transport %}
Expand Down Expand Up @@ -498,6 +501,9 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
{{ "\n" }}
{% endfor %}

{% include '%namespace/%name/%version/%sub/services/%service/_mixins.py.j2' %}

{# TODO: Remove after https://github.com/googleapis/gapic-generator-python/pull/1240 is merged. #}
{% if opts.add_iam_methods %}
def set_iam_policy(
self,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
{% if "grpc" in opts.transport %}

{% if api.has_location_mixin %}

{% if "ListLocations" in api.mixin_api_methods %}
@property
def list_locations(
self,
) -> Callable[[locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse]:
r"""Return a callable for the list locations method over gRPC.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "list_locations" not in self._stubs:
self._stubs["list_locations"] = self.grpc_channel.unary_unary(
"/google.cloud.location.Locations/ListLocations",
request_serializer=locations_pb2.ListLocationsRequest.SerializeToString,
response_deserializer=locations_pb2.ListLocationsResponse.FromString,
)
return self._stubs["list_locations"]
{% endif %}

{% if "GetLocation" in api.mixin_api_methods %}
@property
def get_location(
self,
) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]:
r"""Return a callable for the list locations method over gRPC.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "get_location" not in self._stubs:
self._stubs["get_location"] = self.grpc_channel.unary_unary(
"/google.cloud.location.Locations/GetLocation",
request_serializer=locations_pb2.GetLocationRequest.SerializeToString,
response_deserializer=locations_pb2.Location.FromString,
)
return self._stubs["get_location"]
{% endif %}

{% endif %} {# Location #}

{# TODO: Remove after https://github.com/googleapis/gapic-generator-python/pull/1240 is merged. #}
{% if not opts.add_iam_methods and api.has_iam_mixin %}

{% if "SetIamPolicy" in api.mixin_api_methods %}
@property
def set_iam_policy(
self,
) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]:
r"""Return a callable for the set iam policy method over gRPC.
Sets the IAM access control policy on the specified
function. Replaces any existing policy.
Returns:
Callable[[~.SetIamPolicyRequest],
~.Policy]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "set_iam_policy" not in self._stubs:
self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary(
"/google.iam.v1.IAMPolicy/SetIamPolicy",
request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString,
response_deserializer=policy_pb2.Policy.FromString,
)
return self._stubs["set_iam_policy"]
{% endif %}

{% if "GetIamPolicy" in api.mixin_api_methods %}
@property
def get_iam_policy(
self,
) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]:
r"""Return a callable for the get iam policy method over gRPC.
Gets the IAM access control policy for a function.
Returns an empty policy if the function exists and does
not have a policy set.
Returns:
Callable[[~.GetIamPolicyRequest],
~.Policy]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "get_iam_policy" not in self._stubs:
self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary(
"/google.iam.v1.IAMPolicy/GetIamPolicy",
request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString,
response_deserializer=policy_pb2.Policy.FromString,
)
return self._stubs["get_iam_policy"]
{% endif %}

{% if "TestIamPermissions" in api.mixin_api_methods %}
@property
def test_iam_permissions(
self,
) -> Callable[
[iam_policy_pb2.TestIamPermissionsRequest], iam_policy_pb2.TestIamPermissionsResponse
]:
r"""Return a callable for the test iam permissions method over gRPC.
Tests the specified permissions against the IAM access control
policy for a function. If the function does not exist, this will
return an empty set of permissions, not a NOT_FOUND error.
Returns:
Callable[[~.TestIamPermissionsRequest],
~.TestIamPermissionsResponse]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "test_iam_permissions" not in self._stubs:
self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary(
"/google.iam.v1.IAMPolicy/TestIamPermissions",
request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString,
response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString,
)
return self._stubs["test_iam_permissions"]
{% endif %}
{% endif %} {# IAM #}

{% endif %} {# grpc is transport #}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ from google.oauth2 import service_account # type: ignore
{{ method.input.ident.python_import }}
{{ method.output.ident.python_import }}
{% endfor %}
{% if opts.add_iam_methods %}
{% if opts.add_iam_methods or api.has_iam_mixin %}
from google.iam.v1 import iam_policy_pb2 # type: ignore
from google.iam.v1 import policy_pb2 # type: ignore
{% endif %}
{% if api.has_location_mixin %}
from google.cloud.location import locations_pb2 # type: ignore
{% endif %}
{% endfilter %}

try:
Expand Down Expand Up @@ -169,7 +172,68 @@ class {{ service.name }}Transport(abc.ABC):
raise NotImplementedError()
{% endfor %}

{# TODO: Remove after https://github.com/googleapis/gapic-generator-python/pull/1240 is merged. #}
{% if not opts.add_iam_methods and api.has_iam_mixin %}
{% if "SetIamPolicy" in api.mixin_api_methods %}
@property
def set_iam_policy(
self,
) -> Callable[
[iam_policy_pb2.SetIamPolicyRequest],
Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]],
]:
raise NotImplementedError()
{% endif %}

{% if "GetIamPolicy" in api.mixin_api_methods %}
@property
def get_iam_policy(
self,
) -> Callable[
[iam_policy_pb2.GetIamPolicyRequest],
Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]],
]:
raise NotImplementedError()
{% endif %}

{% if "TestIamPermissions" in api.mixin_api_methods %}
@property
def test_iam_permissions(
self,
) -> Callable[
[iam_policy_pb2.TestIamPermissionsRequest],
Union[
iam_policy_pb2.TestIamPermissionsResponse,
Awaitable[iam_policy_pb2.TestIamPermissionsResponse],
],
]:
raise NotImplementedError()
{% endif %}
{% endif %}

{% if api.has_location_mixin %}
{% if "GetLocation" in api.mixin_api_methods %}
@property
def get_location(self,
) -> Callable[
[locations_pb2.GetLocationRequest],
Union[locations_pb2.Location, Awaitable[locations_pb2.Location]],
]:
raise NotImplementedError()
{% endif %}

{% if "ListLocations" in api.mixin_api_methods %}
@property
def list_locations(self,
) -> Callable[
[locations_pb2.ListLocationsRequest],
Union[locations_pb2.ListLocationsResponse, Awaitable[locations_pb2.ListLocationsResponse]],
]:
raise NotImplementedError()
{% endif %}
{% endif %}

{# TODO: Remove after https://github.com/googleapis/gapic-generator-python/pull/1240 is merged. #}
{% if opts.add_iam_methods %}
@property
def set_iam_policy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ import grpc # type: ignore
{{ method.input.ident.python_import }}
{{ method.output.ident.python_import }}
{% endfor %}
{% if opts.add_iam_methods %}
{% if opts.add_iam_methods or api.has_iam_mixin %}
from google.iam.v1 import iam_policy_pb2 # type: ignore
from google.iam.v1 import policy_pb2 # type: ignore
{% endif %}
{% if api.has_location_mixin %}
from google.cloud.location import locations_pb2 # type: ignore
{% endif %}
{% endfilter %}
from .base import {{ service.name }}Transport, DEFAULT_CLIENT_INFO

Expand Down Expand Up @@ -278,6 +281,7 @@ class {{ service.name }}GrpcTransport({{ service.name }}Transport):
return self._stubs['{{ method.transport_safe_name|snake_case }}']
{% endfor %}

{# TODO: Remove after https://github.com/googleapis/gapic-generator-python/pull/1240 is merged. #}
{% if opts.add_iam_methods %}
@property
def set_iam_policy(
Expand Down Expand Up @@ -362,6 +366,8 @@ class {{ service.name }}GrpcTransport({{ service.name }}Transport):
def close(self):
self.grpc_channel.close()

{% include '%namespace/%name/%version/%sub/services/%service/transports/_mixins.py.j2' %}

__all__ = (
'{{ service.name }}GrpcTransport',
)
Expand Down
Loading