From e669129d930e10a368f3811ce8ebd0d88cb2f30a Mon Sep 17 00:00:00 2001 From: acocuzzo Date: Wed, 21 Sep 2022 11:12:22 -0400 Subject: [PATCH 01/25] (feat): Add grpc Compression argument --- google/api_core/gapic_v1/method.py | 21 +++++++++------ google/api_core/gapic_v1/method_async.py | 3 ++- .../operations_v1/operations_async_client.py | 24 ++++++++++++++--- .../operations_v1/operations_client.py | 24 ++++++++++++++--- .../api_core/operations_v1/transports/base.py | 4 +++ tests/asyncio/gapic/test_method_async.py | 26 +++++++++++++++++++ tests/unit/gapic/test_method.py | 25 ++++++++++++++++++ 7 files changed, 110 insertions(+), 17 deletions(-) diff --git a/google/api_core/gapic_v1/method.py b/google/api_core/gapic_v1/method.py index 73c8d4bc..546b1a8a 100644 --- a/google/api_core/gapic_v1/method.py +++ b/google/api_core/gapic_v1/method.py @@ -38,7 +38,7 @@ class _MethodDefault(enum.Enum): DEFAULT = _MethodDefault._DEFAULT_VALUE -"""Sentinel value indicating that a retry or timeout argument was unspecified, +"""Sentinel value indicating that a retry, timeout, or compression argument was unspecified, so the default should be used.""" @@ -115,15 +115,17 @@ class _GapicCallable(object): provided to the RPC method on every invocation. This is merged with any metadata specified during invocation. If ``None``, no additional metadata will be passed to the RPC method. + compression (grpc.Compression): Indicates the compression method to be used for an RPC. """ - def __init__(self, target, retry, timeout, metadata=None): + def __init__(self, target, retry, timeout, metadata=None, compression=None): self._target = target self._retry = retry self._timeout = timeout self._metadata = metadata + self._compression = compression - def __call__(self, *args, timeout=DEFAULT, retry=DEFAULT, **kwargs): + def __call__(self, *args, timeout=DEFAULT, retry=DEFAULT, compression=DEFAULT, **kwargs): """Invoke the low-level RPC with retry, timeout, and metadata.""" timeout = _determine_timeout( self._timeout, @@ -138,7 +140,7 @@ def __call__(self, *args, timeout=DEFAULT, retry=DEFAULT, **kwargs): retry = self._retry # Apply all applicable decorators. - wrapped_func = _apply_decorators(self._target, [retry, timeout]) + wrapped_func = _apply_decorators(self._target, [retry, timeout, compression]) # Add the user agent metadata to the call. if self._metadata is not None: @@ -158,12 +160,13 @@ def wrap_method( func, default_retry=None, default_timeout=None, - client_info=client_info.DEFAULT_CLIENT_INFO, + default_compression=None, + client_info=client_info.DEFAULT_CLIENT_INFO ): """Wrap an RPC method with common behavior. - This applies common error wrapping, retry, and timeout behavior a function. - The wrapped function will take optional ``retry`` and ``timeout`` + This applies common error wrapping, retry, timeout, and compression behavior a function. + The wrapped function will take optional ``retry``, ``timeout``, and ``compression`` arguments. For example:: @@ -227,6 +230,8 @@ def get_topic(name, timeout=None): default_timeout (Optional[google.api_core.Timeout]): The default timeout strategy. Can also be specified as an int or float. If ``None``, the method will not have timeout specified by default. + default_compression (Optional[grpc.Compression]): The default + grpc.Compression. client_info (Optional[google.api_core.gapic_v1.client_info.ClientInfo]): Client information used to create a user-agent string that's @@ -248,6 +253,6 @@ def get_topic(name, timeout=None): return functools.wraps(func)( _GapicCallable( - func, default_retry, default_timeout, metadata=user_agent_metadata + func, default_retry, default_timeout, metadata=user_agent_metadata, compression=default_compression ) ) diff --git a/google/api_core/gapic_v1/method_async.py b/google/api_core/gapic_v1/method_async.py index 84c99aa2..1d8be3a2 100644 --- a/google/api_core/gapic_v1/method_async.py +++ b/google/api_core/gapic_v1/method_async.py @@ -30,6 +30,7 @@ def wrap_method( func, default_retry=None, default_timeout=None, + default_compression=None, client_info=client_info.DEFAULT_CLIENT_INFO, ): """Wrap an async RPC method with common behavior. @@ -44,5 +45,5 @@ def wrap_method( metadata = [client_info.to_grpc_metadata()] if client_info is not None else None return functools.wraps(func)( - _GapicCallable(func, default_retry, default_timeout, metadata=metadata) + _GapicCallable(func, default_retry, default_timeout, default_compression, metadata=metadata) ) diff --git a/google/api_core/operations_v1/operations_async_client.py b/google/api_core/operations_v1/operations_async_client.py index 5a5e5562..00cbbf5e 100644 --- a/google/api_core/operations_v1/operations_async_client.py +++ b/google/api_core/operations_v1/operations_async_client.py @@ -56,24 +56,28 @@ def __init__(self, channel, client_config=operations_client_config.config): self.operations_stub.GetOperation, default_retry=method_configs["GetOperation"].retry, default_timeout=method_configs["GetOperation"].timeout, + default_compression=method_configs["GetOperation"].compression, ) self._list_operations = gapic_v1.method_async.wrap_method( self.operations_stub.ListOperations, default_retry=method_configs["ListOperations"].retry, default_timeout=method_configs["ListOperations"].timeout, + default_compression=method_configs["ListOperations"].compression, ) self._cancel_operation = gapic_v1.method_async.wrap_method( self.operations_stub.CancelOperation, default_retry=method_configs["CancelOperation"].retry, default_timeout=method_configs["CancelOperation"].timeout, + default_compression=method_configs["CancelOperation"].compression, ) self._delete_operation = gapic_v1.method_async.wrap_method( self.operations_stub.DeleteOperation, default_retry=method_configs["DeleteOperation"].retry, default_timeout=method_configs["DeleteOperation"].timeout, + default_compression=method_configs["DeleteOperation"].compression, ) async def get_operation( @@ -81,6 +85,7 @@ async def get_operation( name, retry=gapic_v1.method_async.DEFAULT, timeout=gapic_v1.method_async.DEFAULT, + compression=None, metadata=None, ): """Gets the latest state of a long-running operation. @@ -107,6 +112,8 @@ async def get_operation( unspecified, the the default timeout in the client configuration is used. If ``None``, then the RPC method will not time out. + compression (grpc.Compression): An element of grpc.compression + e.g. grpc.compression.Gzip. This is an EXPERIMENTAL option. metadata (Optional[List[Tuple[str, str]]]): Additional gRPC metadata. @@ -126,7 +133,7 @@ async def get_operation( metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name})) return await self._get_operation( - request, retry=retry, timeout=timeout, metadata=metadata + request, retry=retry, timeout=timeout, compression=compression, metadata=metadata ) async def list_operations( @@ -135,6 +142,7 @@ async def list_operations( filter_, retry=gapic_v1.method_async.DEFAULT, timeout=gapic_v1.method_async.DEFAULT, + compression=None, metadata=None, ): """ @@ -171,6 +179,8 @@ async def list_operations( unspecified, the the default timeout in the client configuration is used. If ``None``, then the RPC method will not time out. + compression (grpc.Compression): An element of grpc.compression + e.g. grpc.compression.Gzip. This is an EXPERIMENTAL option. metadata (Optional[List[Tuple[str, str]]]): Additional gRPC metadata. @@ -195,7 +205,7 @@ async def list_operations( # Create the method used to fetch pages method = functools.partial( - self._list_operations, retry=retry, timeout=timeout, metadata=metadata + self._list_operations, retry=retry, timeout=timeout, compression=compression, metadata=metadata ) iterator = page_iterator_async.AsyncGRPCIterator( @@ -214,6 +224,7 @@ async def cancel_operation( name, retry=gapic_v1.method_async.DEFAULT, timeout=gapic_v1.method_async.DEFAULT, + compression=None, metadata=None, ): """Starts asynchronous cancellation on a long-running operation. @@ -254,6 +265,8 @@ async def cancel_operation( google.api_core.exceptions.GoogleAPICallError: If an error occurred while invoking the RPC, the appropriate ``GoogleAPICallError`` subclass will be raised. + compression (grpc.Compression): An element of grpc.compression + e.g. grpc.compression.Gzip. This is an EXPERIMENTAL option. metadata (Optional[List[Tuple[str, str]]]): Additional gRPC metadata. """ @@ -265,7 +278,7 @@ async def cancel_operation( metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name})) await self._cancel_operation( - request, retry=retry, timeout=timeout, metadata=metadata + request, retry=retry, timeout=timeout, compression=compression, metadata=metadata ) async def delete_operation( @@ -273,6 +286,7 @@ async def delete_operation( name, retry=gapic_v1.method_async.DEFAULT, timeout=gapic_v1.method_async.DEFAULT, + compression=None, metadata=None, ): """Deletes a long-running operation. @@ -299,6 +313,8 @@ async def delete_operation( unspecified, the the default timeout in the client configuration is used. If ``None``, then the RPC method will not time out. + compression (grpc.Compression): An element of grpc.compression + e.g. grpc.compression.Gzip. This is an EXPERIMENTAL option. metadata (Optional[List[Tuple[str, str]]]): Additional gRPC metadata. @@ -318,5 +334,5 @@ async def delete_operation( metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name})) await self._delete_operation( - request, retry=retry, timeout=timeout, metadata=metadata + request, retry=retry, timeout=timeout, compression=compression, metadata=metadata ) diff --git a/google/api_core/operations_v1/operations_client.py b/google/api_core/operations_v1/operations_client.py index e48eac01..7a960f6a 100644 --- a/google/api_core/operations_v1/operations_client.py +++ b/google/api_core/operations_v1/operations_client.py @@ -69,24 +69,28 @@ def __init__(self, channel, client_config=operations_client_config.config): self.operations_stub.GetOperation, default_retry=method_configs["GetOperation"].retry, default_timeout=method_configs["GetOperation"].timeout, + default_compression=method_configs["GetOperation"].compression, ) self._list_operations = gapic_v1.method.wrap_method( self.operations_stub.ListOperations, default_retry=method_configs["ListOperations"].retry, default_timeout=method_configs["ListOperations"].timeout, + default_compression=method_configs["ListOperations"].compression, ) self._cancel_operation = gapic_v1.method.wrap_method( self.operations_stub.CancelOperation, default_retry=method_configs["CancelOperation"].retry, default_timeout=method_configs["CancelOperation"].timeout, + default_compression=method_configs["CancelOperation"].compression, ) self._delete_operation = gapic_v1.method.wrap_method( self.operations_stub.DeleteOperation, default_retry=method_configs["DeleteOperation"].retry, default_timeout=method_configs["DeleteOperation"].timeout, + default_compression=method_configs["DeleteOperation"].compression, ) # Service calls @@ -96,6 +100,7 @@ def get_operation( retry=gapic_v1.method.DEFAULT, timeout=gapic_v1.method.DEFAULT, metadata=None, + compression=None ): """Gets the latest state of a long-running operation. @@ -123,6 +128,8 @@ def get_operation( not time out. metadata (Optional[List[Tuple[str, str]]]): Additional gRPC metadata. + compression (grpc.Compression): An element of grpc.compression + e.g. grpc.compression.Gzip. This is an EXPERIMENTAL option. Returns: google.longrunning.operations_pb2.Operation: The state of the @@ -140,7 +147,7 @@ def get_operation( metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name})) return self._get_operation( - request, retry=retry, timeout=timeout, metadata=metadata + request, retry=retry, timeout=timeout, compression=compression, metadata=metadata ) def list_operations( @@ -150,6 +157,7 @@ def list_operations( retry=gapic_v1.method.DEFAULT, timeout=gapic_v1.method.DEFAULT, metadata=None, + compression=None ): """ Lists operations that match the specified filter in the request. @@ -187,6 +195,8 @@ def list_operations( not time out. metadata (Optional[List[Tuple[str, str]]]): Additional gRPC metadata. + compression (grpc.Compression): An element of grpc.compression + e.g. grpc.compression.Gzip. This is an EXPERIMENTAL option. Returns: google.api_core.page_iterator.Iterator: An iterator that yields @@ -209,7 +219,7 @@ def list_operations( # Create the method used to fetch pages method = functools.partial( - self._list_operations, retry=retry, timeout=timeout, metadata=metadata + self._list_operations, retry=retry, timeout=timeout, compression=compression, metadata=metadata ) iterator = page_iterator.GRPCIterator( @@ -229,6 +239,7 @@ def cancel_operation( retry=gapic_v1.method.DEFAULT, timeout=gapic_v1.method.DEFAULT, metadata=None, + compression=None ): """Starts asynchronous cancellation on a long-running operation. @@ -262,6 +273,8 @@ def cancel_operation( not time out. metadata (Optional[List[Tuple[str, str]]]): Additional gRPC metadata. + compression (grpc.Compression): An element of grpc.compression + e.g. grpc.compression.Gzip. This is an EXPERIMENTAL option. Raises: google.api_core.exceptions.MethodNotImplemented: If the server @@ -278,7 +291,7 @@ def cancel_operation( metadata = metadata or [] metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name})) - self._cancel_operation(request, retry=retry, timeout=timeout, metadata=metadata) + self._cancel_operation(request, retry=retry, timeout=timeout, compression=compression, metadata=metadata) def delete_operation( self, @@ -286,6 +299,7 @@ def delete_operation( retry=gapic_v1.method.DEFAULT, timeout=gapic_v1.method.DEFAULT, metadata=None, + compression=None ): """Deletes a long-running operation. @@ -313,6 +327,8 @@ def delete_operation( not time out. metadata (Optional[List[Tuple[str, str]]]): Additional gRPC metadata. + compression (grpc.Compression): An element of grpc.compression + e.g. grpc.compression.Gzip. This is an EXPERIMENTAL option. Raises: google.api_core.exceptions.MethodNotImplemented: If the server @@ -329,4 +345,4 @@ def delete_operation( metadata = metadata or [] metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name})) - self._delete_operation(request, retry=retry, timeout=timeout, metadata=metadata) + self._delete_operation(request, retry=retry, timeout=timeout, compression=compression, metadata=metadata) diff --git a/google/api_core/operations_v1/transports/base.py b/google/api_core/operations_v1/transports/base.py index e19bc3e8..e04c47aa 100644 --- a/google/api_core/operations_v1/transports/base.py +++ b/google/api_core/operations_v1/transports/base.py @@ -129,6 +129,7 @@ def _prep_wrapped_messages(self, client_info): deadline=10.0, ), default_timeout=10.0, + default_compression=None, client_info=client_info, ), self.get_operation: gapic_v1.method.wrap_method( @@ -143,6 +144,7 @@ def _prep_wrapped_messages(self, client_info): deadline=10.0, ), default_timeout=10.0, + default_compression=None, client_info=client_info, ), self.delete_operation: gapic_v1.method.wrap_method( @@ -157,6 +159,7 @@ def _prep_wrapped_messages(self, client_info): deadline=10.0, ), default_timeout=10.0, + default_compression=None, client_info=client_info, ), self.cancel_operation: gapic_v1.method.wrap_method( @@ -171,6 +174,7 @@ def _prep_wrapped_messages(self, client_info): deadline=10.0, ), default_timeout=10.0, + default_compression=None, client_info=client_info, ), } diff --git a/tests/asyncio/gapic/test_method_async.py b/tests/asyncio/gapic/test_method_async.py index 11847da7..c8a36aa9 100644 --- a/tests/asyncio/gapic/test_method_async.py +++ b/tests/asyncio/gapic/test_method_async.py @@ -19,6 +19,7 @@ try: from grpc import aio + from grpc import Compression except ImportError: pytest.skip("No GRPC", allow_module_level=True) @@ -92,6 +93,31 @@ async def test_wrap_method_with_custom_client_info(): assert client_info.to_grpc_metadata() in metadata +@pytest.mark.asyncio +async def test_wrap_method_with_no_compression(): + fake_call = grpc_helpers_async.FakeUnaryUnaryCall() + method = mock.Mock(spec=aio.UnaryUnaryMultiCallable, return_value=fake_call) + + wrapped_method = gapic_v1.method_async.wrap_method(method, compression=None) + + await wrapped_method(1, 2, meep="moop") + + method.assert_called_once_with(1, 2, meep="moop") + + +@pytest.mark.asyncio +async def test_wrap_method_with_custom_compression(): + compression = Compression.Gzip + fake_call = grpc_helpers_async.FakeUnaryUnaryCall() + method = mock.Mock(spec=aio.UnaryUnaryMultiCallable, return_value=fake_call) + + wrapped_method = gapic_v1.method_async.wrap_method(method, compression=compression) + + await wrapped_method(1, 2, meep="moop") + + method.assert_called_once_with(1, 2, meep="moop", compression=compression) + + @pytest.mark.asyncio async def test_invoke_wrapped_method_with_metadata(): fake_call = grpc_helpers_async.FakeUnaryUnaryCall() diff --git a/tests/unit/gapic/test_method.py b/tests/unit/gapic/test_method.py index 9778d23a..35672c12 100644 --- a/tests/unit/gapic/test_method.py +++ b/tests/unit/gapic/test_method.py @@ -113,6 +113,31 @@ def test_wrap_method_with_custom_client_info(): assert client_info.to_grpc_metadata() in metadata +def test_wrap_method_with_no_compression(): + method = mock.Mock(spec=["__call__"]) + + wrapped_method = google.api_core.gapic_v1.method.wrap_method( + method, compression=None + ) + + wrapped_method(1, 2, meep="moop") + + method.assert_called_once_with(1, 2, meep="moop") + + +def test_wrap_method_with_custom_client_info(): + compression = grpc.Compression.Gzip + method = mock.Mock(spec=["__call__"]) + + wrapped_method = google.api_core.gapic_v1.method.wrap_method( + method, compression=compression + ) + + wrapped_method(1, 2, meep="moop") + + method.assert_called_once_with(1, 2, meep="moop", compression=grpc.Compression.Gzip) + + def test_invoke_wrapped_method_with_metadata(): method = mock.Mock(spec=["__call__"]) From 9d06f0b9b3e8eaff76ba7195839696aad3a5e0be Mon Sep 17 00:00:00 2001 From: acocuzzo Date: Wed, 21 Sep 2022 11:22:47 -0400 Subject: [PATCH 02/25] Add compression arg to channel creation --- google/api_core/grpc_helpers.py | 14 +++++++++----- google/api_core/grpc_helpers_async.py | 6 +++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/google/api_core/grpc_helpers.py b/google/api_core/grpc_helpers.py index bf04ae4c..fa107e87 100644 --- a/google/api_core/grpc_helpers.py +++ b/google/api_core/grpc_helpers.py @@ -276,6 +276,7 @@ def create_channel( quota_project_id=None, default_scopes=None, default_host=None, + compression=None, **kwargs ): """Create a secure channel with credentials. @@ -297,6 +298,9 @@ def create_channel( default_scopes (Sequence[str]): Default scopes passed by a Google client library. Use 'scopes' for user-defined scopes. default_host (str): The default endpoint. e.g., "pubsub.googleapis.com". + compression (grpc.Compression): An optional value indicating the + compression method to be used over the lifetime of the channel. + This is an EXPERIMENTAL option. kwargs: Additional key-word args passed to :func:`grpc_gcp.secure_channel` or :func:`grpc.secure_channel`. Note: `grpc_gcp` is only supported in environments with protobuf < 4.0.0. @@ -319,12 +323,12 @@ def create_channel( ) if HAS_GRPC_GCP: - return grpc_gcp.secure_channel(target, composite_credentials, **kwargs) - return grpc.secure_channel(target, composite_credentials, **kwargs) + return grpc_gcp.secure_channel(target, composite_credentials, compression=compression, **kwargs) + return grpc.secure_channel(target, composite_credentials, compression=compression, **kwargs) _MethodCall = collections.namedtuple( - "_MethodCall", ("request", "timeout", "metadata", "credentials") + "_MethodCall", ("request", "timeout", "metadata", "credentials", "compression") ) _ChannelRequest = collections.namedtuple("_ChannelRequest", ("method", "request")) @@ -353,9 +357,9 @@ def __init__(self, method, channel): """List[Tuple]: All invocations of this callable. Each tuple is the request, timeout, metadata, and credentials.""" - def __call__(self, request, timeout=None, metadata=None, credentials=None): + def __call__(self, request, timeout=None, metadata=None, credentials=None, compression=None): self._channel.requests.append(_ChannelRequest(self._method, request)) - self.calls.append(_MethodCall(request, timeout, metadata, credentials)) + self.calls.append(_MethodCall(request, timeout, metadata, credentials, compression)) self.requests.append(request) response = self.response diff --git a/google/api_core/grpc_helpers_async.py b/google/api_core/grpc_helpers_async.py index 5a5bf2a6..72901889 100644 --- a/google/api_core/grpc_helpers_async.py +++ b/google/api_core/grpc_helpers_async.py @@ -212,6 +212,7 @@ def create_channel( quota_project_id=None, default_scopes=None, default_host=None, + compression=None, **kwargs ): """Create an AsyncIO secure channel with credentials. @@ -233,6 +234,9 @@ def create_channel( default_scopes (Sequence[str]): Default scopes passed by a Google client library. Use 'scopes' for user-defined scopes. default_host (str): The default endpoint. e.g., "pubsub.googleapis.com". + compression (grpc.Compression): An optional value indicating the + compression method to be used over the lifetime of the channel. + This is an EXPERIMENTAL option. kwargs: Additional key-word args passed to :func:`aio.secure_channel`. Returns: @@ -252,7 +256,7 @@ def create_channel( default_host=default_host, ) - return aio.secure_channel(target, composite_credentials, **kwargs) + return aio.secure_channel(target, composite_credentials, compression=compression, **kwargs) class FakeUnaryUnaryCall(_WrappedUnaryUnaryCall): From b255ba3f9c7dd637f1700058ca6a09f7c47808cd Mon Sep 17 00:00:00 2001 From: acocuzzo Date: Fri, 17 Feb 2023 14:11:41 -0500 Subject: [PATCH 03/25] fix linter errors --- google/api_core/gapic_v1/method.py | 12 +++++-- google/api_core/gapic_v1/method_async.py | 4 ++- google/api_core/grpc_helpers.py | 16 ++++++--- google/api_core/grpc_helpers_async.py | 4 ++- .../operations_v1/operations_async_client.py | 24 ++++++++++--- .../operations_v1/operations_client.py | 36 ++++++++++++++----- 6 files changed, 75 insertions(+), 21 deletions(-) diff --git a/google/api_core/gapic_v1/method.py b/google/api_core/gapic_v1/method.py index 9466e507..c7abaf5d 100644 --- a/google/api_core/gapic_v1/method.py +++ b/google/api_core/gapic_v1/method.py @@ -86,7 +86,9 @@ def __init__(self, target, retry, timeout, metadata=None, compression=None): self._metadata = metadata self._compression = compression - def __call__(self, *args, timeout=DEFAULT, retry=DEFAULT, compression=DEFAULT, **kwargs): + def __call__( + self, *args, timeout=DEFAULT, retry=DEFAULT, compression=DEFAULT, **kwargs + ): """Invoke the low-level RPC with retry, timeout, and metadata.""" if retry is DEFAULT: @@ -120,7 +122,7 @@ def wrap_method( default_retry=None, default_timeout=None, default_compression=None, - client_info=client_info.DEFAULT_CLIENT_INFO + client_info=client_info.DEFAULT_CLIENT_INFO, ): """Wrap an RPC method with common behavior. @@ -212,6 +214,10 @@ def get_topic(name, timeout=None): return functools.wraps(func)( _GapicCallable( - func, default_retry, default_timeout, metadata=user_agent_metadata, compression=default_compression + func, + default_retry, + default_timeout, + metadata=user_agent_metadata, + compression=default_compression, ) ) diff --git a/google/api_core/gapic_v1/method_async.py b/google/api_core/gapic_v1/method_async.py index 1d8be3a2..986bd1ea 100644 --- a/google/api_core/gapic_v1/method_async.py +++ b/google/api_core/gapic_v1/method_async.py @@ -45,5 +45,7 @@ def wrap_method( metadata = [client_info.to_grpc_metadata()] if client_info is not None else None return functools.wraps(func)( - _GapicCallable(func, default_retry, default_timeout, default_compression, metadata=metadata) + _GapicCallable( + func, default_retry, default_timeout, default_compression, metadata=metadata + ) ) diff --git a/google/api_core/grpc_helpers.py b/google/api_core/grpc_helpers.py index fb7474f7..c29560e3 100644 --- a/google/api_core/grpc_helpers.py +++ b/google/api_core/grpc_helpers.py @@ -323,8 +323,12 @@ def create_channel( ) if HAS_GRPC_GCP: # pragma: NO COVER - return grpc_gcp.secure_channel(target, composite_credentials, compression=compression, **kwargs) - return grpc.secure_channel(target, composite_credentials, compression=compression,**kwargs) + return grpc_gcp.secure_channel( + target, composite_credentials, compression=compression, **kwargs + ) + return grpc.secure_channel( + target, composite_credentials, compression=compression, **kwargs + ) _MethodCall = collections.namedtuple( @@ -357,9 +361,13 @@ def __init__(self, method, channel): """List[Tuple]: All invocations of this callable. Each tuple is the request, timeout, metadata, and credentials.""" - def __call__(self, request, timeout=None, metadata=None, credentials=None, compression=None): + def __call__( + self, request, timeout=None, metadata=None, credentials=None, compression=None + ): self._channel.requests.append(_ChannelRequest(self._method, request)) - self.calls.append(_MethodCall(request, timeout, metadata, credentials, compression)) + self.calls.append( + _MethodCall(request, timeout, metadata, credentials, compression) + ) self.requests.append(request) response = self.response diff --git a/google/api_core/grpc_helpers_async.py b/google/api_core/grpc_helpers_async.py index 72901889..872e24ee 100644 --- a/google/api_core/grpc_helpers_async.py +++ b/google/api_core/grpc_helpers_async.py @@ -256,7 +256,9 @@ def create_channel( default_host=default_host, ) - return aio.secure_channel(target, composite_credentials, compression=compression, **kwargs) + return aio.secure_channel( + target, composite_credentials, compression=compression, **kwargs + ) class FakeUnaryUnaryCall(_WrappedUnaryUnaryCall): diff --git a/google/api_core/operations_v1/operations_async_client.py b/google/api_core/operations_v1/operations_async_client.py index 434106d9..4402e70c 100644 --- a/google/api_core/operations_v1/operations_async_client.py +++ b/google/api_core/operations_v1/operations_async_client.py @@ -140,7 +140,11 @@ async def get_operation( metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name})) return await self._get_operation( - request, retry=retry, timeout=timeout, compression=compression, metadata=metadata + request, + retry=retry, + timeout=timeout, + compression=compression, + metadata=metadata, ) async def list_operations( @@ -212,7 +216,11 @@ async def list_operations( # Create the method used to fetch pages method = functools.partial( - self._list_operations, retry=retry, timeout=timeout, compression=compression, metadata=metadata + self._list_operations, + retry=retry, + timeout=timeout, + compression=compression, + metadata=metadata, ) iterator = page_iterator_async.AsyncGRPCIterator( @@ -285,7 +293,11 @@ async def cancel_operation( metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name})) await self._cancel_operation( - request, retry=retry, timeout=timeout, compression=compression, metadata=metadata + request, + retry=retry, + timeout=timeout, + compression=compression, + metadata=metadata, ) async def delete_operation( @@ -341,5 +353,9 @@ async def delete_operation( metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name})) await self._delete_operation( - request, retry=retry, timeout=timeout, compression=compression, metadata=metadata + request, + retry=retry, + timeout=timeout, + compression=compression, + metadata=metadata, ) diff --git a/google/api_core/operations_v1/operations_client.py b/google/api_core/operations_v1/operations_client.py index dd796fa9..c1896813 100644 --- a/google/api_core/operations_v1/operations_client.py +++ b/google/api_core/operations_v1/operations_client.py @@ -107,7 +107,7 @@ def get_operation( retry=gapic_v1.method.DEFAULT, timeout=gapic_v1.method.DEFAULT, metadata=None, - compression=None + compression=None, ): """Gets the latest state of a long-running operation. @@ -154,7 +154,11 @@ def get_operation( metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name})) return self._get_operation( - request, retry=retry, timeout=timeout, compression=compression, metadata=metadata + request, + retry=retry, + timeout=timeout, + compression=compression, + metadata=metadata, ) def list_operations( @@ -164,7 +168,7 @@ def list_operations( retry=gapic_v1.method.DEFAULT, timeout=gapic_v1.method.DEFAULT, metadata=None, - compression=None + compression=None, ): """ Lists operations that match the specified filter in the request. @@ -226,7 +230,11 @@ def list_operations( # Create the method used to fetch pages method = functools.partial( - self._list_operations, retry=retry, timeout=timeout, compression=compression, metadata=metadata + self._list_operations, + retry=retry, + timeout=timeout, + compression=compression, + metadata=metadata, ) iterator = page_iterator.GRPCIterator( @@ -246,7 +254,7 @@ def cancel_operation( retry=gapic_v1.method.DEFAULT, timeout=gapic_v1.method.DEFAULT, metadata=None, - compression=None + compression=None, ): """Starts asynchronous cancellation on a long-running operation. @@ -298,7 +306,13 @@ def cancel_operation( metadata = metadata or [] metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name})) - self._cancel_operation(request, retry=retry, timeout=timeout, compression=compression, metadata=metadata) + self._cancel_operation( + request, + retry=retry, + timeout=timeout, + compression=compression, + metadata=metadata, + ) def delete_operation( self, @@ -306,7 +320,7 @@ def delete_operation( retry=gapic_v1.method.DEFAULT, timeout=gapic_v1.method.DEFAULT, metadata=None, - compression=None + compression=None, ): """Deletes a long-running operation. @@ -352,4 +366,10 @@ def delete_operation( metadata = metadata or [] metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name})) - self._delete_operation(request, retry=retry, timeout=timeout, compression=compression, metadata=metadata) + self._delete_operation( + request, + retry=retry, + timeout=timeout, + compression=compression, + metadata=metadata, + ) From a9cde2280adc0fbc8498354dc27c2e7f784abcd9 Mon Sep 17 00:00:00 2001 From: acocuzzo Date: Fri, 17 Feb 2023 15:11:51 -0500 Subject: [PATCH 04/25] fix linter errors --- google/api_core/gapic_v1/method.py | 14 ++++-- google/api_core/gapic_v1/method_async.py | 11 +++-- google/api_core/operation.py | 37 +++++++++++--- google/api_core/operation_async.py | 14 ++++-- .../operations_v1/operations_client.py | 35 +++++++------ .../api_core/operations_v1/transports/base.py | 9 ++-- tests/unit/gapic/test_method.py | 49 +++++++++---------- 7 files changed, 103 insertions(+), 66 deletions(-) diff --git a/google/api_core/gapic_v1/method.py b/google/api_core/gapic_v1/method.py index c7abaf5d..ce3aa58a 100644 --- a/google/api_core/gapic_v1/method.py +++ b/google/api_core/gapic_v1/method.py @@ -24,6 +24,7 @@ from google.api_core import grpc_helpers from google.api_core.gapic_v1 import client_info from google.api_core.timeout import TimeToDeadlineTimeout +from grpc import Compression USE_DEFAULT_METADATA = object() @@ -79,23 +80,26 @@ class _GapicCallable(object): compression (grpc.Compression): Indicates the compression method to be used for an RPC. """ - def __init__(self, target, retry, timeout, metadata=None, compression=None): + def __init__(self, target, retry, timeout, compression=Compression.NoCompression, metadata=None): self._target = target self._retry = retry self._timeout = timeout - self._metadata = metadata self._compression = compression + self._metadata = metadata def __call__( self, *args, timeout=DEFAULT, retry=DEFAULT, compression=DEFAULT, **kwargs ): - """Invoke the low-level RPC with retry, timeout, and metadata.""" + """Invoke the low-level RPC with retry, timeout, compression, and metadata.""" if retry is DEFAULT: retry = self._retry if timeout is DEFAULT: timeout = self._timeout + + if compression is DEFAULT: + compression = self._compression if isinstance(timeout, (int, float)): timeout = TimeToDeadlineTimeout(timeout=timeout) @@ -121,7 +125,7 @@ def wrap_method( func, default_retry=None, default_timeout=None, - default_compression=None, + default_compression=Compression.NoCompression, client_info=client_info.DEFAULT_CLIENT_INFO, ): """Wrap an RPC method with common behavior. @@ -217,7 +221,7 @@ def get_topic(name, timeout=None): func, default_retry, default_timeout, + default_compression, metadata=user_agent_metadata, - compression=default_compression, ) ) diff --git a/google/api_core/gapic_v1/method_async.py b/google/api_core/gapic_v1/method_async.py index 986bd1ea..8ca929c8 100644 --- a/google/api_core/gapic_v1/method_async.py +++ b/google/api_core/gapic_v1/method_async.py @@ -24,21 +24,22 @@ from google.api_core.gapic_v1.method import _GapicCallable from google.api_core.gapic_v1.method import DEFAULT # noqa: F401 from google.api_core.gapic_v1.method import USE_DEFAULT_METADATA # noqa: F401 +from grpc import Compression def wrap_method( func, default_retry=None, default_timeout=None, - default_compression=None, + default_compression=Compression.NoCompression, client_info=client_info.DEFAULT_CLIENT_INFO, ): """Wrap an async RPC method with common behavior. Returns: - Callable: A new callable that takes optional ``retry`` and ``timeout`` - arguments and applies the common error mapping, retry, timeout, - and metadata behavior to the low-level RPC method. + Callable: A new callable that takes optional ``retry``, ``timeout``, + and compression arguments and applies the common error mapping, + retry, timeout, metadata, and compression behavior to the low-level RPC method. """ func = grpc_helpers_async.wrap_errors(func) @@ -46,6 +47,6 @@ def wrap_method( return functools.wraps(func)( _GapicCallable( - func, default_retry, default_timeout, default_compression, metadata=metadata + func, default_retry, default_timeout, compression=default_compression, metadata=metadata ) ) diff --git a/google/api_core/operation.py b/google/api_core/operation.py index 90cbdc99..151f0f00 100644 --- a/google/api_core/operation.py +++ b/google/api_core/operation.py @@ -45,6 +45,7 @@ def my_callback(future): from google.longrunning import operations_pb2 from google.protobuf import json_format from google.rpc import code_pb2 +from grpc import Compression class Operation(polling.PollingFuture): @@ -61,6 +62,7 @@ class Operation(polling.PollingFuture): result. metadata_type (func:`type`): The protobuf type for the operation's metadata. + compression_type (Compression): The compression method for an operation. polling (google.api_core.retry.Retry): The configuration used for polling. This parameter controls how often :meth:`done` is polled. If the ``timeout`` argument is specified in the :meth:`result` method, it will @@ -77,6 +79,7 @@ def __init__( cancel, result_type, metadata_type=None, + compression_type=Compression.NoCompression, polling=polling.DEFAULT_POLLING, **kwargs ): @@ -86,6 +89,7 @@ def __init__( self._cancel = cancel self._result_type = result_type self._metadata_type = metadata_type + self._compression_type = compression_type self._completion_lock = threading.Lock() # Invoke this in case the operation came back already complete. self._set_result_from_operation() @@ -103,7 +107,16 @@ def metadata(self): return protobuf_helpers.from_any_pb( self._metadata_type, self._operation.metadata - ) + ) + + @property + def compression(self): + """Compression: the current operation compression.""" + if not self._operation.HasField("compression"): + return None + + return self._compression_type + @classmethod def deserialize(self, payload): @@ -291,7 +304,8 @@ def _cancel_grpc(operations_stub, operation_name): operations_stub.CancelOperation(request_pb) -def from_grpc(operation, operations_stub, result_type, grpc_metadata=None, **kwargs): +def from_grpc(operation, operations_stub, result_type, grpc_metadata=None, + grpc_compression=Compression.NoCompression, **kwargs): """Create an operation future using a gRPC client. This interacts with the long-running operations `service`_ (specific @@ -308,6 +322,7 @@ def from_grpc(operation, operations_stub, result_type, grpc_metadata=None, **kwa result_type (:func:`type`): The protobuf result type. grpc_metadata (Optional[List[Tuple[str, str]]]): Additional metadata to pass to the rpc. + grpc_compression (grpc.Compression): Type of compression for the rpc. kwargs: Keyword args passed into the :class:`Operation` constructor. Returns: @@ -315,15 +330,19 @@ def from_grpc(operation, operations_stub, result_type, grpc_metadata=None, **kwa operation. """ refresh = functools.partial( - _refresh_grpc, operations_stub, operation.name, metadata=grpc_metadata + _refresh_grpc, operations_stub, operation.name, metadata=grpc_metadata, + compression=grpc_compression ) cancel = functools.partial( - _cancel_grpc, operations_stub, operation.name, metadata=grpc_metadata + _cancel_grpc, operations_stub, operation.name, metadata=grpc_metadata, + compression=grpc_compression ) return Operation(operation, refresh, cancel, result_type, **kwargs) -def from_gapic(operation, operations_client, result_type, grpc_metadata=None, **kwargs): +def from_gapic(operation, operations_client, result_type, grpc_metadata=None, + grpc_compression=Compression.NoCompression, + **kwargs): """Create an operation future from a gapic client. This interacts with the long-running operations `service`_ (specific @@ -340,6 +359,8 @@ def from_gapic(operation, operations_client, result_type, grpc_metadata=None, ** result_type (:func:`type`): The protobuf result type. grpc_metadata (Optional[List[Tuple[str, str]]]): Additional metadata to pass to the rpc. + grpc_compression (grpc.Comression): Additional metadata to pass + to the rpc. kwargs: Keyword args passed into the :class:`Operation` constructor. Returns: @@ -347,9 +368,11 @@ def from_gapic(operation, operations_client, result_type, grpc_metadata=None, ** operation. """ refresh = functools.partial( - operations_client.get_operation, operation.name, metadata=grpc_metadata + operations_client.get_operation, operation.name, metadata=grpc_metadata, + compression=grpc_compression ) cancel = functools.partial( - operations_client.cancel_operation, operation.name, metadata=grpc_metadata + operations_client.cancel_operation, operation.name, metadata=grpc_metadata, + compression=grpc_compression ) return Operation(operation, refresh, cancel, result_type, **kwargs) diff --git a/google/api_core/operation_async.py b/google/api_core/operation_async.py index 6bae8654..39825466 100644 --- a/google/api_core/operation_async.py +++ b/google/api_core/operation_async.py @@ -44,6 +44,7 @@ def my_callback(future): from google.api_core.future import async_future from google.longrunning import operations_pb2 from google.rpc import code_pb2 +from grpc import Compression class AsyncOperation(async_future.AsyncFuture): @@ -60,6 +61,7 @@ class AsyncOperation(async_future.AsyncFuture): result. metadata_type (func:`type`): The protobuf type for the operation's metadata. + compression_type (Compression): The compression method for an operation. retry (google.api_core.retry.Retry): The retry configuration used when polling. This can be used to control how often :meth:`done` is polled. Regardless of the retry's ``deadline``, it will be @@ -73,6 +75,7 @@ def __init__( cancel, result_type, metadata_type=None, + compression_type=Compression.NoCompression, retry=async_future.DEFAULT_RETRY, ): super().__init__(retry=retry) @@ -81,6 +84,7 @@ def __init__( self._cancel = cancel self._result_type = result_type self._metadata_type = metadata_type + self._compression_type = compression_type self._completion_lock = threading.Lock() # Invoke this in case the operation came back already complete. self._set_result_from_operation() @@ -189,7 +193,8 @@ async def cancelled(self): ) -def from_gapic(operation, operations_client, result_type, grpc_metadata=None, **kwargs): +def from_gapic(operation, operations_client, result_type, grpc_metadata=None, + grpc_compression = Compression.NoCompression, **kwargs): """Create an operation future from a gapic client. This interacts with the long-running operations `service`_ (specific @@ -206,6 +211,7 @@ def from_gapic(operation, operations_client, result_type, grpc_metadata=None, ** result_type (:func:`type`): The protobuf result type. grpc_metadata (Optional[List[Tuple[str, str]]]): Additional metadata to pass to the rpc. + grpc_compression (grpc.Compression): Type of compression for the rpc. kwargs: Keyword args passed into the :class:`Operation` constructor. Returns: @@ -213,9 +219,11 @@ def from_gapic(operation, operations_client, result_type, grpc_metadata=None, ** operation. """ refresh = functools.partial( - operations_client.get_operation, operation.name, metadata=grpc_metadata + operations_client.get_operation, operation.name, metadata=grpc_metadata, + compression=grpc_compression ) cancel = functools.partial( - operations_client.cancel_operation, operation.name, metadata=grpc_metadata + operations_client.cancel_operation, operation.name, metadata=grpc_metadata, + compression=grpc_compression ) return AsyncOperation(operation, refresh, cancel, result_type, **kwargs) diff --git a/google/api_core/operations_v1/operations_client.py b/google/api_core/operations_v1/operations_client.py index c1896813..70b80a22 100644 --- a/google/api_core/operations_v1/operations_client.py +++ b/google/api_core/operations_v1/operations_client.py @@ -43,6 +43,7 @@ from google.api_core import retry as retries from google.api_core import timeout as timeouts from google.longrunning import operations_pb2 +from grpc import Compression class OperationsClient(object): @@ -72,32 +73,34 @@ def __init__(self, channel, client_config=None): ) default_timeout = timeouts.TimeToDeadlineTimeout(timeout=600.0) + default_compression = Compression.NoCompression + self._get_operation = gapic_v1.method.wrap_method( self.operations_stub.GetOperation, default_retry=default_retry, default_timeout=default_timeout, - default_compression=method_configs["GetOperation"].compression, + default_compression=default_compression, ) self._list_operations = gapic_v1.method.wrap_method( self.operations_stub.ListOperations, default_retry=default_retry, default_timeout=default_timeout, - default_compression=method_configs["ListOperations"].compression, + default_compression=default_compression, ) self._cancel_operation = gapic_v1.method.wrap_method( self.operations_stub.CancelOperation, default_retry=default_retry, default_timeout=default_timeout, - default_compression=method_configs["CancelOperation"].compression, + default_compression=default_compression, ) self._delete_operation = gapic_v1.method.wrap_method( self.operations_stub.DeleteOperation, default_retry=default_retry, default_timeout=default_timeout, - default_compression=method_configs["DeleteOperation"].compression, + default_compression=default_compression, ) # Service calls @@ -106,8 +109,8 @@ def get_operation( name, retry=gapic_v1.method.DEFAULT, timeout=gapic_v1.method.DEFAULT, + compression=Compression.NoCompression, metadata=None, - compression=None, ): """Gets the latest state of a long-running operation. @@ -133,10 +136,10 @@ def get_operation( unspecified, the the default timeout in the client configuration is used. If ``None``, then the RPC method will not time out. - metadata (Optional[List[Tuple[str, str]]]): - Additional gRPC metadata. compression (grpc.Compression): An element of grpc.compression e.g. grpc.compression.Gzip. This is an EXPERIMENTAL option. + metadata (Optional[List[Tuple[str, str]]]): + Additional gRPC metadata. Returns: google.longrunning.operations_pb2.Operation: The state of the @@ -167,8 +170,8 @@ def list_operations( filter_, retry=gapic_v1.method.DEFAULT, timeout=gapic_v1.method.DEFAULT, + compression=Compression.NoCompression, metadata=None, - compression=None, ): """ Lists operations that match the specified filter in the request. @@ -204,10 +207,10 @@ def list_operations( unspecified, the the default timeout in the client configuration is used. If ``None``, then the RPC method will not time out. - metadata (Optional[List[Tuple[str, str]]]): Additional gRPC - metadata. compression (grpc.Compression): An element of grpc.compression e.g. grpc.compression.Gzip. This is an EXPERIMENTAL option. + metadata (Optional[List[Tuple[str, str]]]): Additional gRPC + metadata. Returns: google.api_core.page_iterator.Iterator: An iterator that yields @@ -253,8 +256,8 @@ def cancel_operation( name, retry=gapic_v1.method.DEFAULT, timeout=gapic_v1.method.DEFAULT, + compression=gapic_v1.method.DEFAULT, metadata=None, - compression=None, ): """Starts asynchronous cancellation on a long-running operation. @@ -286,10 +289,10 @@ def cancel_operation( unspecified, the the default timeout in the client configuration is used. If ``None``, then the RPC method will not time out. - metadata (Optional[List[Tuple[str, str]]]): Additional gRPC - metadata. compression (grpc.Compression): An element of grpc.compression e.g. grpc.compression.Gzip. This is an EXPERIMENTAL option. + metadata (Optional[List[Tuple[str, str]]]): Additional gRPC + metadata. Raises: google.api_core.exceptions.MethodNotImplemented: If the server @@ -319,8 +322,8 @@ def delete_operation( name, retry=gapic_v1.method.DEFAULT, timeout=gapic_v1.method.DEFAULT, + compression=gapic_v1.method.DEFAULT, metadata=None, - compression=None, ): """Deletes a long-running operation. @@ -346,10 +349,10 @@ def delete_operation( unspecified, the the default timeout in the client configuration is used. If ``None``, then the RPC method will not time out. - metadata (Optional[List[Tuple[str, str]]]): Additional gRPC - metadata. compression (grpc.Compression): An element of grpc.compression e.g. grpc.compression.Gzip. This is an EXPERIMENTAL option. + metadata (Optional[List[Tuple[str, str]]]): Additional gRPC + metadata. Raises: google.api_core.exceptions.MethodNotImplemented: If the server diff --git a/google/api_core/operations_v1/transports/base.py b/google/api_core/operations_v1/transports/base.py index e04c47aa..98cf7896 100644 --- a/google/api_core/operations_v1/transports/base.py +++ b/google/api_core/operations_v1/transports/base.py @@ -26,6 +26,7 @@ from google.longrunning import operations_pb2 from google.oauth2 import service_account # type: ignore from google.protobuf import empty_pb2 # type: ignore +from grpc import Compression DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -129,7 +130,7 @@ def _prep_wrapped_messages(self, client_info): deadline=10.0, ), default_timeout=10.0, - default_compression=None, + default_compression=Compression.NoCompression, client_info=client_info, ), self.get_operation: gapic_v1.method.wrap_method( @@ -144,7 +145,7 @@ def _prep_wrapped_messages(self, client_info): deadline=10.0, ), default_timeout=10.0, - default_compression=None, + default_compression=Compression.NoCompression, client_info=client_info, ), self.delete_operation: gapic_v1.method.wrap_method( @@ -159,7 +160,7 @@ def _prep_wrapped_messages(self, client_info): deadline=10.0, ), default_timeout=10.0, - default_compression=None, + default_compression=Compression.NoCompression, client_info=client_info, ), self.cancel_operation: gapic_v1.method.wrap_method( @@ -174,7 +175,7 @@ def _prep_wrapped_messages(self, client_info): deadline=10.0, ), default_timeout=10.0, - default_compression=None, + default_compression=Compression.NoCompression, client_info=client_info, ), } diff --git a/tests/unit/gapic/test_method.py b/tests/unit/gapic/test_method.py index 28a7c28b..27d63608 100644 --- a/tests/unit/gapic/test_method.py +++ b/tests/unit/gapic/test_method.py @@ -30,7 +30,6 @@ import google.api_core.gapic_v1.method import google.api_core.page_iterator - def _utcnow_monotonic(): curr_value = datetime.datetime.min delta = datetime.timedelta(seconds=0.5) @@ -92,31 +91,6 @@ def test_wrap_method_with_custom_client_info(): assert client_info.to_grpc_metadata() in metadata -def test_wrap_method_with_no_compression(): - method = mock.Mock(spec=["__call__"]) - - wrapped_method = google.api_core.gapic_v1.method.wrap_method( - method, compression=None - ) - - wrapped_method(1, 2, meep="moop") - - method.assert_called_once_with(1, 2, meep="moop") - - -def test_wrap_method_with_custom_client_info(): - compression = grpc.Compression.Gzip - method = mock.Mock(spec=["__call__"]) - - wrapped_method = google.api_core.gapic_v1.method.wrap_method( - method, compression=compression - ) - - wrapped_method(1, 2, meep="moop") - - method.assert_called_once_with(1, 2, meep="moop", compression=grpc.Compression.Gzip) - - def test_invoke_wrapped_method_with_metadata(): method = mock.Mock(spec=["__call__"]) @@ -184,6 +158,29 @@ def test_wrap_method_with_default_retry_and_timeout_using_sentinel(unusued_sleep method.assert_called_with(timeout=60, metadata=mock.ANY) +@mock.patch("time.sleep") +def test_wrap_method_with_default_retry_timeout_compression_using_sentinel(unusued_sleep): + method = mock.Mock( + spec=["__call__"], side_effect=[exceptions.InternalServerError(None), 42] + ) + default_retry = retry.Retry() + default_timeout = timeout.ConstantTimeout(60) + default_compression = grpc.Compression.NoCompression + wrapped_method = google.api_core.gapic_v1.method.wrap_method( + method, default_retry, default_timeout, default_compression + ) + + result = wrapped_method( + retry=google.api_core.gapic_v1.method.DEFAULT, + timeout=google.api_core.gapic_v1.method.DEFAULT, + compression=google.api_core.gapic_v1.method.DEFAULT + ) + + assert result == 42 + assert method.call_count == 2 + method.assert_called_with(timeout=60, metadata=mock.ANY) + + @mock.patch("time.sleep") def test_wrap_method_with_overriding_retry_and_timeout(unusued_sleep): method = mock.Mock(spec=["__call__"], side_effect=[exceptions.NotFound(None), 42]) From c893059c1eba9283ab2137180484b35bd93e83bc Mon Sep 17 00:00:00 2001 From: acocuzzo Date: Fri, 17 Feb 2023 15:13:59 -0500 Subject: [PATCH 05/25] refactor with new lib --- google/api_core/operation.py | 16 ++++++++++------ google/api_core/operation_async.py | 18 ++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/google/api_core/operation.py b/google/api_core/operation.py index 151f0f00..44e39833 100644 --- a/google/api_core/operation.py +++ b/google/api_core/operation.py @@ -304,8 +304,10 @@ def _cancel_grpc(operations_stub, operation_name): operations_stub.CancelOperation(request_pb) -def from_grpc(operation, operations_stub, result_type, grpc_metadata=None, - grpc_compression=Compression.NoCompression, **kwargs): +def from_grpc(operation, operations_stub, result_type, + grpc_compression=Compression.NoCompression, + grpc_metadata=None, + **kwargs): """Create an operation future using a gRPC client. This interacts with the long-running operations `service`_ (specific @@ -330,12 +332,14 @@ def from_grpc(operation, operations_stub, result_type, grpc_metadata=None, operation. """ refresh = functools.partial( - _refresh_grpc, operations_stub, operation.name, metadata=grpc_metadata, - compression=grpc_compression + _refresh_grpc, operations_stub, operation.name, + compression=grpc_compression, + metadata=grpc_metadata, ) cancel = functools.partial( - _cancel_grpc, operations_stub, operation.name, metadata=grpc_metadata, - compression=grpc_compression + _cancel_grpc, operations_stub, operation.name, + compression=grpc_compression, + metadata=grpc_metadata, ) return Operation(operation, refresh, cancel, result_type, **kwargs) diff --git a/google/api_core/operation_async.py b/google/api_core/operation_async.py index 39825466..ce5756a1 100644 --- a/google/api_core/operation_async.py +++ b/google/api_core/operation_async.py @@ -59,9 +59,9 @@ class AsyncOperation(async_future.AsyncFuture): the operation. result_type (func:`type`): The protobuf type for the operation's result. + compression_type (Compression): The compression method for an operation. metadata_type (func:`type`): The protobuf type for the operation's metadata. - compression_type (Compression): The compression method for an operation. retry (google.api_core.retry.Retry): The retry configuration used when polling. This can be used to control how often :meth:`done` is polled. Regardless of the retry's ``deadline``, it will be @@ -74,8 +74,8 @@ def __init__( refresh, cancel, result_type, - metadata_type=None, compression_type=Compression.NoCompression, + metadata_type=None, retry=async_future.DEFAULT_RETRY, ): super().__init__(retry=retry) @@ -193,8 +193,8 @@ async def cancelled(self): ) -def from_gapic(operation, operations_client, result_type, grpc_metadata=None, - grpc_compression = Compression.NoCompression, **kwargs): +def from_gapic(operation, operations_client, result_type, + grpc_compression = Compression.NoCompression, grpc_metadata=None, **kwargs): """Create an operation future from a gapic client. This interacts with the long-running operations `service`_ (specific @@ -219,11 +219,13 @@ def from_gapic(operation, operations_client, result_type, grpc_metadata=None, operation. """ refresh = functools.partial( - operations_client.get_operation, operation.name, metadata=grpc_metadata, - compression=grpc_compression + operations_client.get_operation, operation.name, + compression=grpc_compression, + metadata=grpc_metadata, ) cancel = functools.partial( - operations_client.cancel_operation, operation.name, metadata=grpc_metadata, - compression=grpc_compression + operations_client.cancel_operation, operation.name, + compression=grpc_compression, + metadata=grpc_metadata, ) return AsyncOperation(operation, refresh, cancel, result_type, **kwargs) From 934d6b97c5a282a80058f10e386ad1ab6eb91a8b Mon Sep 17 00:00:00 2001 From: acocuzzo Date: Fri, 17 Feb 2023 15:16:12 -0500 Subject: [PATCH 06/25] reformat --- google/api_core/gapic_v1/method.py | 11 +++++- google/api_core/gapic_v1/method_async.py | 6 ++- google/api_core/operation.py | 48 ++++++++++++++++-------- google/api_core/operation_async.py | 16 ++++++-- tests/unit/gapic/test_method.py | 7 +++- 5 files changed, 63 insertions(+), 25 deletions(-) diff --git a/google/api_core/gapic_v1/method.py b/google/api_core/gapic_v1/method.py index ce3aa58a..56b88c33 100644 --- a/google/api_core/gapic_v1/method.py +++ b/google/api_core/gapic_v1/method.py @@ -80,7 +80,14 @@ class _GapicCallable(object): compression (grpc.Compression): Indicates the compression method to be used for an RPC. """ - def __init__(self, target, retry, timeout, compression=Compression.NoCompression, metadata=None): + def __init__( + self, + target, + retry, + timeout, + compression=Compression.NoCompression, + metadata=None, + ): self._target = target self._retry = retry self._timeout = timeout @@ -97,7 +104,7 @@ def __call__( if timeout is DEFAULT: timeout = self._timeout - + if compression is DEFAULT: compression = self._compression diff --git a/google/api_core/gapic_v1/method_async.py b/google/api_core/gapic_v1/method_async.py index 8ca929c8..4edc18a9 100644 --- a/google/api_core/gapic_v1/method_async.py +++ b/google/api_core/gapic_v1/method_async.py @@ -47,6 +47,10 @@ def wrap_method( return functools.wraps(func)( _GapicCallable( - func, default_retry, default_timeout, compression=default_compression, metadata=metadata + func, + default_retry, + default_timeout, + compression=default_compression, + metadata=metadata, ) ) diff --git a/google/api_core/operation.py b/google/api_core/operation.py index 44e39833..37281800 100644 --- a/google/api_core/operation.py +++ b/google/api_core/operation.py @@ -107,8 +107,8 @@ def metadata(self): return protobuf_helpers.from_any_pb( self._metadata_type, self._operation.metadata - ) - + ) + @property def compression(self): """Compression: the current operation compression.""" @@ -116,7 +116,6 @@ def compression(self): return None return self._compression_type - @classmethod def deserialize(self, payload): @@ -304,10 +303,14 @@ def _cancel_grpc(operations_stub, operation_name): operations_stub.CancelOperation(request_pb) -def from_grpc(operation, operations_stub, result_type, - grpc_compression=Compression.NoCompression, - grpc_metadata=None, - **kwargs): +def from_grpc( + operation, + operations_stub, + result_type, + grpc_compression=Compression.NoCompression, + grpc_metadata=None, + **kwargs +): """Create an operation future using a gRPC client. This interacts with the long-running operations `service`_ (specific @@ -332,21 +335,30 @@ def from_grpc(operation, operations_stub, result_type, operation. """ refresh = functools.partial( - _refresh_grpc, operations_stub, operation.name, + _refresh_grpc, + operations_stub, + operation.name, compression=grpc_compression, metadata=grpc_metadata, ) cancel = functools.partial( - _cancel_grpc, operations_stub, operation.name, + _cancel_grpc, + operations_stub, + operation.name, compression=grpc_compression, metadata=grpc_metadata, ) return Operation(operation, refresh, cancel, result_type, **kwargs) -def from_gapic(operation, operations_client, result_type, grpc_metadata=None, - grpc_compression=Compression.NoCompression, - **kwargs): +def from_gapic( + operation, + operations_client, + result_type, + grpc_metadata=None, + grpc_compression=Compression.NoCompression, + **kwargs +): """Create an operation future from a gapic client. This interacts with the long-running operations `service`_ (specific @@ -372,11 +384,15 @@ def from_gapic(operation, operations_client, result_type, grpc_metadata=None, operation. """ refresh = functools.partial( - operations_client.get_operation, operation.name, metadata=grpc_metadata, - compression=grpc_compression + operations_client.get_operation, + operation.name, + metadata=grpc_metadata, + compression=grpc_compression, ) cancel = functools.partial( - operations_client.cancel_operation, operation.name, metadata=grpc_metadata, - compression=grpc_compression + operations_client.cancel_operation, + operation.name, + metadata=grpc_metadata, + compression=grpc_compression, ) return Operation(operation, refresh, cancel, result_type, **kwargs) diff --git a/google/api_core/operation_async.py b/google/api_core/operation_async.py index ce5756a1..9f795a0e 100644 --- a/google/api_core/operation_async.py +++ b/google/api_core/operation_async.py @@ -193,8 +193,14 @@ async def cancelled(self): ) -def from_gapic(operation, operations_client, result_type, - grpc_compression = Compression.NoCompression, grpc_metadata=None, **kwargs): +def from_gapic( + operation, + operations_client, + result_type, + grpc_compression=Compression.NoCompression, + grpc_metadata=None, + **kwargs +): """Create an operation future from a gapic client. This interacts with the long-running operations `service`_ (specific @@ -219,12 +225,14 @@ def from_gapic(operation, operations_client, result_type, operation. """ refresh = functools.partial( - operations_client.get_operation, operation.name, + operations_client.get_operation, + operation.name, compression=grpc_compression, metadata=grpc_metadata, ) cancel = functools.partial( - operations_client.cancel_operation, operation.name, + operations_client.cancel_operation, + operation.name, compression=grpc_compression, metadata=grpc_metadata, ) diff --git a/tests/unit/gapic/test_method.py b/tests/unit/gapic/test_method.py index 27d63608..0075af75 100644 --- a/tests/unit/gapic/test_method.py +++ b/tests/unit/gapic/test_method.py @@ -30,6 +30,7 @@ import google.api_core.gapic_v1.method import google.api_core.page_iterator + def _utcnow_monotonic(): curr_value = datetime.datetime.min delta = datetime.timedelta(seconds=0.5) @@ -159,7 +160,9 @@ def test_wrap_method_with_default_retry_and_timeout_using_sentinel(unusued_sleep @mock.patch("time.sleep") -def test_wrap_method_with_default_retry_timeout_compression_using_sentinel(unusued_sleep): +def test_wrap_method_with_default_retry_timeout_compression_using_sentinel( + unusued_sleep, +): method = mock.Mock( spec=["__call__"], side_effect=[exceptions.InternalServerError(None), 42] ) @@ -173,7 +176,7 @@ def test_wrap_method_with_default_retry_timeout_compression_using_sentinel(unusu result = wrapped_method( retry=google.api_core.gapic_v1.method.DEFAULT, timeout=google.api_core.gapic_v1.method.DEFAULT, - compression=google.api_core.gapic_v1.method.DEFAULT + compression=google.api_core.gapic_v1.method.DEFAULT, ) assert result == 42 From 69cf59b7637038073029dcebdb6157956042b0cb Mon Sep 17 00:00:00 2001 From: acocuzzo Date: Fri, 17 Feb 2023 15:22:28 -0500 Subject: [PATCH 07/25] fix tests --- tests/unit/test_grpc_helpers.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/unit/test_grpc_helpers.py b/tests/unit/test_grpc_helpers.py index 9fe938d6..02556c3f 100644 --- a/tests/unit/test_grpc_helpers.py +++ b/tests/unit/test_grpc_helpers.py @@ -366,7 +366,7 @@ def test_create_channel_implicit(grpc_secure_channel, default, composite_creds_c default.assert_called_once_with(scopes=None, default_scopes=None) if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER - grpc_secure_channel.assert_called_once_with(target, composite_creds, None) + grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: grpc_secure_channel.assert_called_once_with(target, composite_creds) @@ -401,7 +401,7 @@ def test_create_channel_implicit_with_default_host( ) if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER - grpc_secure_channel.assert_called_once_with(target, composite_creds, None) + grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: grpc_secure_channel.assert_called_once_with(target, composite_creds) @@ -428,7 +428,7 @@ def test_create_channel_implicit_with_ssl_creds( composite_creds = composite_creds_call.return_value if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER - grpc_secure_channel.assert_called_once_with(target, composite_creds, None) + grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: grpc_secure_channel.assert_called_once_with(target, composite_creds) @@ -453,7 +453,7 @@ def test_create_channel_implicit_with_scopes( default.assert_called_once_with(scopes=["one", "two"], default_scopes=None) if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER - grpc_secure_channel.assert_called_once_with(target, composite_creds, None) + grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: grpc_secure_channel.assert_called_once_with(target, composite_creds) @@ -478,7 +478,7 @@ def test_create_channel_implicit_with_default_scopes( default.assert_called_once_with(scopes=None, default_scopes=["three", "four"]) if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER - grpc_secure_channel.assert_called_once_with(target, composite_creds, None) + grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: grpc_secure_channel.assert_called_once_with(target, composite_creds) @@ -510,7 +510,7 @@ def test_create_channel_explicit(grpc_secure_channel, auth_creds, composite_cred assert channel is grpc_secure_channel.return_value if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER - grpc_secure_channel.assert_called_once_with(target, composite_creds, None) + grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: grpc_secure_channel.assert_called_once_with(target, composite_creds) @@ -534,7 +534,7 @@ def test_create_channel_explicit_scoped(grpc_secure_channel, composite_creds_cal assert channel is grpc_secure_channel.return_value if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER - grpc_secure_channel.assert_called_once_with(target, composite_creds, None) + grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: grpc_secure_channel.assert_called_once_with(target, composite_creds) @@ -562,7 +562,7 @@ def test_create_channel_explicit_default_scopes( assert channel is grpc_secure_channel.return_value if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER - grpc_secure_channel.assert_called_once_with(target, composite_creds, None) + grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: grpc_secure_channel.assert_called_once_with(target, composite_creds) @@ -588,7 +588,7 @@ def test_create_channel_explicit_with_quota_project( assert channel is grpc_secure_channel.return_value if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER - grpc_secure_channel.assert_called_once_with(target, composite_creds, None) + grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: grpc_secure_channel.assert_called_once_with(target, composite_creds) @@ -617,7 +617,7 @@ def test_create_channel_with_credentials_file( assert channel is grpc_secure_channel.return_value if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER - grpc_secure_channel.assert_called_once_with(target, composite_creds, None) + grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: grpc_secure_channel.assert_called_once_with(target, composite_creds) @@ -649,7 +649,7 @@ def test_create_channel_with_credentials_file_and_scopes( assert channel is grpc_secure_channel.return_value if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER - grpc_secure_channel.assert_called_once_with(target, composite_creds, None) + grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: grpc_secure_channel.assert_called_once_with(target, composite_creds) @@ -681,7 +681,7 @@ def test_create_channel_with_credentials_file_and_default_scopes( assert channel is grpc_secure_channel.return_value if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER - grpc_secure_channel.assert_called_once_with(target, composite_creds, None) + grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: grpc_secure_channel.assert_called_once_with(target, composite_creds) From 49e8d9c7fd9e0cf758f43227fa73d1763397ce52 Mon Sep 17 00:00:00 2001 From: acocuzzo Date: Fri, 14 Apr 2023 16:04:50 -0400 Subject: [PATCH 08/25] add compression after refactor: --- google/api_core/gapic_v1/method.py | 25 +++++++++++------ google/api_core/gapic_v1/method_async.py | 7 ++--- .../abstract_operations_client.py | 6 ++++ .../operations_v1/operations_async_client.py | 20 +++++++------ .../operations_v1/operations_client.py | 4 +-- .../api_core/operations_v1/transports/rest.py | 5 ++++ tests/asyncio/gapic/test_method_async.py | 10 +++---- tests/asyncio/test_grpc_helpers_async.py | 22 +++++++-------- tests/unit/gapic/test_method.py | 6 ++-- tests/unit/test_grpc_helpers.py | 28 ++++++++++--------- 10 files changed, 77 insertions(+), 56 deletions(-) diff --git a/google/api_core/gapic_v1/method.py b/google/api_core/gapic_v1/method.py index 56b88c33..da59360d 100644 --- a/google/api_core/gapic_v1/method.py +++ b/google/api_core/gapic_v1/method.py @@ -15,7 +15,7 @@ """Helpers for wrapping low-level gRPC methods with common functionality. This is used by gapic clients to provide common error mapping, retry, timeout, -pagination, and long-running operations to gRPC methods. +compression, pagination, and long-running operations to gRPC methods. """ import enum @@ -73,11 +73,13 @@ class _GapicCallable(object): after its start, not to be confused with deadline). If ``None``, this callable will not specify a timeout argument to the low-level RPC method. + compression (grpc.Compression): The default compression for the callable. + If ``None``, this callable will not specify a compression argument + to the low-level RPC method. metadata (Sequence[Tuple[str, str]]): Additional metadata that is provided to the RPC method on every invocation. This is merged with any metadata specified during invocation. If ``None``, no additional metadata will be passed to the RPC method. - compression (grpc.Compression): Indicates the compression method to be used for an RPC. """ def __init__( @@ -85,7 +87,7 @@ def __init__( target, retry, timeout, - compression=Compression.NoCompression, + compression, metadata=None, ): self._target = target @@ -112,7 +114,7 @@ def __call__( timeout = TimeToDeadlineTimeout(timeout=timeout) # Apply all applicable decorators. - wrapped_func = _apply_decorators(self._target, [retry, timeout, compression]) + wrapped_func = _apply_decorators(self._target, [retry, timeout]) # Add the user agent metadata to the call. if self._metadata is not None: @@ -124,6 +126,8 @@ def __call__( metadata = list(metadata) metadata.extend(self._metadata) kwargs["metadata"] = metadata + if self._compression is not None: + kwargs["compression"] = compression return wrapped_func(*args, **kwargs) @@ -132,7 +136,7 @@ def wrap_method( func, default_retry=None, default_timeout=None, - default_compression=Compression.NoCompression, + default_compression=None, client_info=client_info.DEFAULT_CLIENT_INFO, ): """Wrap an RPC method with common behavior. @@ -146,6 +150,7 @@ def wrap_method( import google.api_core.gapic_v1.method from google.api_core import retry from google.api_core import timeout + from grpc import Compression # The original RPC method. def get_topic(name, timeout=None): @@ -154,6 +159,7 @@ def get_topic(name, timeout=None): default_retry = retry.Retry(deadline=60) default_timeout = timeout.Timeout(deadline=60) + default_compression = Compression.NoCompression wrapped_get_topic = google.api_core.gapic_v1.method.wrap_method( get_topic, default_retry) @@ -203,7 +209,8 @@ def get_topic(name, timeout=None): timeout strategy. Can also be specified as an int or float. If ``None``, the method will not have timeout specified by default. default_compression (Optional[grpc.Compression]): The default - grpc.Compression. + grpc.Compression. If ``None``, the method will not have + compression specified by default. client_info (Optional[google.api_core.gapic_v1.client_info.ClientInfo]): Client information used to create a user-agent string that's @@ -212,12 +219,12 @@ def get_topic(name, timeout=None): metadata will be provided to the RPC method. Returns: - Callable: A new callable that takes optional ``retry`` and ``timeout`` - arguments and applies the common error mapping, retry, timeout, + Callable: A new callable that takes optional ``retry``, ``timeout``, + and ``compression`` + arguments and applies the common error mapping, retry, timeout, compression, and metadata behavior to the low-level RPC method. """ func = grpc_helpers.wrap_errors(func) - if client_info is not None: user_agent_metadata = [client_info.to_grpc_metadata()] else: diff --git a/google/api_core/gapic_v1/method_async.py b/google/api_core/gapic_v1/method_async.py index 4edc18a9..d0920d9b 100644 --- a/google/api_core/gapic_v1/method_async.py +++ b/google/api_core/gapic_v1/method_async.py @@ -14,7 +14,7 @@ """AsyncIO helpers for wrapping gRPC methods with common functionality. This is used by gapic clients to provide common error mapping, retry, timeout, -pagination, and long-running operations to gRPC methods. +compression, pagination, and long-running operations to gRPC methods. """ import functools @@ -24,14 +24,13 @@ from google.api_core.gapic_v1.method import _GapicCallable from google.api_core.gapic_v1.method import DEFAULT # noqa: F401 from google.api_core.gapic_v1.method import USE_DEFAULT_METADATA # noqa: F401 -from grpc import Compression def wrap_method( func, default_retry=None, default_timeout=None, - default_compression=Compression.NoCompression, + default_compression=None, client_info=client_info.DEFAULT_CLIENT_INFO, ): """Wrap an async RPC method with common behavior. @@ -50,7 +49,7 @@ def wrap_method( func, default_retry, default_timeout, - compression=default_compression, + default_compression, metadata=metadata, ) ) diff --git a/google/api_core/operations_v1/abstract_operations_client.py b/google/api_core/operations_v1/abstract_operations_client.py index 78a61746..fee0b393 100644 --- a/google/api_core/operations_v1/abstract_operations_client.py +++ b/google/api_core/operations_v1/abstract_operations_client.py @@ -33,6 +33,7 @@ from google.auth.transport import mtls # type: ignore from google.longrunning import operations_pb2 from google.oauth2 import service_account # type: ignore +import grpc OptionalRetry = Union[retries.Retry, object] @@ -368,6 +369,7 @@ def list_operations( page_token: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, + compression: Optional[grpc.Compression] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListOperationsPager: r"""Lists operations that match the specified filter in the request. @@ -450,6 +452,7 @@ def get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, + compression: Optional[grpc.Compression] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operations_pb2.Operation: r"""Gets the latest state of a long-running operation. @@ -502,6 +505,7 @@ def delete_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, + compression: Optional[grpc.Compression] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Deletes a long-running operation. This method indicates that the @@ -550,6 +554,7 @@ def cancel_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, + compression: Optional[grpc.Compression] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Starts asynchronous cancellation on a long-running operation. @@ -598,5 +603,6 @@ def cancel_operation( request, retry=retry, timeout=timeout, + compression=compression, metadata=metadata, ) diff --git a/google/api_core/operations_v1/operations_async_client.py b/google/api_core/operations_v1/operations_async_client.py index 4402e70c..f60d9e47 100644 --- a/google/api_core/operations_v1/operations_async_client.py +++ b/google/api_core/operations_v1/operations_async_client.py @@ -29,7 +29,7 @@ from google.api_core import retry as retries from google.api_core import timeout as timeouts from google.longrunning import operations_pb2 - +import grpc class OperationsAsyncClient: """Async client for interacting with long-running operations. @@ -59,32 +59,34 @@ def __init__(self, channel, client_config=None): ) default_timeout = timeouts.TimeToDeadlineTimeout(timeout=600.0) + default_compression = grpc.Compression.NoCompression + self._get_operation = gapic_v1.method_async.wrap_method( self.operations_stub.GetOperation, default_retry=default_retry, default_timeout=default_timeout, - default_compression=method_configs["GetOperation"].compression, + default_compression=default_compression, ) self._list_operations = gapic_v1.method_async.wrap_method( self.operations_stub.ListOperations, default_retry=default_retry, default_timeout=default_timeout, - default_compression=method_configs["ListOperations"].compression, + default_compression=default_compression, ) self._cancel_operation = gapic_v1.method_async.wrap_method( self.operations_stub.CancelOperation, default_retry=default_retry, default_timeout=default_timeout, - default_compression=method_configs["CancelOperation"].compression, + default_compression=default_compression, ) self._delete_operation = gapic_v1.method_async.wrap_method( self.operations_stub.DeleteOperation, default_retry=default_retry, default_timeout=default_timeout, - default_compression=method_configs["DeleteOperation"].compression, + default_compression=default_compression, ) async def get_operation( @@ -92,7 +94,7 @@ async def get_operation( name, retry=gapic_v1.method_async.DEFAULT, timeout=gapic_v1.method_async.DEFAULT, - compression=None, + compression=gapic_v1.method_async.DEFAULT, metadata=None, ): """Gets the latest state of a long-running operation. @@ -153,7 +155,7 @@ async def list_operations( filter_, retry=gapic_v1.method_async.DEFAULT, timeout=gapic_v1.method_async.DEFAULT, - compression=None, + compression=gapic_v1.method_async.DEFAULT, metadata=None, ): """ @@ -239,7 +241,7 @@ async def cancel_operation( name, retry=gapic_v1.method_async.DEFAULT, timeout=gapic_v1.method_async.DEFAULT, - compression=None, + compression=gapic_v1.method_async.DEFAULT, metadata=None, ): """Starts asynchronous cancellation on a long-running operation. @@ -305,7 +307,7 @@ async def delete_operation( name, retry=gapic_v1.method_async.DEFAULT, timeout=gapic_v1.method_async.DEFAULT, - compression=None, + compression=gapic_v1.method_async.DEFAULT, metadata=None, ): """Deletes a long-running operation. diff --git a/google/api_core/operations_v1/operations_client.py b/google/api_core/operations_v1/operations_client.py index 70b80a22..1cbfa63d 100644 --- a/google/api_core/operations_v1/operations_client.py +++ b/google/api_core/operations_v1/operations_client.py @@ -109,7 +109,7 @@ def get_operation( name, retry=gapic_v1.method.DEFAULT, timeout=gapic_v1.method.DEFAULT, - compression=Compression.NoCompression, + compression=gapic_v1.method.DEFAULT, metadata=None, ): """Gets the latest state of a long-running operation. @@ -170,7 +170,7 @@ def list_operations( filter_, retry=gapic_v1.method.DEFAULT, timeout=gapic_v1.method.DEFAULT, - compression=Compression.NoCompression, + compression=gapic_v1.method.DEFAULT, metadata=None, ): """ diff --git a/google/api_core/operations_v1/transports/rest.py b/google/api_core/operations_v1/transports/rest.py index bb9000f4..49f99d21 100644 --- a/google/api_core/operations_v1/transports/rest.py +++ b/google/api_core/operations_v1/transports/rest.py @@ -29,6 +29,7 @@ from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore from google.protobuf import json_format # type: ignore +import grpc from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO, OperationsTransport OptionalRetry = Union[retries.Retry, object] @@ -149,6 +150,7 @@ def _list_operations( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, + compression: Optional[grpc.Compression] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Call the list operations method over HTTP. @@ -228,6 +230,7 @@ def _get_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, + compression: Optional[grpc.Compression] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> operations_pb2.Operation: r"""Call the get operation method over HTTP. @@ -308,6 +311,7 @@ def _delete_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, + compression: Optional[grpc.Compression] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> empty_pb2.Empty: r"""Call the delete operation method over HTTP. @@ -378,6 +382,7 @@ def _cancel_operation( *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, + compression: Optional[grpc.Compression] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> empty_pb2.Empty: r"""Call the cancel operation method over HTTP. diff --git a/tests/asyncio/gapic/test_method_async.py b/tests/asyncio/gapic/test_method_async.py index ae35e4cf..9f95ce2d 100644 --- a/tests/asyncio/gapic/test_method_async.py +++ b/tests/asyncio/gapic/test_method_async.py @@ -98,11 +98,11 @@ async def test_wrap_method_with_no_compression(): fake_call = grpc_helpers_async.FakeUnaryUnaryCall() method = mock.Mock(spec=aio.UnaryUnaryMultiCallable, return_value=fake_call) - wrapped_method = gapic_v1.method_async.wrap_method(method, compression=None) + wrapped_method = gapic_v1.method_async.wrap_method(method) - await wrapped_method(1, 2, meep="moop") + await wrapped_method(1, 2, meep="moop", compression=None) - method.assert_called_once_with(1, 2, meep="moop") + method.assert_called_once_with(1, 2, meep="moop", compression=None) @pytest.mark.asyncio @@ -111,9 +111,9 @@ async def test_wrap_method_with_custom_compression(): fake_call = grpc_helpers_async.FakeUnaryUnaryCall() method = mock.Mock(spec=aio.UnaryUnaryMultiCallable, return_value=fake_call) - wrapped_method = gapic_v1.method_async.wrap_method(method, compression=compression) + wrapped_method = gapic_v1.method_async.wrap_method(method) - await wrapped_method(1, 2, meep="moop") + await wrapped_method(1, 2, meep="moop", compression=compression) method.assert_called_once_with(1, 2, meep="moop", compression=compression) diff --git a/tests/asyncio/test_grpc_helpers_async.py b/tests/asyncio/test_grpc_helpers_async.py index 33ce8212..03d671b1 100644 --- a/tests/asyncio/test_grpc_helpers_async.py +++ b/tests/asyncio/test_grpc_helpers_async.py @@ -292,7 +292,7 @@ def test_create_channel_implicit(grpc_secure_channel, default, composite_creds_c assert channel is grpc_secure_channel.return_value default.assert_called_once_with(scopes=None, default_scopes=None) - grpc_secure_channel.assert_called_once_with(target, composite_creds) + grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) @mock.patch("google.auth.transport.grpc.AuthMetadataPlugin", autospec=True) @@ -323,7 +323,7 @@ def test_create_channel_implicit_with_default_host( auth_metadata_plugin.assert_called_once_with( mock.sentinel.credentials, mock.sentinel.Request, default_host=default_host ) - grpc_secure_channel.assert_called_once_with(target, composite_creds) + grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) @mock.patch("grpc.composite_channel_credentials") @@ -344,7 +344,7 @@ def test_create_channel_implicit_with_ssl_creds( default.assert_called_once_with(scopes=None, default_scopes=None) composite_creds_call.assert_called_once_with(ssl_creds, mock.ANY) composite_creds = composite_creds_call.return_value - grpc_secure_channel.assert_called_once_with(target, composite_creds) + grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) @mock.patch("grpc.composite_channel_credentials") @@ -365,7 +365,7 @@ def test_create_channel_implicit_with_scopes( assert channel is grpc_secure_channel.return_value default.assert_called_once_with(scopes=["one", "two"], default_scopes=None) - grpc_secure_channel.assert_called_once_with(target, composite_creds) + grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) @mock.patch("grpc.composite_channel_credentials") @@ -388,7 +388,7 @@ def test_create_channel_implicit_with_default_scopes( assert channel is grpc_secure_channel.return_value default.assert_called_once_with(scopes=None, default_scopes=["three", "four"]) - grpc_secure_channel.assert_called_once_with(target, composite_creds) + grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) def test_create_channel_explicit_with_duplicate_credentials(): @@ -419,7 +419,7 @@ def test_create_channel_explicit(grpc_secure_channel, auth_creds, composite_cred mock.sentinel.credentials, scopes=None, default_scopes=None ) assert channel is grpc_secure_channel.return_value - grpc_secure_channel.assert_called_once_with(target, composite_creds) + grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) @mock.patch("grpc.composite_channel_credentials") @@ -438,7 +438,7 @@ def test_create_channel_explicit_scoped(grpc_secure_channel, composite_creds_cal credentials.with_scopes.assert_called_once_with(scopes, default_scopes=None) assert channel is grpc_secure_channel.return_value - grpc_secure_channel.assert_called_once_with(target, composite_creds) + grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) @mock.patch("grpc.composite_channel_credentials") @@ -461,7 +461,7 @@ def test_create_channel_explicit_default_scopes( scopes=None, default_scopes=default_scopes ) assert channel is grpc_secure_channel.return_value - grpc_secure_channel.assert_called_once_with(target, composite_creds) + grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) @mock.patch("grpc.composite_channel_credentials") @@ -482,7 +482,7 @@ def test_create_channel_explicit_with_quota_project( credentials.with_quota_project.assert_called_once_with("project-foo") assert channel is grpc_secure_channel.return_value - grpc_secure_channel.assert_called_once_with(target, composite_creds) + grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) @mock.patch("grpc.composite_channel_credentials") @@ -508,7 +508,7 @@ def test_create_channel_with_credentials_file( credentials_file, scopes=None, default_scopes=None ) assert channel is grpc_secure_channel.return_value - grpc_secure_channel.assert_called_once_with(target, composite_creds) + grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) @mock.patch("grpc.composite_channel_credentials") @@ -562,7 +562,7 @@ def test_create_channel_with_credentials_file_and_default_scopes( credentials_file, scopes=None, default_scopes=default_scopes ) assert channel is grpc_secure_channel.return_value - grpc_secure_channel.assert_called_once_with(target, composite_creds) + grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) @mock.patch("grpc.aio.secure_channel") diff --git a/tests/unit/gapic/test_method.py b/tests/unit/gapic/test_method.py index 0133ffb8..ecb056e4 100644 --- a/tests/unit/gapic/test_method.py +++ b/tests/unit/gapic/test_method.py @@ -165,7 +165,7 @@ def test_wrap_method_with_overriding_retry_timeout_compression(unused_sleep): method = mock.Mock(spec=["__call__"], side_effect=[exceptions.NotFound(None), 42]) default_retry = retry.Retry() default_timeout = timeout.ConstantTimeout(60) - default_compression = grpc.Compression.NoCompression + default_compression = grpc.Compression.Gzip wrapped_method = google.api_core.gapic_v1.method.wrap_method( method, default_retry, default_timeout, default_compression ) @@ -173,12 +173,12 @@ def test_wrap_method_with_overriding_retry_timeout_compression(unused_sleep): result = wrapped_method( retry=retry.Retry(retry.if_exception_type(exceptions.NotFound)), timeout=timeout.ConstantTimeout(22), - compression=grpc.Compression.NoCompression + compression=default_compression ) assert result == 42 assert method.call_count == 2 - method.assert_called_with(timeout=22, metadata=mock.ANY) + method.assert_called_with(timeout=22, compression=default_compression, metadata=mock.ANY) def test_wrap_method_with_overriding_timeout_as_a_number(): diff --git a/tests/unit/test_grpc_helpers.py b/tests/unit/test_grpc_helpers.py index 51f425c7..dd98d493 100644 --- a/tests/unit/test_grpc_helpers.py +++ b/tests/unit/test_grpc_helpers.py @@ -368,7 +368,7 @@ def test_create_channel_implicit(grpc_secure_channel, default, composite_creds_c if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: - grpc_secure_channel.assert_called_once_with(target, composite_creds) + grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) @mock.patch("google.auth.transport.grpc.AuthMetadataPlugin", autospec=True) @@ -403,7 +403,7 @@ def test_create_channel_implicit_with_default_host( if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: - grpc_secure_channel.assert_called_once_with(target, composite_creds) + grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) @mock.patch("grpc.composite_channel_credentials") @@ -430,7 +430,7 @@ def test_create_channel_implicit_with_ssl_creds( if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: - grpc_secure_channel.assert_called_once_with(target, composite_creds) + grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) @mock.patch("grpc.composite_channel_credentials") @@ -455,7 +455,7 @@ def test_create_channel_implicit_with_scopes( if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: - grpc_secure_channel.assert_called_once_with(target, composite_creds) + grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) @mock.patch("grpc.composite_channel_credentials") @@ -480,7 +480,7 @@ def test_create_channel_implicit_with_default_scopes( if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: - grpc_secure_channel.assert_called_once_with(target, composite_creds) + grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) def test_create_channel_explicit_with_duplicate_credentials(): @@ -512,7 +512,7 @@ def test_create_channel_explicit(grpc_secure_channel, auth_creds, composite_cred if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: - grpc_secure_channel.assert_called_once_with(target, composite_creds) + grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) @mock.patch("grpc.composite_channel_credentials") @@ -536,7 +536,7 @@ def test_create_channel_explicit_scoped(grpc_secure_channel, composite_creds_cal if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: - grpc_secure_channel.assert_called_once_with(target, composite_creds) + grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) @mock.patch("grpc.composite_channel_credentials") @@ -564,7 +564,7 @@ def test_create_channel_explicit_default_scopes( if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: - grpc_secure_channel.assert_called_once_with(target, composite_creds) + grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) @mock.patch("grpc.composite_channel_credentials") @@ -590,7 +590,7 @@ def test_create_channel_explicit_with_quota_project( if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: - grpc_secure_channel.assert_called_once_with(target, composite_creds) + grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) @mock.patch("grpc.composite_channel_credentials") @@ -619,7 +619,7 @@ def test_create_channel_with_credentials_file( if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: - grpc_secure_channel.assert_called_once_with(target, composite_creds) + grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) @mock.patch("grpc.composite_channel_credentials") @@ -651,7 +651,7 @@ def test_create_channel_with_credentials_file_and_scopes( if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: - grpc_secure_channel.assert_called_once_with(target, composite_creds) + grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) @mock.patch("grpc.composite_channel_credentials") @@ -683,7 +683,7 @@ def test_create_channel_with_credentials_file_and_default_scopes( if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: - grpc_secure_channel.assert_called_once_with(target, composite_creds) + grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) @pytest.mark.skipif( @@ -813,6 +813,7 @@ def test_call_info(self): stub = operations_pb2.OperationsStub(channel) expected_request = operations_pb2.GetOperationRequest(name="meep") expected_response = operations_pb2.Operation(name="moop") + expected_compression = grpc.Compression.NoCompression expected_metadata = [("red", "blue"), ("two", "shoe")] expected_credentials = mock.sentinel.credentials channel.GetOperation.response = expected_response @@ -820,6 +821,7 @@ def test_call_info(self): response = stub.GetOperation( expected_request, timeout=42, + compression=expected_compression, metadata=expected_metadata, credentials=expected_credentials, ) @@ -827,7 +829,7 @@ def test_call_info(self): assert response == expected_response assert channel.requests == [("GetOperation", expected_request)] assert channel.GetOperation.calls == [ - (expected_request, 42, expected_metadata, expected_credentials) + (expected_request, 42, expected_metadata, expected_credentials, expected_compression) ] def test_unary_unary(self): From b92254b45078f121b5ac0cd666d09f36c0bfd03d Mon Sep 17 00:00:00 2001 From: acocuzzo Date: Fri, 14 Apr 2023 16:46:34 -0400 Subject: [PATCH 09/25] fix lint --- .../abstract_operations_client.py | 2 +- .../operations_v1/operations_async_client.py | 1 + tests/asyncio/test_grpc_helpers_async.py | 44 +++++++++++---- tests/unit/gapic/test_method.py | 6 +- tests/unit/test_grpc_helpers.py | 56 ++++++++++++++----- 5 files changed, 82 insertions(+), 27 deletions(-) diff --git a/google/api_core/operations_v1/abstract_operations_client.py b/google/api_core/operations_v1/abstract_operations_client.py index fee0b393..745eb77d 100644 --- a/google/api_core/operations_v1/abstract_operations_client.py +++ b/google/api_core/operations_v1/abstract_operations_client.py @@ -369,7 +369,7 @@ def list_operations( page_token: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - compression: Optional[grpc.Compression] = gapic_v1.method.DEFAULT, + compression: Optional[grpc.Compression] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListOperationsPager: r"""Lists operations that match the specified filter in the request. diff --git a/google/api_core/operations_v1/operations_async_client.py b/google/api_core/operations_v1/operations_async_client.py index f60d9e47..54a4b0c6 100644 --- a/google/api_core/operations_v1/operations_async_client.py +++ b/google/api_core/operations_v1/operations_async_client.py @@ -31,6 +31,7 @@ from google.longrunning import operations_pb2 import grpc + class OperationsAsyncClient: """Async client for interacting with long-running operations. diff --git a/tests/asyncio/test_grpc_helpers_async.py b/tests/asyncio/test_grpc_helpers_async.py index 03d671b1..93b646ed 100644 --- a/tests/asyncio/test_grpc_helpers_async.py +++ b/tests/asyncio/test_grpc_helpers_async.py @@ -292,7 +292,9 @@ def test_create_channel_implicit(grpc_secure_channel, default, composite_creds_c assert channel is grpc_secure_channel.return_value default.assert_called_once_with(scopes=None, default_scopes=None) - grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) + grpc_secure_channel.assert_called_once_with( + target, composite_creds, compression=None + ) @mock.patch("google.auth.transport.grpc.AuthMetadataPlugin", autospec=True) @@ -323,7 +325,9 @@ def test_create_channel_implicit_with_default_host( auth_metadata_plugin.assert_called_once_with( mock.sentinel.credentials, mock.sentinel.Request, default_host=default_host ) - grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) + grpc_secure_channel.assert_called_once_with( + target, composite_creds, compression=None + ) @mock.patch("grpc.composite_channel_credentials") @@ -344,7 +348,9 @@ def test_create_channel_implicit_with_ssl_creds( default.assert_called_once_with(scopes=None, default_scopes=None) composite_creds_call.assert_called_once_with(ssl_creds, mock.ANY) composite_creds = composite_creds_call.return_value - grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) + grpc_secure_channel.assert_called_once_with( + target, composite_creds, compression=None + ) @mock.patch("grpc.composite_channel_credentials") @@ -365,7 +371,9 @@ def test_create_channel_implicit_with_scopes( assert channel is grpc_secure_channel.return_value default.assert_called_once_with(scopes=["one", "two"], default_scopes=None) - grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) + grpc_secure_channel.assert_called_once_with( + target, composite_creds, compression=None + ) @mock.patch("grpc.composite_channel_credentials") @@ -388,7 +396,9 @@ def test_create_channel_implicit_with_default_scopes( assert channel is grpc_secure_channel.return_value default.assert_called_once_with(scopes=None, default_scopes=["three", "four"]) - grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) + grpc_secure_channel.assert_called_once_with( + target, composite_creds, compression=None + ) def test_create_channel_explicit_with_duplicate_credentials(): @@ -419,7 +429,9 @@ def test_create_channel_explicit(grpc_secure_channel, auth_creds, composite_cred mock.sentinel.credentials, scopes=None, default_scopes=None ) assert channel is grpc_secure_channel.return_value - grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) + grpc_secure_channel.assert_called_once_with( + target, composite_creds, compression=None + ) @mock.patch("grpc.composite_channel_credentials") @@ -438,7 +450,9 @@ def test_create_channel_explicit_scoped(grpc_secure_channel, composite_creds_cal credentials.with_scopes.assert_called_once_with(scopes, default_scopes=None) assert channel is grpc_secure_channel.return_value - grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) + grpc_secure_channel.assert_called_once_with( + target, composite_creds, compression=None + ) @mock.patch("grpc.composite_channel_credentials") @@ -461,7 +475,9 @@ def test_create_channel_explicit_default_scopes( scopes=None, default_scopes=default_scopes ) assert channel is grpc_secure_channel.return_value - grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) + grpc_secure_channel.assert_called_once_with( + target, composite_creds, compression=None + ) @mock.patch("grpc.composite_channel_credentials") @@ -482,7 +498,9 @@ def test_create_channel_explicit_with_quota_project( credentials.with_quota_project.assert_called_once_with("project-foo") assert channel is grpc_secure_channel.return_value - grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) + grpc_secure_channel.assert_called_once_with( + target, composite_creds, compression=None + ) @mock.patch("grpc.composite_channel_credentials") @@ -508,7 +526,9 @@ def test_create_channel_with_credentials_file( credentials_file, scopes=None, default_scopes=None ) assert channel is grpc_secure_channel.return_value - grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) + grpc_secure_channel.assert_called_once_with( + target, composite_creds, compression=None + ) @mock.patch("grpc.composite_channel_credentials") @@ -562,7 +582,9 @@ def test_create_channel_with_credentials_file_and_default_scopes( credentials_file, scopes=None, default_scopes=default_scopes ) assert channel is grpc_secure_channel.return_value - grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) + grpc_secure_channel.assert_called_once_with( + target, composite_creds, compression=None + ) @mock.patch("grpc.aio.secure_channel") diff --git a/tests/unit/gapic/test_method.py b/tests/unit/gapic/test_method.py index ecb056e4..c354c3b3 100644 --- a/tests/unit/gapic/test_method.py +++ b/tests/unit/gapic/test_method.py @@ -173,12 +173,14 @@ def test_wrap_method_with_overriding_retry_timeout_compression(unused_sleep): result = wrapped_method( retry=retry.Retry(retry.if_exception_type(exceptions.NotFound)), timeout=timeout.ConstantTimeout(22), - compression=default_compression + compression=default_compression, ) assert result == 42 assert method.call_count == 2 - method.assert_called_with(timeout=22, compression=default_compression, metadata=mock.ANY) + method.assert_called_with( + timeout=22, compression=default_compression, metadata=mock.ANY + ) def test_wrap_method_with_overriding_timeout_as_a_number(): diff --git a/tests/unit/test_grpc_helpers.py b/tests/unit/test_grpc_helpers.py index dd98d493..0653a256 100644 --- a/tests/unit/test_grpc_helpers.py +++ b/tests/unit/test_grpc_helpers.py @@ -368,7 +368,9 @@ def test_create_channel_implicit(grpc_secure_channel, default, composite_creds_c if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: - grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) + grpc_secure_channel.assert_called_once_with( + target, composite_creds, compression=None + ) @mock.patch("google.auth.transport.grpc.AuthMetadataPlugin", autospec=True) @@ -403,7 +405,9 @@ def test_create_channel_implicit_with_default_host( if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: - grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) + grpc_secure_channel.assert_called_once_with( + target, composite_creds, compression=None + ) @mock.patch("grpc.composite_channel_credentials") @@ -430,7 +434,9 @@ def test_create_channel_implicit_with_ssl_creds( if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: - grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) + grpc_secure_channel.assert_called_once_with( + target, composite_creds, compression=None + ) @mock.patch("grpc.composite_channel_credentials") @@ -455,7 +461,9 @@ def test_create_channel_implicit_with_scopes( if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: - grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) + grpc_secure_channel.assert_called_once_with( + target, composite_creds, compression=None + ) @mock.patch("grpc.composite_channel_credentials") @@ -480,7 +488,9 @@ def test_create_channel_implicit_with_default_scopes( if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: - grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) + grpc_secure_channel.assert_called_once_with( + target, composite_creds, compression=None + ) def test_create_channel_explicit_with_duplicate_credentials(): @@ -512,7 +522,9 @@ def test_create_channel_explicit(grpc_secure_channel, auth_creds, composite_cred if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: - grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) + grpc_secure_channel.assert_called_once_with( + target, composite_creds, compression=None + ) @mock.patch("grpc.composite_channel_credentials") @@ -536,7 +548,9 @@ def test_create_channel_explicit_scoped(grpc_secure_channel, composite_creds_cal if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: - grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) + grpc_secure_channel.assert_called_once_with( + target, composite_creds, compression=None + ) @mock.patch("grpc.composite_channel_credentials") @@ -564,7 +578,9 @@ def test_create_channel_explicit_default_scopes( if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: - grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) + grpc_secure_channel.assert_called_once_with( + target, composite_creds, compression=None + ) @mock.patch("grpc.composite_channel_credentials") @@ -590,7 +606,9 @@ def test_create_channel_explicit_with_quota_project( if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: - grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) + grpc_secure_channel.assert_called_once_with( + target, composite_creds, compression=None + ) @mock.patch("grpc.composite_channel_credentials") @@ -619,7 +637,9 @@ def test_create_channel_with_credentials_file( if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: - grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) + grpc_secure_channel.assert_called_once_with( + target, composite_creds, compression=None + ) @mock.patch("grpc.composite_channel_credentials") @@ -651,7 +671,9 @@ def test_create_channel_with_credentials_file_and_scopes( if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: - grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) + grpc_secure_channel.assert_called_once_with( + target, composite_creds, compression=None + ) @mock.patch("grpc.composite_channel_credentials") @@ -683,7 +705,9 @@ def test_create_channel_with_credentials_file_and_default_scopes( if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) else: - grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) + grpc_secure_channel.assert_called_once_with( + target, composite_creds, compression=None + ) @pytest.mark.skipif( @@ -829,7 +853,13 @@ def test_call_info(self): assert response == expected_response assert channel.requests == [("GetOperation", expected_request)] assert channel.GetOperation.calls == [ - (expected_request, 42, expected_metadata, expected_credentials, expected_compression) + ( + expected_request, + 42, + expected_metadata, + expected_credentials, + expected_compression, + ) ] def test_unary_unary(self): From 3b5c6571bff0314832fa4eee1db52a004830494c Mon Sep 17 00:00:00 2001 From: acocuzzo Date: Fri, 14 Apr 2023 16:56:03 -0400 Subject: [PATCH 10/25] fix unit tests --- tests/asyncio/gapic/test_method_async.py | 2 +- tests/asyncio/test_grpc_helpers_async.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/asyncio/gapic/test_method_async.py b/tests/asyncio/gapic/test_method_async.py index 9f95ce2d..d0cbc370 100644 --- a/tests/asyncio/gapic/test_method_async.py +++ b/tests/asyncio/gapic/test_method_async.py @@ -102,7 +102,7 @@ async def test_wrap_method_with_no_compression(): await wrapped_method(1, 2, meep="moop", compression=None) - method.assert_called_once_with(1, 2, meep="moop", compression=None) + method.assert_called_once_with(1, 2, meep="moop", metadata = mock.ANY) @pytest.mark.asyncio diff --git a/tests/asyncio/test_grpc_helpers_async.py b/tests/asyncio/test_grpc_helpers_async.py index 93b646ed..e44b5bdf 100644 --- a/tests/asyncio/test_grpc_helpers_async.py +++ b/tests/asyncio/test_grpc_helpers_async.py @@ -555,7 +555,7 @@ def test_create_channel_with_credentials_file_and_scopes( credentials_file, scopes=scopes, default_scopes=None ) assert channel is grpc_secure_channel.return_value - grpc_secure_channel.assert_called_once_with(target, composite_creds) + grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) @mock.patch("grpc.composite_channel_credentials") From 00cfbb2b536d2c9e4abde4bc2b99054f9d143545 Mon Sep 17 00:00:00 2001 From: acocuzzo Date: Sat, 6 May 2023 19:09:20 -0400 Subject: [PATCH 11/25] fix unit tests --- google/api_core/gapic_v1/method_async.py | 2 +- google/api_core/grpc_helpers.py | 10 ++++- google/api_core/operation.py | 9 +++- google/api_core/operation_async.py | 16 +------ .../abstract_operations_client.py | 3 ++ .../operations_v1/operations_async_client.py | 4 +- tests/asyncio/gapic/test_method_async.py | 42 ++++++++++++------- .../test_operations_async_client.py | 22 +++++++--- tests/asyncio/test_grpc_helpers_async.py | 26 ++++++++---- tests/unit/gapic/test_method.py | 22 ++++++---- tests/unit/test_grpc_helpers.py | 8 ++-- 11 files changed, 104 insertions(+), 60 deletions(-) diff --git a/google/api_core/gapic_v1/method_async.py b/google/api_core/gapic_v1/method_async.py index d0920d9b..24880756 100644 --- a/google/api_core/gapic_v1/method_async.py +++ b/google/api_core/gapic_v1/method_async.py @@ -37,7 +37,7 @@ def wrap_method( Returns: Callable: A new callable that takes optional ``retry``, ``timeout``, - and compression arguments and applies the common error mapping, + and ``compression`` arguments and applies the common error mapping, retry, timeout, metadata, and compression behavior to the low-level RPC method. """ func = grpc_helpers_async.wrap_errors(func) diff --git a/google/api_core/grpc_helpers.py b/google/api_core/grpc_helpers.py index c29560e3..33fccafc 100644 --- a/google/api_core/grpc_helpers.py +++ b/google/api_core/grpc_helpers.py @@ -16,6 +16,7 @@ import collections import functools +import logging import warnings import grpc @@ -277,7 +278,7 @@ def create_channel( default_scopes=None, default_host=None, compression=None, - **kwargs + **kwargs, ): """Create a secure channel with credentials. @@ -321,6 +322,10 @@ def create_channel( quota_project_id=quota_project_id, default_host=default_host, ) + logging.log( + logging.WARNING, f"creating secure_channels with compression={compression}" + ) + logging.log(logging.WARNING, f"creating secure_channels with kwargs={kwargs}") if HAS_GRPC_GCP: # pragma: NO COVER return grpc_gcp.secure_channel( @@ -359,12 +364,13 @@ def __init__(self, method, channel): """List[protobuf.Message]: All requests sent to this callable.""" self.calls = [] """List[Tuple]: All invocations of this callable. Each tuple is the - request, timeout, metadata, and credentials.""" + request, timeout, metadata, compression, and credentials.""" def __call__( self, request, timeout=None, metadata=None, credentials=None, compression=None ): self._channel.requests.append(_ChannelRequest(self._method, request)) + logging.log(logging.WARNING, f"__call__ called with compression={compression}") self.calls.append( _MethodCall(request, timeout, metadata, credentials, compression) ) diff --git a/google/api_core/operation.py b/google/api_core/operation.py index 37281800..21e92dd1 100644 --- a/google/api_core/operation.py +++ b/google/api_core/operation.py @@ -395,4 +395,11 @@ def from_gapic( metadata=grpc_metadata, compression=grpc_compression, ) - return Operation(operation, refresh, cancel, result_type, **kwargs) + return Operation( + operation, + refresh, + cancel, + result_type, + compression_type=grpc_compression, + **kwargs + ) diff --git a/google/api_core/operation_async.py b/google/api_core/operation_async.py index 9f795a0e..2fd341d9 100644 --- a/google/api_core/operation_async.py +++ b/google/api_core/operation_async.py @@ -44,7 +44,6 @@ def my_callback(future): from google.api_core.future import async_future from google.longrunning import operations_pb2 from google.rpc import code_pb2 -from grpc import Compression class AsyncOperation(async_future.AsyncFuture): @@ -59,7 +58,6 @@ class AsyncOperation(async_future.AsyncFuture): the operation. result_type (func:`type`): The protobuf type for the operation's result. - compression_type (Compression): The compression method for an operation. metadata_type (func:`type`): The protobuf type for the operation's metadata. retry (google.api_core.retry.Retry): The retry configuration used @@ -74,7 +72,6 @@ def __init__( refresh, cancel, result_type, - compression_type=Compression.NoCompression, metadata_type=None, retry=async_future.DEFAULT_RETRY, ): @@ -84,7 +81,6 @@ def __init__( self._cancel = cancel self._result_type = result_type self._metadata_type = metadata_type - self._compression_type = compression_type self._completion_lock = threading.Lock() # Invoke this in case the operation came back already complete. self._set_result_from_operation() @@ -193,14 +189,7 @@ async def cancelled(self): ) -def from_gapic( - operation, - operations_client, - result_type, - grpc_compression=Compression.NoCompression, - grpc_metadata=None, - **kwargs -): +def from_gapic(operation, operations_client, result_type, grpc_metadata=None, **kwargs): """Create an operation future from a gapic client. This interacts with the long-running operations `service`_ (specific @@ -217,7 +206,6 @@ def from_gapic( result_type (:func:`type`): The protobuf result type. grpc_metadata (Optional[List[Tuple[str, str]]]): Additional metadata to pass to the rpc. - grpc_compression (grpc.Compression): Type of compression for the rpc. kwargs: Keyword args passed into the :class:`Operation` constructor. Returns: @@ -227,13 +215,11 @@ def from_gapic( refresh = functools.partial( operations_client.get_operation, operation.name, - compression=grpc_compression, metadata=grpc_metadata, ) cancel = functools.partial( operations_client.cancel_operation, operation.name, - compression=grpc_compression, metadata=grpc_metadata, ) return AsyncOperation(operation, refresh, cancel, result_type, **kwargs) diff --git a/google/api_core/operations_v1/abstract_operations_client.py b/google/api_core/operations_v1/abstract_operations_client.py index 745eb77d..714c2aae 100644 --- a/google/api_core/operations_v1/abstract_operations_client.py +++ b/google/api_core/operations_v1/abstract_operations_client.py @@ -431,6 +431,7 @@ def list_operations( request, retry=retry, timeout=timeout, + compression=compression, metadata=metadata, ) @@ -493,6 +494,7 @@ def get_operation( request, retry=retry, timeout=timeout, + compression=compression, metadata=metadata, ) @@ -545,6 +547,7 @@ def delete_operation( request, retry=retry, timeout=timeout, + compression=compression, metadata=metadata, ) diff --git a/google/api_core/operations_v1/operations_async_client.py b/google/api_core/operations_v1/operations_async_client.py index 54a4b0c6..3175d184 100644 --- a/google/api_core/operations_v1/operations_async_client.py +++ b/google/api_core/operations_v1/operations_async_client.py @@ -29,7 +29,7 @@ from google.api_core import retry as retries from google.api_core import timeout as timeouts from google.longrunning import operations_pb2 -import grpc +from grpc import Compression class OperationsAsyncClient: @@ -60,7 +60,7 @@ def __init__(self, channel, client_config=None): ) default_timeout = timeouts.TimeToDeadlineTimeout(timeout=600.0) - default_compression = grpc.Compression.NoCompression + default_compression = Compression.NoCompression self._get_operation = gapic_v1.method_async.wrap_method( self.operations_stub.GetOperation, diff --git a/tests/asyncio/gapic/test_method_async.py b/tests/asyncio/gapic/test_method_async.py index d0cbc370..ee206979 100644 --- a/tests/asyncio/gapic/test_method_async.py +++ b/tests/asyncio/gapic/test_method_async.py @@ -18,8 +18,7 @@ import pytest try: - from grpc import aio - from grpc import Compression + from grpc import aio, Compression except ImportError: pytest.skip("No GRPC", allow_module_level=True) @@ -102,7 +101,7 @@ async def test_wrap_method_with_no_compression(): await wrapped_method(1, 2, meep="moop", compression=None) - method.assert_called_once_with(1, 2, meep="moop", metadata = mock.ANY) + method.assert_called_once_with(1, 2, meep="moop", metadata=mock.ANY) @pytest.mark.asyncio @@ -111,11 +110,15 @@ async def test_wrap_method_with_custom_compression(): fake_call = grpc_helpers_async.FakeUnaryUnaryCall() method = mock.Mock(spec=aio.UnaryUnaryMultiCallable, return_value=fake_call) - wrapped_method = gapic_v1.method_async.wrap_method(method) + wrapped_method = gapic_v1.method_async.wrap_method( + method, default_compression=compression + ) - await wrapped_method(1, 2, meep="moop", compression=compression) + await wrapped_method(1, 2, meep="moop", compression=Compression.Deflate) - method.assert_called_once_with(1, 2, meep="moop", compression=compression) + method.assert_called_once_with( + 1, 2, meep="moop", metadata=mock.ANY, compression=Compression.Deflate + ) @pytest.mark.asyncio @@ -152,7 +155,7 @@ async def test_invoke_wrapped_method_with_metadata_as_none(): @mock.patch("asyncio.sleep") @pytest.mark.asyncio -async def test_wrap_method_with_default_retry_and_timeout(unused_sleep): +async def test_wrap_method_with_default_retry_timeout_and_compression(unused_sleep): fake_call = grpc_helpers_async.FakeUnaryUnaryCall(42) method = mock.Mock( spec=aio.UnaryUnaryMultiCallable, @@ -161,15 +164,18 @@ async def test_wrap_method_with_default_retry_and_timeout(unused_sleep): default_retry = retry_async.AsyncRetry() default_timeout = timeout.ConstantTimeout(60) + default_compression = Compression.Gzip wrapped_method = gapic_v1.method_async.wrap_method( - method, default_retry, default_timeout + method, default_retry, default_timeout, default_compression ) result = await wrapped_method() assert result == 42 assert method.call_count == 2 - method.assert_called_with(timeout=60, metadata=mock.ANY) + method.assert_called_with( + timeout=60, compression=default_compression, metadata=mock.ANY + ) @mock.patch("asyncio.sleep") @@ -183,23 +189,27 @@ async def test_wrap_method_with_default_retry_and_timeout_using_sentinel(unused_ default_retry = retry_async.AsyncRetry() default_timeout = timeout.ConstantTimeout(60) + default_compression = Compression.Gzip wrapped_method = gapic_v1.method_async.wrap_method( - method, default_retry, default_timeout + method, default_retry, default_timeout, default_compression ) result = await wrapped_method( retry=gapic_v1.method_async.DEFAULT, timeout=gapic_v1.method_async.DEFAULT, + compression=gapic_v1.method_async.DEFAULT, ) assert result == 42 assert method.call_count == 2 - method.assert_called_with(timeout=60, metadata=mock.ANY) + method.assert_called_with( + timeout=60, compression=Compression.Gzip, metadata=mock.ANY + ) @mock.patch("asyncio.sleep") @pytest.mark.asyncio -async def test_wrap_method_with_overriding_retry_and_timeout(unused_sleep): +async def test_wrap_method_with_overriding_retry_timeout_and_compression(unused_sleep): fake_call = grpc_helpers_async.FakeUnaryUnaryCall(42) method = mock.Mock( spec=aio.UnaryUnaryMultiCallable, @@ -208,8 +218,9 @@ async def test_wrap_method_with_overriding_retry_and_timeout(unused_sleep): default_retry = retry_async.AsyncRetry() default_timeout = timeout.ConstantTimeout(60) + default_compression = Compression.Gzip wrapped_method = gapic_v1.method_async.wrap_method( - method, default_retry, default_timeout + method, default_retry, default_timeout, default_compression ) result = await wrapped_method( @@ -217,11 +228,14 @@ async def test_wrap_method_with_overriding_retry_and_timeout(unused_sleep): retry_async.if_exception_type(exceptions.NotFound) ), timeout=timeout.ConstantTimeout(22), + compression=Compression.Deflate, ) assert result == 42 assert method.call_count == 2 - method.assert_called_with(timeout=22, metadata=mock.ANY) + method.assert_called_with( + timeout=22, compression=Compression.Deflate, metadata=mock.ANY + ) @pytest.mark.asyncio diff --git a/tests/asyncio/operations_v1/test_operations_async_client.py b/tests/asyncio/operations_v1/test_operations_async_client.py index 34236da7..19ac9b56 100644 --- a/tests/asyncio/operations_v1/test_operations_async_client.py +++ b/tests/asyncio/operations_v1/test_operations_async_client.py @@ -16,7 +16,7 @@ import pytest try: - from grpc import aio + from grpc import aio, Compression except ImportError: # pragma: NO COVER pytest.skip("No GRPC", allow_module_level=True) @@ -42,10 +42,13 @@ async def test_get_operation(): ) client = operations_v1.OperationsAsyncClient(mocked_channel) - response = await client.get_operation("name", metadata=[("header", "foo")]) + response = await client.get_operation( + "name", metadata=[("header", "foo")], compression=Compression.Gzip + ) assert method.call_count == 1 assert tuple(method.call_args_list[0])[0][0].name == "name" assert ("header", "foo") in tuple(method.call_args_list[0])[1]["metadata"] + assert tuple(method.call_args_list[0])[1]["compression"] == Compression.Gzip assert ("x-goog-request-params", "name=name") in tuple(method.call_args_list[0])[1][ "metadata" ] @@ -63,7 +66,9 @@ async def test_list_operations(): mocked_channel, method, fake_call = _mock_grpc_objects(list_response) client = operations_v1.OperationsAsyncClient(mocked_channel) - pager = await client.list_operations("name", "filter", metadata=[("header", "foo")]) + pager = await client.list_operations( + "name", "filter", metadata=[("header", "foo")], compression=Compression.Gzip + ) assert isinstance(pager, page_iterator_async.AsyncIterator) responses = [] @@ -74,6 +79,7 @@ async def test_list_operations(): assert method.call_count == 1 assert ("header", "foo") in tuple(method.call_args_list[0])[1]["metadata"] + assert tuple(method.call_args_list[0])[1]["compression"] == Compression.Gzip assert ("x-goog-request-params", "name=name") in tuple(method.call_args_list[0])[1][ "metadata" ] @@ -88,11 +94,14 @@ async def test_delete_operation(): mocked_channel, method, fake_call = _mock_grpc_objects(empty_pb2.Empty()) client = operations_v1.OperationsAsyncClient(mocked_channel) - await client.delete_operation("name", metadata=[("header", "foo")]) + await client.delete_operation( + "name", metadata=[("header", "foo")], compression=Compression.Gzip + ) assert method.call_count == 1 assert tuple(method.call_args_list[0])[0][0].name == "name" assert ("header", "foo") in tuple(method.call_args_list[0])[1]["metadata"] + assert tuple(method.call_args_list[0])[1]["compression"] == Compression.Gzip assert ("x-goog-request-params", "name=name") in tuple(method.call_args_list[0])[1][ "metadata" ] @@ -103,11 +112,14 @@ async def test_cancel_operation(): mocked_channel, method, fake_call = _mock_grpc_objects(empty_pb2.Empty()) client = operations_v1.OperationsAsyncClient(mocked_channel) - await client.cancel_operation("name", metadata=[("header", "foo")]) + await client.cancel_operation( + "name", metadata=[("header", "foo")], compression=Compression.Gzip + ) assert method.call_count == 1 assert tuple(method.call_args_list[0])[0][0].name == "name" assert ("header", "foo") in tuple(method.call_args_list[0])[1]["metadata"] + assert tuple(method.call_args_list[0])[1]["compression"] == Compression.Gzip assert ("x-goog-request-params", "name=name") in tuple(method.call_args_list[0])[1][ "metadata" ] diff --git a/tests/asyncio/test_grpc_helpers_async.py b/tests/asyncio/test_grpc_helpers_async.py index e44b5bdf..95242f6b 100644 --- a/tests/asyncio/test_grpc_helpers_async.py +++ b/tests/asyncio/test_grpc_helpers_async.py @@ -390,14 +390,14 @@ def test_create_channel_implicit_with_default_scopes( composite_creds = composite_creds_call.return_value channel = grpc_helpers_async.create_channel( - target, default_scopes=["three", "four"] + target, default_scopes=["three", "four"], compression=grpc.Compression.Gzip ) assert channel is grpc_secure_channel.return_value default.assert_called_once_with(scopes=None, default_scopes=["three", "four"]) grpc_secure_channel.assert_called_once_with( - target, composite_creds, compression=None + target, composite_creds, compression=grpc.Compression.Gzip ) @@ -422,7 +422,7 @@ def test_create_channel_explicit(grpc_secure_channel, auth_creds, composite_cred composite_creds = composite_creds_call.return_value channel = grpc_helpers_async.create_channel( - target, credentials=mock.sentinel.credentials + target, credentials=mock.sentinel.credentials, compression=grpc.Compression.Gzip ) auth_creds.assert_called_once_with( @@ -430,7 +430,7 @@ def test_create_channel_explicit(grpc_secure_channel, auth_creds, composite_cred ) assert channel is grpc_secure_channel.return_value grpc_secure_channel.assert_called_once_with( - target, composite_creds, compression=None + target, composite_creds, compression=grpc.Compression.Gzip ) @@ -445,13 +445,16 @@ def test_create_channel_explicit_scoped(grpc_secure_channel, composite_creds_cal credentials.requires_scopes = True channel = grpc_helpers_async.create_channel( - target, credentials=credentials, scopes=scopes + target, + credentials=credentials, + scopes=scopes, + compression=grpc.Compression.Gzip, ) credentials.with_scopes.assert_called_once_with(scopes, default_scopes=None) assert channel is grpc_secure_channel.return_value grpc_secure_channel.assert_called_once_with( - target, composite_creds, compression=None + target, composite_creds, compression=grpc.Compression.Gzip ) @@ -468,7 +471,10 @@ def test_create_channel_explicit_default_scopes( credentials.requires_scopes = True channel = grpc_helpers_async.create_channel( - target, credentials=credentials, default_scopes=default_scopes + target, + credentials=credentials, + default_scopes=default_scopes, + compression=grpc.Compression.Gzip, ) credentials.with_scopes.assert_called_once_with( @@ -476,7 +482,7 @@ def test_create_channel_explicit_default_scopes( ) assert channel is grpc_secure_channel.return_value grpc_secure_channel.assert_called_once_with( - target, composite_creds, compression=None + target, composite_creds, compression=grpc.Compression.Gzip ) @@ -555,7 +561,9 @@ def test_create_channel_with_credentials_file_and_scopes( credentials_file, scopes=scopes, default_scopes=None ) assert channel is grpc_secure_channel.return_value - grpc_secure_channel.assert_called_once_with(target, composite_creds, compression=None) + grpc_secure_channel.assert_called_once_with( + target, composite_creds, compression=None + ) @mock.patch("grpc.composite_channel_credentials") diff --git a/tests/unit/gapic/test_method.py b/tests/unit/gapic/test_method.py index c354c3b3..0623a5bc 100644 --- a/tests/unit/gapic/test_method.py +++ b/tests/unit/gapic/test_method.py @@ -121,21 +121,24 @@ def test_invoke_wrapped_method_with_metadata_as_none(): @mock.patch("time.sleep") -def test_wrap_method_with_default_retry_and_timeout(unused_sleep): +def test_wrap_method_with_default_retry_and_timeout_and_compression(unused_sleep): method = mock.Mock( spec=["__call__"], side_effect=[exceptions.InternalServerError(None), 42] ) default_retry = retry.Retry() default_timeout = timeout.ConstantTimeout(60) + default_compression = grpc.Compression.Gzip wrapped_method = google.api_core.gapic_v1.method.wrap_method( - method, default_retry, default_timeout + method, default_retry, default_timeout, default_compression ) result = wrapped_method() assert result == 42 assert method.call_count == 2 - method.assert_called_with(timeout=60, metadata=mock.ANY) + method.assert_called_with( + timeout=60, compression=default_compression, metadata=mock.ANY + ) @mock.patch("time.sleep") @@ -145,23 +148,26 @@ def test_wrap_method_with_default_retry_and_timeout_using_sentinel(unused_sleep) ) default_retry = retry.Retry() default_timeout = timeout.ConstantTimeout(60) + default_compression = grpc.Compression.Gzip wrapped_method = google.api_core.gapic_v1.method.wrap_method( - method, default_retry, default_timeout + method, default_retry, default_timeout, default_compression ) result = wrapped_method( retry=google.api_core.gapic_v1.method.DEFAULT, timeout=google.api_core.gapic_v1.method.DEFAULT, + compression=google.api_core.gapic_v1.method.DEFAULT, ) assert result == 42 assert method.call_count == 2 - method.assert_called_with(timeout=60, metadata=mock.ANY) + method.assert_called_with( + timeout=60, compression=default_compression, metadata=mock.ANY + ) @mock.patch("time.sleep") def test_wrap_method_with_overriding_retry_timeout_compression(unused_sleep): - method = mock.Mock(spec=["__call__"], side_effect=[exceptions.NotFound(None), 42]) default_retry = retry.Retry() default_timeout = timeout.ConstantTimeout(60) @@ -173,13 +179,13 @@ def test_wrap_method_with_overriding_retry_timeout_compression(unused_sleep): result = wrapped_method( retry=retry.Retry(retry.if_exception_type(exceptions.NotFound)), timeout=timeout.ConstantTimeout(22), - compression=default_compression, + compression=grpc.Compression.Deflate, ) assert result == 42 assert method.call_count == 2 method.assert_called_with( - timeout=22, compression=default_compression, metadata=mock.ANY + timeout=22, compression=grpc.Compression.Deflate, metadata=mock.ANY ) diff --git a/tests/unit/test_grpc_helpers.py b/tests/unit/test_grpc_helpers.py index 0653a256..195fcb4f 100644 --- a/tests/unit/test_grpc_helpers.py +++ b/tests/unit/test_grpc_helpers.py @@ -359,17 +359,19 @@ def test_create_channel_implicit(grpc_secure_channel, default, composite_creds_c target = "example.com:443" composite_creds = composite_creds_call.return_value - channel = grpc_helpers.create_channel(target) + channel = grpc_helpers.create_channel(target, compression=grpc.Compression.Gzip) assert channel is grpc_secure_channel.return_value default.assert_called_once_with(scopes=None, default_scopes=None) if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER - grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) + grpc_secure_channel.assert_called_once_with( + target, composite_creds, None, compression=grpc.Compression.Gzip + ) else: grpc_secure_channel.assert_called_once_with( - target, composite_creds, compression=None + target, composite_creds, compression=grpc.Compression.Gzip ) From 8b0c7db3866e510aeac63f0d7fba9864ebc8b1d3 Mon Sep 17 00:00:00 2001 From: acocuzzo Date: Sat, 6 May 2023 19:18:13 -0400 Subject: [PATCH 12/25] fix operation --- google/api_core/operation.py | 46 +++--------------------------------- 1 file changed, 3 insertions(+), 43 deletions(-) diff --git a/google/api_core/operation.py b/google/api_core/operation.py index 21e92dd1..4b9c9a58 100644 --- a/google/api_core/operation.py +++ b/google/api_core/operation.py @@ -45,7 +45,6 @@ def my_callback(future): from google.longrunning import operations_pb2 from google.protobuf import json_format from google.rpc import code_pb2 -from grpc import Compression class Operation(polling.PollingFuture): @@ -62,7 +61,6 @@ class Operation(polling.PollingFuture): result. metadata_type (func:`type`): The protobuf type for the operation's metadata. - compression_type (Compression): The compression method for an operation. polling (google.api_core.retry.Retry): The configuration used for polling. This parameter controls how often :meth:`done` is polled. If the ``timeout`` argument is specified in the :meth:`result` method, it will @@ -79,7 +77,6 @@ def __init__( cancel, result_type, metadata_type=None, - compression_type=Compression.NoCompression, polling=polling.DEFAULT_POLLING, **kwargs ): @@ -89,7 +86,6 @@ def __init__( self._cancel = cancel self._result_type = result_type self._metadata_type = metadata_type - self._compression_type = compression_type self._completion_lock = threading.Lock() # Invoke this in case the operation came back already complete. self._set_result_from_operation() @@ -109,14 +105,6 @@ def metadata(self): self._metadata_type, self._operation.metadata ) - @property - def compression(self): - """Compression: the current operation compression.""" - if not self._operation.HasField("compression"): - return None - - return self._compression_type - @classmethod def deserialize(self, payload): """Deserialize a ``google.longrunning.Operation`` protocol buffer. @@ -303,14 +291,7 @@ def _cancel_grpc(operations_stub, operation_name): operations_stub.CancelOperation(request_pb) -def from_grpc( - operation, - operations_stub, - result_type, - grpc_compression=Compression.NoCompression, - grpc_metadata=None, - **kwargs -): +def from_grpc(operation, operations_stub, result_type, grpc_metadata=None, **kwargs): """Create an operation future using a gRPC client. This interacts with the long-running operations `service`_ (specific @@ -327,7 +308,6 @@ def from_grpc( result_type (:func:`type`): The protobuf result type. grpc_metadata (Optional[List[Tuple[str, str]]]): Additional metadata to pass to the rpc. - grpc_compression (grpc.Compression): Type of compression for the rpc. kwargs: Keyword args passed into the :class:`Operation` constructor. Returns: @@ -338,27 +318,18 @@ def from_grpc( _refresh_grpc, operations_stub, operation.name, - compression=grpc_compression, metadata=grpc_metadata, ) cancel = functools.partial( _cancel_grpc, operations_stub, operation.name, - compression=grpc_compression, metadata=grpc_metadata, ) return Operation(operation, refresh, cancel, result_type, **kwargs) -def from_gapic( - operation, - operations_client, - result_type, - grpc_metadata=None, - grpc_compression=Compression.NoCompression, - **kwargs -): +def from_gapic(operation, operations_client, result_type, grpc_metadata=None, **kwargs): """Create an operation future from a gapic client. This interacts with the long-running operations `service`_ (specific @@ -375,8 +346,6 @@ def from_gapic( result_type (:func:`type`): The protobuf result type. grpc_metadata (Optional[List[Tuple[str, str]]]): Additional metadata to pass to the rpc. - grpc_compression (grpc.Comression): Additional metadata to pass - to the rpc. kwargs: Keyword args passed into the :class:`Operation` constructor. Returns: @@ -387,19 +356,10 @@ def from_gapic( operations_client.get_operation, operation.name, metadata=grpc_metadata, - compression=grpc_compression, ) cancel = functools.partial( operations_client.cancel_operation, operation.name, metadata=grpc_metadata, - compression=grpc_compression, - ) - return Operation( - operation, - refresh, - cancel, - result_type, - compression_type=grpc_compression, - **kwargs ) + return Operation(operation, refresh, cancel, result_type, **kwargs) From e91798c90fc07939b57a71a43b57d81fb0c6030a Mon Sep 17 00:00:00 2001 From: acocuzzo Date: Sat, 6 May 2023 19:21:58 -0400 Subject: [PATCH 13/25] remove unused import --- google/api_core/gapic_v1/method.py | 1 - 1 file changed, 1 deletion(-) diff --git a/google/api_core/gapic_v1/method.py b/google/api_core/gapic_v1/method.py index da59360d..f05009cc 100644 --- a/google/api_core/gapic_v1/method.py +++ b/google/api_core/gapic_v1/method.py @@ -24,7 +24,6 @@ from google.api_core import grpc_helpers from google.api_core.gapic_v1 import client_info from google.api_core.timeout import TimeToDeadlineTimeout -from grpc import Compression USE_DEFAULT_METADATA = object() From fb7522542a2a003d4d970f982d744b3d9b7b437e Mon Sep 17 00:00:00 2001 From: acocuzzo Date: Sat, 6 May 2023 19:46:42 -0400 Subject: [PATCH 14/25] remove compression for grpc_gcp.secure_channel call --- google/api_core/grpc_helpers.py | 15 +++++++-------- tests/unit/test_grpc_helpers.py | 26 ++++++++++++-------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/google/api_core/grpc_helpers.py b/google/api_core/grpc_helpers.py index 33fccafc..2833a5d8 100644 --- a/google/api_core/grpc_helpers.py +++ b/google/api_core/grpc_helpers.py @@ -52,6 +52,8 @@ # The list of gRPC Callable interfaces that return iterators. _STREAM_WRAP_CLASSES = (grpc.UnaryStreamMultiCallable, grpc.StreamStreamMultiCallable) +_LOGGER = logging.getLogger(__name__) + def _patch_callable_name(callable_): """Fix-up gRPC callable attributes. @@ -322,15 +324,13 @@ def create_channel( quota_project_id=quota_project_id, default_host=default_host, ) - logging.log( - logging.WARNING, f"creating secure_channels with compression={compression}" - ) - logging.log(logging.WARNING, f"creating secure_channels with kwargs={kwargs}") if HAS_GRPC_GCP: # pragma: NO COVER - return grpc_gcp.secure_channel( - target, composite_credentials, compression=compression, **kwargs - ) + if compression is not None and compression != grpc.Compression.NoCompression: + _LOGGER.debug( + "Compression argument is being ignored for grpc_gcp.secure_channel creation." + ) + return grpc_gcp.secure_channel(target, composite_credentials, **kwargs) return grpc.secure_channel( target, composite_credentials, compression=compression, **kwargs ) @@ -370,7 +370,6 @@ def __call__( self, request, timeout=None, metadata=None, credentials=None, compression=None ): self._channel.requests.append(_ChannelRequest(self._method, request)) - logging.log(logging.WARNING, f"__call__ called with compression={compression}") self.calls.append( _MethodCall(request, timeout, metadata, credentials, compression) ) diff --git a/tests/unit/test_grpc_helpers.py b/tests/unit/test_grpc_helpers.py index 195fcb4f..4eccbcaa 100644 --- a/tests/unit/test_grpc_helpers.py +++ b/tests/unit/test_grpc_helpers.py @@ -366,9 +366,7 @@ def test_create_channel_implicit(grpc_secure_channel, default, composite_creds_c default.assert_called_once_with(scopes=None, default_scopes=None) if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER - grpc_secure_channel.assert_called_once_with( - target, composite_creds, None, compression=grpc.Compression.Gzip - ) + grpc_secure_channel.assert_called_once_with(target, composite_creds, None) else: grpc_secure_channel.assert_called_once_with( target, composite_creds, compression=grpc.Compression.Gzip @@ -405,7 +403,7 @@ def test_create_channel_implicit_with_default_host( ) if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER - grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) + grpc_secure_channel.assert_called_once_with(target, composite_creds, None) else: grpc_secure_channel.assert_called_once_with( target, composite_creds, compression=None @@ -434,7 +432,7 @@ def test_create_channel_implicit_with_ssl_creds( composite_creds = composite_creds_call.return_value if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER - grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) + grpc_secure_channel.assert_called_once_with(target, composite_creds, None) else: grpc_secure_channel.assert_called_once_with( target, composite_creds, compression=None @@ -461,7 +459,7 @@ def test_create_channel_implicit_with_scopes( default.assert_called_once_with(scopes=["one", "two"], default_scopes=None) if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER - grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) + grpc_secure_channel.assert_called_once_with(target, composite_creds, None) else: grpc_secure_channel.assert_called_once_with( target, composite_creds, compression=None @@ -488,7 +486,7 @@ def test_create_channel_implicit_with_default_scopes( default.assert_called_once_with(scopes=None, default_scopes=["three", "four"]) if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER - grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) + grpc_secure_channel.assert_called_once_with(target, composite_creds, None) else: grpc_secure_channel.assert_called_once_with( target, composite_creds, compression=None @@ -522,7 +520,7 @@ def test_create_channel_explicit(grpc_secure_channel, auth_creds, composite_cred assert channel is grpc_secure_channel.return_value if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER - grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) + grpc_secure_channel.assert_called_once_with(target, composite_creds, None) else: grpc_secure_channel.assert_called_once_with( target, composite_creds, compression=None @@ -548,7 +546,7 @@ def test_create_channel_explicit_scoped(grpc_secure_channel, composite_creds_cal assert channel is grpc_secure_channel.return_value if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER - grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) + grpc_secure_channel.assert_called_once_with(target, composite_creds, None) else: grpc_secure_channel.assert_called_once_with( target, composite_creds, compression=None @@ -578,7 +576,7 @@ def test_create_channel_explicit_default_scopes( assert channel is grpc_secure_channel.return_value if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER - grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) + grpc_secure_channel.assert_called_once_with(target, composite_creds, None) else: grpc_secure_channel.assert_called_once_with( target, composite_creds, compression=None @@ -606,7 +604,7 @@ def test_create_channel_explicit_with_quota_project( assert channel is grpc_secure_channel.return_value if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER - grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) + grpc_secure_channel.assert_called_once_with(target, composite_creds, None) else: grpc_secure_channel.assert_called_once_with( target, composite_creds, compression=None @@ -637,7 +635,7 @@ def test_create_channel_with_credentials_file( assert channel is grpc_secure_channel.return_value if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER - grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) + grpc_secure_channel.assert_called_once_with(target, composite_creds, None) else: grpc_secure_channel.assert_called_once_with( target, composite_creds, compression=None @@ -671,7 +669,7 @@ def test_create_channel_with_credentials_file_and_scopes( assert channel is grpc_secure_channel.return_value if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER - grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) + grpc_secure_channel.assert_called_once_with(target, composite_creds, None) else: grpc_secure_channel.assert_called_once_with( target, composite_creds, compression=None @@ -705,7 +703,7 @@ def test_create_channel_with_credentials_file_and_default_scopes( assert channel is grpc_secure_channel.return_value if grpc_helpers.HAS_GRPC_GCP: # pragma: NO COVER - grpc_secure_channel.assert_called_once_with(target, composite_creds, None, None) + grpc_secure_channel.assert_called_once_with(target, composite_creds, None) else: grpc_secure_channel.assert_called_once_with( target, composite_creds, compression=None From 909eed1fa1232ae6bcc7b75607e33f9a3f2b31b3 Mon Sep 17 00:00:00 2001 From: acocuzzo Date: Mon, 8 May 2023 18:20:22 -0400 Subject: [PATCH 15/25] fix method.py comment --- google/api_core/gapic_v1/method.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google/api_core/gapic_v1/method.py b/google/api_core/gapic_v1/method.py index f05009cc..e6df1332 100644 --- a/google/api_core/gapic_v1/method.py +++ b/google/api_core/gapic_v1/method.py @@ -140,7 +140,7 @@ def wrap_method( ): """Wrap an RPC method with common behavior. - This applies common error wrapping, retry, timeout, and compression behavior a function. + This applies common error wrapping, retry, timeout, and compression behavior to a function. The wrapped function will take optional ``retry``, ``timeout``, and ``compression`` arguments. From 735de81383bf8397929d84627f6b4b20cedbfbe7 Mon Sep 17 00:00:00 2001 From: Anna Cocuzzo <63511057+acocuzzo@users.noreply.github.com> Date: Fri, 1 Sep 2023 15:11:42 -0400 Subject: [PATCH 16/25] Update grpc_helpers.py Remove experimental disclaimer --- google/api_core/grpc_helpers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/google/api_core/grpc_helpers.py b/google/api_core/grpc_helpers.py index 2833a5d8..f52e180a 100644 --- a/google/api_core/grpc_helpers.py +++ b/google/api_core/grpc_helpers.py @@ -303,7 +303,6 @@ def create_channel( default_host (str): The default endpoint. e.g., "pubsub.googleapis.com". compression (grpc.Compression): An optional value indicating the compression method to be used over the lifetime of the channel. - This is an EXPERIMENTAL option. kwargs: Additional key-word args passed to :func:`grpc_gcp.secure_channel` or :func:`grpc.secure_channel`. Note: `grpc_gcp` is only supported in environments with protobuf < 4.0.0. From de9c9de4f2501ca8a41f8f97291ae2f8a81509f8 Mon Sep 17 00:00:00 2001 From: Anna Cocuzzo <63511057+acocuzzo@users.noreply.github.com> Date: Fri, 1 Sep 2023 15:12:42 -0400 Subject: [PATCH 17/25] Update grpc_helpers_async.py Remove experimental disclaimer --- google/api_core/grpc_helpers_async.py | 1 - 1 file changed, 1 deletion(-) diff --git a/google/api_core/grpc_helpers_async.py b/google/api_core/grpc_helpers_async.py index 872e24ee..d1f69d98 100644 --- a/google/api_core/grpc_helpers_async.py +++ b/google/api_core/grpc_helpers_async.py @@ -236,7 +236,6 @@ def create_channel( default_host (str): The default endpoint. e.g., "pubsub.googleapis.com". compression (grpc.Compression): An optional value indicating the compression method to be used over the lifetime of the channel. - This is an EXPERIMENTAL option. kwargs: Additional key-word args passed to :func:`aio.secure_channel`. Returns: From b1332d800debaf65af4518eec64357a7024b20c7 Mon Sep 17 00:00:00 2001 From: Anna Cocuzzo <63511057+acocuzzo@users.noreply.github.com> Date: Sat, 2 Sep 2023 16:27:32 -0400 Subject: [PATCH 18/25] Update google/api_core/operations_v1/operations_client.py Co-authored-by: Anthonios Partheniou --- google/api_core/operations_v1/operations_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google/api_core/operations_v1/operations_client.py b/google/api_core/operations_v1/operations_client.py index 1cbfa63d..be8a37b6 100644 --- a/google/api_core/operations_v1/operations_client.py +++ b/google/api_core/operations_v1/operations_client.py @@ -208,7 +208,7 @@ def list_operations( configuration is used. If ``None``, then the RPC method will not time out. compression (grpc.Compression): An element of grpc.compression - e.g. grpc.compression.Gzip. This is an EXPERIMENTAL option. + e.g. grpc.compression.Gzip. metadata (Optional[List[Tuple[str, str]]]): Additional gRPC metadata. From c661ecc62d3f2f781033f8c6d65478ff127cb48b Mon Sep 17 00:00:00 2001 From: Anna Cocuzzo <63511057+acocuzzo@users.noreply.github.com> Date: Sat, 2 Sep 2023 16:27:41 -0400 Subject: [PATCH 19/25] Update google/api_core/operations_v1/operations_client.py Co-authored-by: Anthonios Partheniou --- google/api_core/operations_v1/operations_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google/api_core/operations_v1/operations_client.py b/google/api_core/operations_v1/operations_client.py index be8a37b6..382c9f49 100644 --- a/google/api_core/operations_v1/operations_client.py +++ b/google/api_core/operations_v1/operations_client.py @@ -350,7 +350,7 @@ def delete_operation( configuration is used. If ``None``, then the RPC method will not time out. compression (grpc.Compression): An element of grpc.compression - e.g. grpc.compression.Gzip. This is an EXPERIMENTAL option. + e.g. grpc.compression.Gzip. metadata (Optional[List[Tuple[str, str]]]): Additional gRPC metadata. From 8ffa4da81e6bd7855caa38ff00c0efc671942dee Mon Sep 17 00:00:00 2001 From: Anna Cocuzzo <63511057+acocuzzo@users.noreply.github.com> Date: Sat, 2 Sep 2023 16:28:01 -0400 Subject: [PATCH 20/25] Update google/api_core/operations_v1/operations_client.py Co-authored-by: Anthonios Partheniou --- google/api_core/operations_v1/operations_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google/api_core/operations_v1/operations_client.py b/google/api_core/operations_v1/operations_client.py index 382c9f49..d9678286 100644 --- a/google/api_core/operations_v1/operations_client.py +++ b/google/api_core/operations_v1/operations_client.py @@ -290,7 +290,7 @@ def cancel_operation( configuration is used. If ``None``, then the RPC method will not time out. compression (grpc.Compression): An element of grpc.compression - e.g. grpc.compression.Gzip. This is an EXPERIMENTAL option. + e.g. grpc.compression.Gzip. metadata (Optional[List[Tuple[str, str]]]): Additional gRPC metadata. From 26438ba809a87e9a89c3aa0b7860f84b6b57f382 Mon Sep 17 00:00:00 2001 From: Anna Cocuzzo <63511057+acocuzzo@users.noreply.github.com> Date: Sat, 2 Sep 2023 16:28:09 -0400 Subject: [PATCH 21/25] Update google/api_core/operations_v1/operations_async_client.py Co-authored-by: Anthonios Partheniou --- google/api_core/operations_v1/operations_async_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google/api_core/operations_v1/operations_async_client.py b/google/api_core/operations_v1/operations_async_client.py index 3175d184..57708b6c 100644 --- a/google/api_core/operations_v1/operations_async_client.py +++ b/google/api_core/operations_v1/operations_async_client.py @@ -194,7 +194,7 @@ async def list_operations( configuration is used. If ``None``, then the RPC method will not time out. compression (grpc.Compression): An element of grpc.compression - e.g. grpc.compression.Gzip. This is an EXPERIMENTAL option. + e.g. grpc.compression.Gzip. metadata (Optional[List[Tuple[str, str]]]): Additional gRPC metadata. From 21371b03d4ebb603f75a88d3dba16f3496014756 Mon Sep 17 00:00:00 2001 From: Anna Cocuzzo <63511057+acocuzzo@users.noreply.github.com> Date: Sat, 2 Sep 2023 16:28:16 -0400 Subject: [PATCH 22/25] Update google/api_core/operations_v1/operations_async_client.py Co-authored-by: Anthonios Partheniou --- google/api_core/operations_v1/operations_async_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google/api_core/operations_v1/operations_async_client.py b/google/api_core/operations_v1/operations_async_client.py index 57708b6c..5a91f64c 100644 --- a/google/api_core/operations_v1/operations_async_client.py +++ b/google/api_core/operations_v1/operations_async_client.py @@ -284,7 +284,7 @@ async def cancel_operation( while invoking the RPC, the appropriate ``GoogleAPICallError`` subclass will be raised. compression (grpc.Compression): An element of grpc.compression - e.g. grpc.compression.Gzip. This is an EXPERIMENTAL option. + e.g. grpc.compression.Gzip. metadata (Optional[List[Tuple[str, str]]]): Additional gRPC metadata. """ From 8aeeffd3bf8f68999076341f1e9b7435fc2b51ff Mon Sep 17 00:00:00 2001 From: Anna Cocuzzo <63511057+acocuzzo@users.noreply.github.com> Date: Sat, 2 Sep 2023 16:28:23 -0400 Subject: [PATCH 23/25] Update google/api_core/operations_v1/operations_async_client.py Co-authored-by: Anthonios Partheniou --- google/api_core/operations_v1/operations_async_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google/api_core/operations_v1/operations_async_client.py b/google/api_core/operations_v1/operations_async_client.py index 5a91f64c..d14312be 100644 --- a/google/api_core/operations_v1/operations_async_client.py +++ b/google/api_core/operations_v1/operations_async_client.py @@ -123,7 +123,7 @@ async def get_operation( configuration is used. If ``None``, then the RPC method will not time out. compression (grpc.Compression): An element of grpc.compression - e.g. grpc.compression.Gzip. This is an EXPERIMENTAL option. + e.g. grpc.compression.Gzip. metadata (Optional[List[Tuple[str, str]]]): Additional gRPC metadata. From 6becbeb5f83b9264c6f626f894c434f8214f2a46 Mon Sep 17 00:00:00 2001 From: Anna Cocuzzo <63511057+acocuzzo@users.noreply.github.com> Date: Sat, 2 Sep 2023 16:28:30 -0400 Subject: [PATCH 24/25] Update google/api_core/operations_v1/operations_async_client.py Co-authored-by: Anthonios Partheniou --- google/api_core/operations_v1/operations_async_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google/api_core/operations_v1/operations_async_client.py b/google/api_core/operations_v1/operations_async_client.py index d14312be..72c68c70 100644 --- a/google/api_core/operations_v1/operations_async_client.py +++ b/google/api_core/operations_v1/operations_async_client.py @@ -336,7 +336,7 @@ async def delete_operation( configuration is used. If ``None``, then the RPC method will not time out. compression (grpc.Compression): An element of grpc.compression - e.g. grpc.compression.Gzip. This is an EXPERIMENTAL option. + e.g. grpc.compression.Gzip. metadata (Optional[List[Tuple[str, str]]]): Additional gRPC metadata. From 0aa02497450f657eb9d2f842cb9c69882e155a3f Mon Sep 17 00:00:00 2001 From: Anna Cocuzzo <63511057+acocuzzo@users.noreply.github.com> Date: Sat, 2 Sep 2023 16:28:36 -0400 Subject: [PATCH 25/25] Update google/api_core/operations_v1/operations_client.py Co-authored-by: Anthonios Partheniou --- google/api_core/operations_v1/operations_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google/api_core/operations_v1/operations_client.py b/google/api_core/operations_v1/operations_client.py index d9678286..d1d3fd55 100644 --- a/google/api_core/operations_v1/operations_client.py +++ b/google/api_core/operations_v1/operations_client.py @@ -137,7 +137,7 @@ def get_operation( configuration is used. If ``None``, then the RPC method will not time out. compression (grpc.Compression): An element of grpc.compression - e.g. grpc.compression.Gzip. This is an EXPERIMENTAL option. + e.g. grpc.compression.Gzip. metadata (Optional[List[Tuple[str, str]]]): Additional gRPC metadata.