-
- As of January 1, 2020 this library no longer supports Python 2 on the latest released version. +
+ As of January 1, 2020 this library no longer supports Python 2 on the latest released version. Library versions released prior to that date will continue to be available. For more information please visit Python 2 support on Google Cloud.
diff --git a/packages/google-cloud-bigtable/docs/bigtable_admin_v2/bigtable_instance_admin.rst b/packages/google-cloud-bigtable/docs/bigtable_admin_v2/bigtable_instance_admin.rst new file mode 100644 index 000000000000..42f7caad7cb1 --- /dev/null +++ b/packages/google-cloud-bigtable/docs/bigtable_admin_v2/bigtable_instance_admin.rst @@ -0,0 +1,10 @@ +BigtableInstanceAdmin +--------------------------------------- + +.. automodule:: google.cloud.bigtable_admin_v2.services.bigtable_instance_admin + :members: + :inherited-members: + +.. automodule:: google.cloud.bigtable_admin_v2.services.bigtable_instance_admin.pagers + :members: + :inherited-members: diff --git a/packages/google-cloud-bigtable/docs/bigtable_admin_v2/bigtable_table_admin.rst b/packages/google-cloud-bigtable/docs/bigtable_admin_v2/bigtable_table_admin.rst new file mode 100644 index 000000000000..e10ff3ac6e02 --- /dev/null +++ b/packages/google-cloud-bigtable/docs/bigtable_admin_v2/bigtable_table_admin.rst @@ -0,0 +1,10 @@ +BigtableTableAdmin +------------------------------------ + +.. automodule:: google.cloud.bigtable_admin_v2.services.bigtable_table_admin + :members: + :inherited-members: + +.. automodule:: google.cloud.bigtable_admin_v2.services.bigtable_table_admin.pagers + :members: + :inherited-members: diff --git a/packages/google-cloud-bigtable/docs/bigtable_admin_v2/services_.rst b/packages/google-cloud-bigtable/docs/bigtable_admin_v2/services_.rst new file mode 100644 index 000000000000..ea55c7da14a3 --- /dev/null +++ b/packages/google-cloud-bigtable/docs/bigtable_admin_v2/services_.rst @@ -0,0 +1,7 @@ +Services for Google Cloud Bigtable Admin v2 API +=============================================== +.. toctree:: + :maxdepth: 2 + + bigtable_instance_admin + bigtable_table_admin diff --git a/packages/google-cloud-bigtable/docs/bigtable_admin_v2/types_.rst b/packages/google-cloud-bigtable/docs/bigtable_admin_v2/types_.rst new file mode 100644 index 000000000000..2f935927abbd --- /dev/null +++ b/packages/google-cloud-bigtable/docs/bigtable_admin_v2/types_.rst @@ -0,0 +1,6 @@ +Types for Google Cloud Bigtable Admin v2 API +============================================ + +.. automodule:: google.cloud.bigtable_admin_v2.types + :members: + :show-inheritance: diff --git a/packages/google-cloud-bigtable/docs/bigtable_v2/bigtable.rst b/packages/google-cloud-bigtable/docs/bigtable_v2/bigtable.rst new file mode 100644 index 000000000000..9f92e0fee6fb --- /dev/null +++ b/packages/google-cloud-bigtable/docs/bigtable_v2/bigtable.rst @@ -0,0 +1,6 @@ +Bigtable +-------------------------- + +.. automodule:: google.cloud.bigtable_v2.services.bigtable + :members: + :inherited-members: diff --git a/packages/google-cloud-bigtable/docs/bigtable_v2/services_.rst b/packages/google-cloud-bigtable/docs/bigtable_v2/services_.rst new file mode 100644 index 000000000000..1de472763075 --- /dev/null +++ b/packages/google-cloud-bigtable/docs/bigtable_v2/services_.rst @@ -0,0 +1,6 @@ +Services for Google Cloud Bigtable v2 API +========================================= +.. toctree:: + :maxdepth: 2 + + bigtable diff --git a/packages/google-cloud-bigtable/docs/bigtable_v2/types_.rst b/packages/google-cloud-bigtable/docs/bigtable_v2/types_.rst new file mode 100644 index 000000000000..56a8941a2b7d --- /dev/null +++ b/packages/google-cloud-bigtable/docs/bigtable_v2/types_.rst @@ -0,0 +1,6 @@ +Types for Google Cloud Bigtable v2 API +====================================== + +.. automodule:: google.cloud.bigtable_v2.types + :members: + :show-inheritance: diff --git a/packages/google-cloud-bigtable/docs/conf.py b/packages/google-cloud-bigtable/docs/conf.py index d8f0352cdd1c..18fe3a5dc5db 100644 --- a/packages/google-cloud-bigtable/docs/conf.py +++ b/packages/google-cloud-bigtable/docs/conf.py @@ -1,18 +1,18 @@ # -*- coding: utf-8 -*- -# Copyright 2024 Google LLC +# Copyright 2025 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# +## # google-cloud-bigtable documentation build configuration file # # This file is execfile()d with the current directory set to its @@ -24,9 +24,11 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys +import logging import os import shlex +import sys +from typing import Any # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the @@ -42,7 +44,7 @@ # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. -needs_sphinx = "1.5.5" +needs_sphinx = "4.5.0" # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom @@ -81,7 +83,7 @@ # General information about the project. project = "google-cloud-bigtable" -copyright = "2019, Google" +copyright = "2025, Google, LLC" author = "Google APIs" # The version info for the project you're documenting, acts as replacement for @@ -109,6 +111,8 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = [ + "bigtable_v2/**", + "bigtable_admin_v2/**", "_build", "**/.nox/**/*", "samples/AUTHORING_GUIDE.md", @@ -156,7 +160,7 @@ html_theme_options = { "description": "Google Cloud Client Libraries for google-cloud-bigtable", "github_user": "googleapis", - "github_repo": "python-bigtable", + "github_repo": "google-cloud-python", "github_banner": True, "font_family": "'Roboto', Georgia, sans", "head_font_family": "'Roboto', Georgia, serif", @@ -266,13 +270,13 @@ latex_elements = { # The paper size ('letterpaper' or 'a4paper'). - #'papersize': 'letterpaper', + # 'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). - #'pointsize': '10pt', + # 'pointsize': '10pt', # Additional stuff for the LaTeX preamble. - #'preamble': '', + # 'preamble': '', # Latex figure (float) alignment - #'figure_align': 'htbp', + # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples @@ -382,3 +386,34 @@ napoleon_use_ivar = False napoleon_use_param = True napoleon_use_rtype = True + + +# Setup for sphinx behaviors such as warning filters. +class UnexpectedUnindentFilter(logging.Filter): + """Filter out warnings about unexpected unindentation following bullet lists.""" + + def filter(self, record: logging.LogRecord) -> bool: + """Filter the log record. + + Args: + record (logging.LogRecord): The log record. + + Returns: + bool: False to suppress the warning, True to allow it. + """ + msg = record.getMessage() + if "Bullet list ends without a blank line" in msg: + return False + return True + + +def setup(app: Any) -> None: + """Setup the Sphinx application. + + Args: + app (Any): The Sphinx application. + """ + # Sphinx's logger is hierarchical. Adding a filter to the + # root 'sphinx' logger will catch warnings from all sub-loggers. + logger = logging.getLogger("sphinx") + logger.addFilter(UnexpectedUnindentFilter()) diff --git a/packages/google-cloud-bigtable/docs/index.rst b/packages/google-cloud-bigtable/docs/index.rst index 1eb603684846..1c6a396f6090 100644 --- a/packages/google-cloud-bigtable/docs/index.rst +++ b/packages/google-cloud-bigtable/docs/index.rst @@ -2,6 +2,7 @@ .. include:: multiprocessing.rst + Client Types ------------- .. toctree:: @@ -11,15 +12,16 @@ Client Types classic_client/usage admin_client/admin_client_usage + Changelog --------- For a list of all ``google-cloud-bigtable`` releases: .. toctree:: - :maxdepth: 2 + :maxdepth: 2 - CHANGELOG + CHANGELOG .. toctree:: :hidden: diff --git a/packages/google-cloud-bigtable/docs/summary_overview.md b/packages/google-cloud-bigtable/docs/summary_overview.md index 2379e8b6bc1f..b13302894649 100644 --- a/packages/google-cloud-bigtable/docs/summary_overview.md +++ b/packages/google-cloud-bigtable/docs/summary_overview.md @@ -5,14 +5,14 @@ reverted. Instead, if you want to place additional content, create an pick up on the content and merge the content. ]: # -# Cloud Bigtable API +# Google Cloud Bigtable API -Overview of the APIs available for Cloud Bigtable API. +Overview of the APIs available for Google Cloud Bigtable API. ## All entries Classes, methods and properties & attributes for -Cloud Bigtable API. +Google Cloud Bigtable API. [classes](https://cloud.google.com/python/docs/reference/bigtable/latest/summary_class.html) diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable/__init__.py b/packages/google-cloud-bigtable/google/cloud/bigtable/__init__.py index 8b73ec2e424f..bc469b893859 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable/__init__.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable/__init__.py @@ -1,4 +1,5 @@ -# Copyright 2015 Google LLC +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,7 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - +# """Google Cloud Bigtable API package.""" from google.cloud.bigtable import gapic_version as package_version diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable/gapic_version.py b/packages/google-cloud-bigtable/google/cloud/bigtable/gapic_version.py index d0a538508f75..e138acef04f7 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable/gapic_version.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable/gapic_version.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2025 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/async_client.py b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/async_client.py index 7639a91ea1e5..532e46290b47 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/async_client.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/async_client.py @@ -44,18 +44,12 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore -from google.api_core import ( - operation, # type: ignore - operation_async, # type: ignore -) -from google.iam.v1 import ( - iam_policy_pb2, # type: ignore - policy_pb2, # type: ignore -) -from google.protobuf import ( - field_mask_pb2, # type: ignore - timestamp_pb2, # type: ignore -) +import google.api_core.operation as operation # type: ignore +import google.api_core.operation_async as operation_async # type: ignore +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore +import google.iam.v1.policy_pb2 as policy_pb2 # type: ignore +import google.protobuf.field_mask_pb2 as field_mask_pb2 # type: ignore +import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore from google.cloud.bigtable_admin_v2.services.bigtable_instance_admin import pagers from google.cloud.bigtable_admin_v2.types import ( @@ -163,9 +157,10 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): Returns: BigtableInstanceAdminAsyncClient: The constructed client. """ - return BigtableInstanceAdminClient.from_service_account_info.__func__( - BigtableInstanceAdminAsyncClient, info, *args, **kwargs - ) # type: ignore + sa_info_func = ( + BigtableInstanceAdminClient.from_service_account_info.__func__ # type: ignore + ) + return sa_info_func(BigtableInstanceAdminAsyncClient, info, *args, **kwargs) @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): @@ -181,9 +176,10 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): Returns: BigtableInstanceAdminAsyncClient: The constructed client. """ - return BigtableInstanceAdminClient.from_service_account_file.__func__( - BigtableInstanceAdminAsyncClient, filename, *args, **kwargs - ) # type: ignore + sa_file_func = ( + BigtableInstanceAdminClient.from_service_account_file.__func__ # type: ignore + ) + return sa_file_func(BigtableInstanceAdminAsyncClient, filename, *args, **kwargs) from_service_account_json = from_service_account_file @@ -235,7 +231,7 @@ def transport(self) -> BigtableInstanceAdminTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2524,7 +2520,7 @@ async def get_iam_policy( # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import bigtable_admin_v2 - from google.iam.v1 import iam_policy_pb2 # type: ignore + import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore async def sample_get_iam_policy(): # Create a client @@ -2663,7 +2659,7 @@ async def set_iam_policy( # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import bigtable_admin_v2 - from google.iam.v1 import iam_policy_pb2 # type: ignore + import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore async def sample_set_iam_policy(): # Create a client @@ -2803,7 +2799,7 @@ async def test_iam_permissions( # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import bigtable_admin_v2 - from google.iam.v1 import iam_policy_pb2 # type: ignore + import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore async def sample_test_iam_permissions(): # Create a client diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/client.py b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/client.py index d15902ca8ad3..aeb1ea6e4948 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/client.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/client.py @@ -61,18 +61,12 @@ _LOGGER = std_logging.getLogger(__name__) -from google.api_core import ( - operation, # type: ignore - operation_async, # type: ignore -) -from google.iam.v1 import ( - iam_policy_pb2, # type: ignore - policy_pb2, # type: ignore -) -from google.protobuf import ( - field_mask_pb2, # type: ignore - timestamp_pb2, # type: ignore -) +import google.api_core.operation as operation # type: ignore +import google.api_core.operation_async as operation_async # type: ignore +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore +import google.iam.v1.policy_pb2 as policy_pb2 # type: ignore +import google.protobuf.field_mask_pb2 as field_mask_pb2 # type: ignore +import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore from google.cloud.bigtable_admin_v2.services.bigtable_instance_admin import pagers from google.cloud.bigtable_admin_v2.types import ( @@ -131,7 +125,7 @@ class BigtableInstanceAdminClient(metaclass=BigtableInstanceAdminClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -139,7 +133,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -149,6 +143,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -611,7 +609,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -710,7 +708,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -801,18 +799,16 @@ def __init__( universe_domain_opt = getattr(self._client_options, "universe_domain", None) - ( - self._use_client_cert, - self._use_mtls_endpoint, - self._universe_domain_env, - ) = BigtableInstanceAdminClient._read_environment_variables() + self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = ( + BigtableInstanceAdminClient._read_environment_variables() + ) self._client_cert_source = BigtableInstanceAdminClient._get_client_cert_source( self._client_options.client_cert_source, self._use_client_cert ) self._universe_domain = BigtableInstanceAdminClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -3036,7 +3032,7 @@ def get_iam_policy( # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import bigtable_admin_v2 - from google.iam.v1 import iam_policy_pb2 # type: ignore + import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore def sample_get_iam_policy(): # Create a client @@ -3176,7 +3172,7 @@ def set_iam_policy( # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import bigtable_admin_v2 - from google.iam.v1 import iam_policy_pb2 # type: ignore + import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore def sample_set_iam_policy(): # Create a client @@ -3317,7 +3313,7 @@ def test_iam_permissions( # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import bigtable_admin_v2 - from google.iam.v1 import iam_policy_pb2 # type: ignore + import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore def sample_test_iam_permissions(): # Create a client diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/README.rst b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/README.rst index 9a01ee7c3032..bf1871a63f9e 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/README.rst +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BigtableInstanceAdminTransport` is the ABC for all transports. -- public child `BigtableInstanceAdminGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BigtableInstanceAdminGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBigtableInstanceAdminRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BigtableInstanceAdminRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BigtableInstanceAdminTransport`` is the ABC for all transports. + +- public child ``BigtableInstanceAdminGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BigtableInstanceAdminGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBigtableInstanceAdminRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BigtableInstanceAdminRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/base.py b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/base.py index 4a1866dfabfb..5882a27de7aa 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/base.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/base.py @@ -18,18 +18,16 @@ import google.api_core import google.auth # type: ignore +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore +import google.iam.v1.policy_pb2 as policy_pb2 # type: ignore import google.protobuf +import google.protobuf.empty_pb2 as empty_pb2 # type: ignore from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1, operations_v1 from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore -from google.iam.v1 import ( - iam_policy_pb2, # type: ignore - policy_pb2, # type: ignore -) from google.longrunning import operations_pb2 # type: ignore from google.oauth2 import service_account # type: ignore -from google.protobuf import empty_pb2 # type: ignore from google.cloud.bigtable_admin_v2 import gapic_version as package_version from google.cloud.bigtable_admin_v2.types import bigtable_instance_admin, instance @@ -94,10 +92,12 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ - scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} - # Save the scopes. self._scopes = scopes if not hasattr(self, "_ignore_credentials"): @@ -112,11 +112,16 @@ def __init__( if credentials_file is not None: credentials, _ = google.auth.load_credentials_from_file( - credentials_file, **scopes_kwargs, quota_project_id=quota_project_id + credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + default_scopes=self.AUTH_SCOPES, ) elif credentials is None and not self._ignore_credentials: credentials, _ = google.auth.default( - **scopes_kwargs, quota_project_id=quota_project_id + scopes=scopes, + quota_project_id=quota_project_id, + default_scopes=self.AUTH_SCOPES, ) # Don't apply audience if the credentials file passed from user. if hasattr(credentials, "with_gdch_audience"): @@ -140,6 +145,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/grpc.py b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/grpc.py index fe0cba78c397..f2cc6e40304f 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/grpc.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/grpc.py @@ -20,18 +20,16 @@ from typing import Callable, Dict, Optional, Sequence, Tuple, Union import google.auth # type: ignore +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore +import google.iam.v1.policy_pb2 as policy_pb2 # type: ignore +import google.protobuf.empty_pb2 as empty_pb2 # type: ignore import google.protobuf.message import grpc # type: ignore import proto # type: ignore from google.api_core import gapic_v1, grpc_helpers, operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -from google.iam.v1 import ( - iam_policy_pb2, # type: ignore - policy_pb2, # type: ignore -) from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore from google.protobuf.json_format import MessageToJson from google.cloud.bigtable_admin_v2.types import bigtable_instance_admin, instance @@ -60,7 +58,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +93,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -193,6 +191,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/grpc_asyncio.py b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/grpc_asyncio.py index b579205f2362..e444a9c07ad1 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/grpc_asyncio.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/grpc_asyncio.py @@ -20,6 +20,9 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore +import google.iam.v1.policy_pb2 as policy_pb2 # type: ignore +import google.protobuf.empty_pb2 as empty_pb2 # type: ignore import google.protobuf.message import grpc # type: ignore import proto # type: ignore @@ -28,12 +31,7 @@ from google.api_core import retry_async as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -from google.iam.v1 import ( - iam_policy_pb2, # type: ignore - policy_pb2, # type: ignore -) from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore from google.protobuf.json_format import MessageToJson from grpc.experimental import aio # type: ignore @@ -66,7 +64,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -101,7 +99,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -244,6 +242,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/rest.py b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/rest.py index 75178e60f514..30f13fddd614 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/rest.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/rest.py @@ -19,21 +19,17 @@ import warnings from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore +import google.iam.v1.policy_pb2 as policy_pb2 # type: ignore import google.protobuf +import google.protobuf.empty_pb2 as empty_pb2 # type: ignore from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1, operations_v1, rest_helpers, rest_streaming from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.requests import AuthorizedSession # type: ignore -from google.iam.v1 import ( - iam_policy_pb2, # type: ignore - policy_pb2, # type: ignore -) from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import ( - empty_pb2, # type: ignore - json_format, -) +from google.protobuf import json_format from requests import __version__ as requests_version from google.cloud.bigtable_admin_v2.types import bigtable_instance_admin, instance @@ -1736,6 +1732,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[BigtableInstanceAdminRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. @@ -2051,7 +2053,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -2202,7 +2204,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -2355,7 +2357,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -2510,7 +2512,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -2651,7 +2653,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -2759,7 +2761,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -2865,7 +2867,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -2973,7 +2975,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -3083,7 +3085,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -5078,7 +5080,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -5233,7 +5235,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -5765,7 +5767,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -5920,7 +5922,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -6233,7 +6235,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -6388,7 +6390,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/rest_base.py b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/rest_base.py index e2e960c38e8a..991f8400a905 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/rest_base.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/rest_base.py @@ -17,16 +17,12 @@ import re from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore +import google.iam.v1.policy_pb2 as policy_pb2 # type: ignore +import google.protobuf.empty_pb2 as empty_pb2 # type: ignore from google.api_core import gapic_v1, path_template -from google.iam.v1 import ( - iam_policy_pb2, # type: ignore - policy_pb2, # type: ignore -) from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import ( - empty_pb2, # type: ignore - json_format, -) +from google.protobuf import json_format from google.cloud.bigtable_admin_v2.types import bigtable_instance_admin, instance diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/async_client.py b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/async_client.py index 35dfed3ea6b4..91f5a9042485 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/async_client.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/async_client.py @@ -44,18 +44,12 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore -from google.api_core import ( - operation, # type: ignore - operation_async, # type: ignore -) -from google.iam.v1 import ( - iam_policy_pb2, # type: ignore - policy_pb2, # type: ignore -) -from google.protobuf import ( - field_mask_pb2, # type: ignore - timestamp_pb2, # type: ignore -) +import google.api_core.operation as operation # type: ignore +import google.api_core.operation_async as operation_async # type: ignore +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore +import google.iam.v1.policy_pb2 as policy_pb2 # type: ignore +import google.protobuf.field_mask_pb2 as field_mask_pb2 # type: ignore +import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore from google.cloud.bigtable_admin_v2.services.bigtable_table_admin import pagers from google.cloud.bigtable_admin_v2.types import bigtable_table_admin, table, types @@ -158,9 +152,10 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): Returns: BaseBigtableTableAdminAsyncClient: The constructed client. """ - return BaseBigtableTableAdminClient.from_service_account_info.__func__( - BaseBigtableTableAdminAsyncClient, info, *args, **kwargs - ) # type: ignore + sa_info_func = ( + BaseBigtableTableAdminClient.from_service_account_info.__func__ # type: ignore + ) + return sa_info_func(BaseBigtableTableAdminAsyncClient, info, *args, **kwargs) @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): @@ -176,9 +171,12 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): Returns: BaseBigtableTableAdminAsyncClient: The constructed client. """ - return BaseBigtableTableAdminClient.from_service_account_file.__func__( + sa_file_func = ( + BaseBigtableTableAdminClient.from_service_account_file.__func__ # type: ignore + ) + return sa_file_func( BaseBigtableTableAdminAsyncClient, filename, *args, **kwargs - ) # type: ignore + ) from_service_account_json = from_service_account_file @@ -230,7 +228,7 @@ def transport(self) -> BigtableTableAdminTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -3926,7 +3924,7 @@ async def get_iam_policy( # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import bigtable_admin_v2 - from google.iam.v1 import iam_policy_pb2 # type: ignore + import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore async def sample_get_iam_policy(): # Create a client @@ -4065,7 +4063,7 @@ async def set_iam_policy( # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import bigtable_admin_v2 - from google.iam.v1 import iam_policy_pb2 # type: ignore + import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore async def sample_set_iam_policy(): # Create a client @@ -4205,7 +4203,7 @@ async def test_iam_permissions( # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import bigtable_admin_v2 - from google.iam.v1 import iam_policy_pb2 # type: ignore + import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore async def sample_test_iam_permissions(): # Create a client diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/client.py b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/client.py index 8169e4edf759..95f2716ed6e1 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/client.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/client.py @@ -61,18 +61,12 @@ _LOGGER = std_logging.getLogger(__name__) -from google.api_core import ( - operation, # type: ignore - operation_async, # type: ignore -) -from google.iam.v1 import ( - iam_policy_pb2, # type: ignore - policy_pb2, # type: ignore -) -from google.protobuf import ( - field_mask_pb2, # type: ignore - timestamp_pb2, # type: ignore -) +import google.api_core.operation as operation # type: ignore +import google.api_core.operation_async as operation_async # type: ignore +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore +import google.iam.v1.policy_pb2 as policy_pb2 # type: ignore +import google.protobuf.field_mask_pb2 as field_mask_pb2 # type: ignore +import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore from google.cloud.bigtable_admin_v2.services.bigtable_table_admin import pagers from google.cloud.bigtable_admin_v2.types import bigtable_table_admin, table, types @@ -128,7 +122,7 @@ class BaseBigtableTableAdminClient(metaclass=BaseBigtableTableAdminClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -136,7 +130,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -146,6 +140,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -614,7 +612,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -713,7 +711,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -804,18 +802,16 @@ def __init__( universe_domain_opt = getattr(self._client_options, "universe_domain", None) - ( - self._use_client_cert, - self._use_mtls_endpoint, - self._universe_domain_env, - ) = BaseBigtableTableAdminClient._read_environment_variables() + self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = ( + BaseBigtableTableAdminClient._read_environment_variables() + ) self._client_cert_source = BaseBigtableTableAdminClient._get_client_cert_source( self._client_options.client_cert_source, self._use_client_cert ) self._universe_domain = BaseBigtableTableAdminClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -4421,7 +4417,7 @@ def get_iam_policy( # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import bigtable_admin_v2 - from google.iam.v1 import iam_policy_pb2 # type: ignore + import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore def sample_get_iam_policy(): # Create a client @@ -4561,7 +4557,7 @@ def set_iam_policy( # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import bigtable_admin_v2 - from google.iam.v1 import iam_policy_pb2 # type: ignore + import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore def sample_set_iam_policy(): # Create a client @@ -4702,7 +4698,7 @@ def test_iam_permissions( # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.cloud import bigtable_admin_v2 - from google.iam.v1 import iam_policy_pb2 # type: ignore + import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore def sample_test_iam_permissions(): # Create a client diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/README.rst b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/README.rst index 0e8f40ec3a60..1e0bce38758d 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/README.rst +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BigtableTableAdminTransport` is the ABC for all transports. -- public child `BigtableTableAdminGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BigtableTableAdminGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBigtableTableAdminRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BigtableTableAdminRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BigtableTableAdminTransport`` is the ABC for all transports. + +- public child ``BigtableTableAdminGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BigtableTableAdminGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBigtableTableAdminRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BigtableTableAdminRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/base.py b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/base.py index f37cdd85935e..164a36c8fdf9 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/base.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/base.py @@ -18,18 +18,16 @@ import google.api_core import google.auth # type: ignore +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore +import google.iam.v1.policy_pb2 as policy_pb2 # type: ignore import google.protobuf +import google.protobuf.empty_pb2 as empty_pb2 # type: ignore from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1, operations_v1 from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore -from google.iam.v1 import ( - iam_policy_pb2, # type: ignore - policy_pb2, # type: ignore -) from google.longrunning import operations_pb2 # type: ignore from google.oauth2 import service_account # type: ignore -from google.protobuf import empty_pb2 # type: ignore from google.cloud.bigtable_admin_v2 import gapic_version as package_version from google.cloud.bigtable_admin_v2.types import bigtable_table_admin, table @@ -94,10 +92,12 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ - scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} - # Save the scopes. self._scopes = scopes if not hasattr(self, "_ignore_credentials"): @@ -112,11 +112,16 @@ def __init__( if credentials_file is not None: credentials, _ = google.auth.load_credentials_from_file( - credentials_file, **scopes_kwargs, quota_project_id=quota_project_id + credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + default_scopes=self.AUTH_SCOPES, ) elif credentials is None and not self._ignore_credentials: credentials, _ = google.auth.default( - **scopes_kwargs, quota_project_id=quota_project_id + scopes=scopes, + quota_project_id=quota_project_id, + default_scopes=self.AUTH_SCOPES, ) # Don't apply audience if the credentials file passed from user. if hasattr(credentials, "with_gdch_audience"): @@ -140,6 +145,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/grpc.py b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/grpc.py index 1428d555f70e..3d39f4382ec6 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/grpc.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/grpc.py @@ -20,18 +20,16 @@ from typing import Callable, Dict, Optional, Sequence, Tuple, Union import google.auth # type: ignore +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore +import google.iam.v1.policy_pb2 as policy_pb2 # type: ignore +import google.protobuf.empty_pb2 as empty_pb2 # type: ignore import google.protobuf.message import grpc # type: ignore import proto # type: ignore from google.api_core import gapic_v1, grpc_helpers, operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -from google.iam.v1 import ( - iam_policy_pb2, # type: ignore - policy_pb2, # type: ignore -) from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore from google.protobuf.json_format import MessageToJson from google.cloud.bigtable_admin_v2.types import bigtable_table_admin, table @@ -61,7 +59,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -96,7 +94,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -195,6 +193,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/grpc_asyncio.py b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/grpc_asyncio.py index 0f0d4c0e097d..58a472e7c18d 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/grpc_asyncio.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/grpc_asyncio.py @@ -20,6 +20,9 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore +import google.iam.v1.policy_pb2 as policy_pb2 # type: ignore +import google.protobuf.empty_pb2 as empty_pb2 # type: ignore import google.protobuf.message import grpc # type: ignore import proto # type: ignore @@ -28,12 +31,7 @@ from google.api_core import retry_async as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -from google.iam.v1 import ( - iam_policy_pb2, # type: ignore - policy_pb2, # type: ignore -) from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import empty_pb2 # type: ignore from google.protobuf.json_format import MessageToJson from grpc.experimental import aio # type: ignore @@ -67,7 +65,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -102,7 +100,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -246,6 +244,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/rest.py b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/rest.py index 33bae4ae86ac..adb950e08e20 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/rest.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/rest.py @@ -19,21 +19,17 @@ import warnings from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore +import google.iam.v1.policy_pb2 as policy_pb2 # type: ignore import google.protobuf +import google.protobuf.empty_pb2 as empty_pb2 # type: ignore from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1, operations_v1, rest_helpers, rest_streaming from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.requests import AuthorizedSession # type: ignore -from google.iam.v1 import ( - iam_policy_pb2, # type: ignore - policy_pb2, # type: ignore -) from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import ( - empty_pb2, # type: ignore - json_format, -) +from google.protobuf import json_format from requests import __version__ as requests_version from google.cloud.bigtable_admin_v2.types import bigtable_table_admin, table @@ -1913,6 +1909,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[BigtableTableAdminRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. @@ -2228,7 +2230,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -2381,7 +2383,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -2534,7 +2536,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -2687,7 +2689,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -3004,7 +3006,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -3147,7 +3149,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -3255,7 +3257,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -3363,7 +3365,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -3478,7 +3480,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -3584,7 +3586,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -3695,7 +3697,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -5878,7 +5880,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -6260,7 +6262,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -6564,7 +6566,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -6717,7 +6719,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -7022,7 +7024,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { @@ -7175,7 +7177,7 @@ def __call__( ) method = transcoded_request["method"] try: - request_payload = json_format.MessageToJson(request) + request_payload = type(request).to_json(request) except: request_payload = None http_request = { diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/rest_base.py b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/rest_base.py index c01a48b6897d..1b6b7d48bdc2 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/rest_base.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/rest_base.py @@ -17,16 +17,12 @@ import re from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore +import google.iam.v1.policy_pb2 as policy_pb2 # type: ignore +import google.protobuf.empty_pb2 as empty_pb2 # type: ignore from google.api_core import gapic_v1, path_template -from google.iam.v1 import ( - iam_policy_pb2, # type: ignore - policy_pb2, # type: ignore -) from google.longrunning import operations_pb2 # type: ignore -from google.protobuf import ( - empty_pb2, # type: ignore - json_format, -) +from google.protobuf import json_format from google.cloud.bigtable_admin_v2.types import bigtable_table_admin, table from google.cloud.bigtable_admin_v2.types import table as gba_table diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/types/bigtable_instance_admin.py b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/types/bigtable_instance_admin.py index afca9be1aa5e..0f2cbfd91bce 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/types/bigtable_instance_admin.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/types/bigtable_instance_admin.py @@ -17,11 +17,9 @@ from typing import MutableMapping, MutableSequence +import google.protobuf.field_mask_pb2 as field_mask_pb2 # type: ignore +import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore import proto # type: ignore -from google.protobuf import ( - field_mask_pb2, # type: ignore - timestamp_pb2, # type: ignore -) from google.cloud.bigtable_admin_v2.types import instance as gba_instance diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/types/bigtable_table_admin.py b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/types/bigtable_table_admin.py index 01866ea1257f..508b1fcba337 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/types/bigtable_table_admin.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/types/bigtable_table_admin.py @@ -17,12 +17,10 @@ from typing import MutableMapping, MutableSequence +import google.protobuf.duration_pb2 as duration_pb2 # type: ignore +import google.protobuf.field_mask_pb2 as field_mask_pb2 # type: ignore +import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore import proto # type: ignore -from google.protobuf import ( - duration_pb2, # type: ignore - field_mask_pb2, # type: ignore - timestamp_pb2, # type: ignore -) from google.cloud.bigtable_admin_v2.types import common from google.cloud.bigtable_admin_v2.types import table as gba_table diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/types/common.py b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/types/common.py index c8da50ee7eb7..7f03891307e5 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/types/common.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/types/common.py @@ -17,8 +17,8 @@ from typing import MutableMapping, MutableSequence +import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore import proto # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( package="google.bigtable.admin.v2", diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/types/instance.py b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/types/instance.py index 859e42298a40..9d6878706b54 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/types/instance.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/types/instance.py @@ -17,8 +17,8 @@ from typing import MutableMapping, MutableSequence +import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore import proto # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore from google.cloud.bigtable_admin_v2.types import common diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/types/table.py b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/types/table.py index 5449bbb4123b..66e1626f95e3 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/types/table.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_admin_v2/types/table.py @@ -17,12 +17,10 @@ from typing import MutableMapping, MutableSequence +import google.protobuf.duration_pb2 as duration_pb2 # type: ignore +import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore +import google.rpc.status_pb2 as status_pb2 # type: ignore import proto # type: ignore -from google.protobuf import ( - duration_pb2, # type: ignore - timestamp_pb2, # type: ignore -) -from google.rpc import status_pb2 # type: ignore from google.cloud.bigtable_admin_v2.types import types from google.cloud.bigtable_admin_v2.utils import oneof_message diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/async_client.py b/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/async_client.py index e917acffbdab..90732351193a 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/async_client.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/async_client.py @@ -46,7 +46,7 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore +import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore from google.cloud.bigtable_v2.types import bigtable, data, request_stats @@ -118,9 +118,10 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): Returns: BigtableAsyncClient: The constructed client. """ - return BigtableClient.from_service_account_info.__func__( - BigtableAsyncClient, info, *args, **kwargs - ) # type: ignore + sa_info_func = ( + BigtableClient.from_service_account_info.__func__ # type: ignore + ) + return sa_info_func(BigtableAsyncClient, info, *args, **kwargs) @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): @@ -136,9 +137,10 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): Returns: BigtableAsyncClient: The constructed client. """ - return BigtableClient.from_service_account_file.__func__( - BigtableAsyncClient, filename, *args, **kwargs - ) # type: ignore + sa_file_func = ( + BigtableClient.from_service_account_file.__func__ # type: ignore + ) + return sa_file_func(BigtableAsyncClient, filename, *args, **kwargs) from_service_account_json = from_service_account_file @@ -188,7 +190,7 @@ def transport(self) -> BigtableTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/client.py b/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/client.py index 1dc7d7a8b852..d0dbe91866ac 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/client.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/client.py @@ -62,7 +62,7 @@ _LOGGER = std_logging.getLogger(__name__) -from google.protobuf import timestamp_pb2 # type: ignore +import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore from google.cloud.bigtable_v2.types import bigtable, data, request_stats @@ -113,7 +113,7 @@ class BigtableClient(metaclass=BigtableClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # Could not parse api_endpoint; return as-is. + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -501,7 +505,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint - ): + ) -> str: """Return the API endpoint used by the client. Args: @@ -598,7 +602,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -685,18 +689,16 @@ def __init__( universe_domain_opt = getattr(self._client_options, "universe_domain", None) - ( - self._use_client_cert, - self._use_mtls_endpoint, - self._universe_domain_env, - ) = BigtableClient._read_environment_variables() + self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = ( + BigtableClient._read_environment_variables() + ) self._client_cert_source = BigtableClient._get_client_cert_source( self._client_options.client_cert_source, self._use_client_cert ) self._universe_domain = BigtableClient._get_universe_domain( universe_domain_opt, self._universe_domain_env ) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/transports/README.rst b/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/transports/README.rst index 254812cd366f..674da52de70f 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/transports/README.rst +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/transports/README.rst @@ -2,8 +2,9 @@ transport inheritance structure _______________________________ -`BigtableTransport` is the ABC for all transports. -- public child `BigtableGrpcTransport` for sync gRPC transport (defined in `grpc.py`). -- public child `BigtableGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`). -- private child `_BaseBigtableRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`). -- public child `BigtableRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`). +``BigtableTransport`` is the ABC for all transports. + +- public child ``BigtableGrpcTransport`` for sync gRPC transport (defined in ``grpc.py``). +- public child ``BigtableGrpcAsyncIOTransport`` for async gRPC transport (defined in ``grpc_asyncio.py``). +- private child ``_BaseBigtableRestTransport`` for base REST transport with inner classes ``_BaseMETHOD`` (defined in ``rest_base.py``). +- public child ``BigtableRestTransport`` for sync REST transport with inner classes ``METHOD`` derived from the parent's corresponding ``_BaseMETHOD`` classes (defined in ``rest.py``). diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/transports/base.py b/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/transports/base.py index e25ea52c6eda..27a6204cf903 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/transports/base.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/transports/base.py @@ -87,10 +87,12 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ - scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} - # Save the scopes. self._scopes = scopes if not hasattr(self, "_ignore_credentials"): @@ -105,11 +107,16 @@ def __init__( if credentials_file is not None: credentials, _ = google.auth.load_credentials_from_file( - credentials_file, **scopes_kwargs, quota_project_id=quota_project_id + credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + default_scopes=self.AUTH_SCOPES, ) elif credentials is None and not self._ignore_credentials: credentials, _ = google.auth.default( - **scopes_kwargs, quota_project_id=quota_project_id + scopes=scopes, + quota_project_id=quota_project_id, + default_scopes=self.AUTH_SCOPES, ) # Don't apply audience if the credentials file passed from user. if hasattr(credentials, "with_gdch_audience"): @@ -133,6 +140,8 @@ def __init__( host += ":443" self._host = host + self._wrapped_methods: Dict[Callable, Callable] = {} + @property def host(self): return self._host diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/transports/grpc.py b/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/transports/grpc.py index 0dfef01b9ca6..addbd2b89ce2 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/transports/grpc.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -185,6 +185,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/transports/grpc_asyncio.py b/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/transports/grpc_asyncio.py index 217f6fb09f82..54e68eacefab 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/transports/grpc_asyncio.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/transports/grpc_asyncio.py @@ -60,7 +60,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -95,7 +95,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, @@ -236,6 +236,10 @@ def __init__( your own client library. always_use_jwt_access (Optional[bool]): Whether self signed JWT should be used for service account credentials. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/transports/rest.py b/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/transports/rest.py index 9914b6f37cdd..c233f68ea815 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/transports/rest.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_v2/services/bigtable/transports/rest.py @@ -765,6 +765,12 @@ def __init__( url_scheme: the protocol scheme for the API endpoint. Normally "https", but for testing or local servers, "http" can be specified. + interceptor (Optional[BigtableRestInterceptor]): Interceptor used + to manipulate requests, request metadata, and responses. + api_audience (Optional[str]): The intended audience for the API calls + to the service that will be set when using certain 3rd party + authentication flows. Audience is typically a resource identifier. + If not set, the host value will be used as a default. """ # Run the base constructor # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. @@ -1160,11 +1166,10 @@ def __call__( http_options = _BaseBigtableRestTransport._BaseGenerateInitialChangeStreamPartitions._get_http_options() - ( - request, - metadata, - ) = self._interceptor.pre_generate_initial_change_stream_partitions( - request, metadata + request, metadata = ( + self._interceptor.pre_generate_initial_change_stream_partitions( + request, metadata + ) ) transcoded_request = _BaseBigtableRestTransport._BaseGenerateInitialChangeStreamPartitions._get_transcoded_request( http_options, request @@ -1231,11 +1236,10 @@ def __call__( resp ) response_metadata = [(k, str(v)) for k, v in response.headers.items()] - ( - resp, - _, - ) = self._interceptor.post_generate_initial_change_stream_partitions_with_metadata( - resp, response_metadata + resp, _ = ( + self._interceptor.post_generate_initial_change_stream_partitions_with_metadata( + resp, response_metadata + ) ) if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( logging.DEBUG diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_v2/types/bigtable.py b/packages/google-cloud-bigtable/google/cloud/bigtable_v2/types/bigtable.py index d73fe457a998..b6eb9ce21359 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_v2/types/bigtable.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_v2/types/bigtable.py @@ -17,13 +17,11 @@ from typing import MutableMapping, MutableSequence +import google.protobuf.duration_pb2 as duration_pb2 # type: ignore +import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore +import google.protobuf.wrappers_pb2 as wrappers_pb2 # type: ignore +import google.rpc.status_pb2 as status_pb2 # type: ignore import proto # type: ignore -from google.protobuf import ( - duration_pb2, # type: ignore - timestamp_pb2, # type: ignore - wrappers_pb2, # type: ignore -) -from google.rpc import status_pb2 # type: ignore from google.cloud.bigtable_v2.types import data, types from google.cloud.bigtable_v2.types import request_stats as gb_request_stats diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_v2/types/data.py b/packages/google-cloud-bigtable/google/cloud/bigtable_v2/types/data.py index 0b62553c62d7..d4c481c93988 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_v2/types/data.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_v2/types/data.py @@ -17,9 +17,9 @@ from typing import MutableMapping, MutableSequence +import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore +import google.type.date_pb2 as date_pb2 # type: ignore import proto # type: ignore -from google.protobuf import timestamp_pb2 # type: ignore -from google.type import date_pb2 # type: ignore from google.cloud.bigtable_v2.types import types diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable_v2/types/request_stats.py b/packages/google-cloud-bigtable/google/cloud/bigtable_v2/types/request_stats.py index 8ac034b2ead8..3e53b8fe2872 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable_v2/types/request_stats.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable_v2/types/request_stats.py @@ -17,8 +17,8 @@ from typing import MutableMapping, MutableSequence +import google.protobuf.duration_pb2 as duration_pb2 # type: ignore import proto # type: ignore -from google.protobuf import duration_pb2 # type: ignore __protobuf__ = proto.module( package="google.bigtable.v2", diff --git a/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_instance_admin_get_iam_policy_async.py b/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_instance_admin_get_iam_policy_async.py index e811b7c76295..0aaf2680fb86 100644 --- a/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_instance_admin_get_iam_policy_async.py +++ b/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_instance_admin_get_iam_policy_async.py @@ -31,7 +31,7 @@ # - It may require specifying regional endpoints when creating the service # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.iam.v1 import iam_policy_pb2 # type: ignore +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore from google.cloud import bigtable_admin_v2 diff --git a/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_instance_admin_get_iam_policy_sync.py b/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_instance_admin_get_iam_policy_sync.py index b4faf4d04963..9a1ff3c7ac1b 100644 --- a/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_instance_admin_get_iam_policy_sync.py +++ b/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_instance_admin_get_iam_policy_sync.py @@ -31,7 +31,7 @@ # - It may require specifying regional endpoints when creating the service # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.iam.v1 import iam_policy_pb2 # type: ignore +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore from google.cloud import bigtable_admin_v2 diff --git a/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_instance_admin_set_iam_policy_async.py b/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_instance_admin_set_iam_policy_async.py index eb0889e2961d..e6e0a0f13e28 100644 --- a/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_instance_admin_set_iam_policy_async.py +++ b/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_instance_admin_set_iam_policy_async.py @@ -31,7 +31,7 @@ # - It may require specifying regional endpoints when creating the service # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.iam.v1 import iam_policy_pb2 # type: ignore +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore from google.cloud import bigtable_admin_v2 diff --git a/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_instance_admin_set_iam_policy_sync.py b/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_instance_admin_set_iam_policy_sync.py index 609bf911f5f5..9281dbcc63b3 100644 --- a/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_instance_admin_set_iam_policy_sync.py +++ b/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_instance_admin_set_iam_policy_sync.py @@ -31,7 +31,7 @@ # - It may require specifying regional endpoints when creating the service # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.iam.v1 import iam_policy_pb2 # type: ignore +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore from google.cloud import bigtable_admin_v2 diff --git a/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_instance_admin_test_iam_permissions_async.py b/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_instance_admin_test_iam_permissions_async.py index f1b657b4db7c..cb1f7844b171 100644 --- a/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_instance_admin_test_iam_permissions_async.py +++ b/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_instance_admin_test_iam_permissions_async.py @@ -31,7 +31,7 @@ # - It may require specifying regional endpoints when creating the service # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.iam.v1 import iam_policy_pb2 # type: ignore +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore from google.cloud import bigtable_admin_v2 diff --git a/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_instance_admin_test_iam_permissions_sync.py b/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_instance_admin_test_iam_permissions_sync.py index 375ab6c1d0ea..38ccd693845f 100644 --- a/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_instance_admin_test_iam_permissions_sync.py +++ b/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_instance_admin_test_iam_permissions_sync.py @@ -31,7 +31,7 @@ # - It may require specifying regional endpoints when creating the service # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.iam.v1 import iam_policy_pb2 # type: ignore +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore from google.cloud import bigtable_admin_v2 diff --git a/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_table_admin_get_iam_policy_async.py b/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_table_admin_get_iam_policy_async.py index ae31d02628c5..ab44d558886f 100644 --- a/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_table_admin_get_iam_policy_async.py +++ b/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_table_admin_get_iam_policy_async.py @@ -31,7 +31,7 @@ # - It may require specifying regional endpoints when creating the service # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.iam.v1 import iam_policy_pb2 # type: ignore +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore from google.cloud import bigtable_admin_v2 diff --git a/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_table_admin_get_iam_policy_sync.py b/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_table_admin_get_iam_policy_sync.py index 72ca478294b3..729cd4d70bc6 100644 --- a/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_table_admin_get_iam_policy_sync.py +++ b/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_table_admin_get_iam_policy_sync.py @@ -31,7 +31,7 @@ # - It may require specifying regional endpoints when creating the service # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.iam.v1 import iam_policy_pb2 # type: ignore +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore from google.cloud import bigtable_admin_v2 diff --git a/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_table_admin_set_iam_policy_async.py b/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_table_admin_set_iam_policy_async.py index e80c9caf3cb7..e21252ecabda 100644 --- a/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_table_admin_set_iam_policy_async.py +++ b/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_table_admin_set_iam_policy_async.py @@ -31,7 +31,7 @@ # - It may require specifying regional endpoints when creating the service # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.iam.v1 import iam_policy_pb2 # type: ignore +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore from google.cloud import bigtable_admin_v2 diff --git a/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_table_admin_set_iam_policy_sync.py b/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_table_admin_set_iam_policy_sync.py index beb9a47807ff..609086bc9243 100644 --- a/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_table_admin_set_iam_policy_sync.py +++ b/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_table_admin_set_iam_policy_sync.py @@ -31,7 +31,7 @@ # - It may require specifying regional endpoints when creating the service # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.iam.v1 import iam_policy_pb2 # type: ignore +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore from google.cloud import bigtable_admin_v2 diff --git a/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_table_admin_test_iam_permissions_async.py b/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_table_admin_test_iam_permissions_async.py index 44a5e56614f5..558c21079288 100644 --- a/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_table_admin_test_iam_permissions_async.py +++ b/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_table_admin_test_iam_permissions_async.py @@ -31,7 +31,7 @@ # - It may require specifying regional endpoints when creating the service # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.iam.v1 import iam_policy_pb2 # type: ignore +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore from google.cloud import bigtable_admin_v2 diff --git a/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_table_admin_test_iam_permissions_sync.py b/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_table_admin_test_iam_permissions_sync.py index 3a73a27d990d..97c9138a1bd7 100644 --- a/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_table_admin_test_iam_permissions_sync.py +++ b/packages/google-cloud-bigtable/samples/generated_samples/bigtableadmin_v2_generated_bigtable_table_admin_test_iam_permissions_sync.py @@ -31,7 +31,7 @@ # - It may require specifying regional endpoints when creating the service # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html -from google.iam.v1 import iam_policy_pb2 # type: ignore +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore from google.cloud import bigtable_admin_v2 diff --git a/packages/google-cloud-bigtable/setup.py b/packages/google-cloud-bigtable/setup.py index 1adac7449e79..80b0380b2b96 100644 --- a/packages/google-cloud-bigtable/setup.py +++ b/packages/google-cloud-bigtable/setup.py @@ -1,4 +1,5 @@ -# Copyright 2018 Google LLC +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,48 +12,51 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - -# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input` -# The source of truth for this file is `.librarian/generator-input` - - +# import io import os +import re -import setuptools +import setuptools # type: ignore package_root = os.path.abspath(os.path.dirname(__file__)) -# Package metadata. - name = "google-cloud-bigtable" + + description = "Google Cloud Bigtable API client library" -version = {} +version = None + with open(os.path.join(package_root, "google/cloud/bigtable/gapic_version.py")) as fp: - exec(fp.read(), version) -version = version["__version__"] + version_candidates = re.findall(r"(?<=\")\d+.\d+.\d+(?=\")", fp.read()) + assert len(version_candidates) == 1 + version = version_candidates[0] +if version[0] == "0": + release_status = "Development Status :: 4 - Beta" +else: + release_status = "Development Status :: 5 - Production/Stable" -# Should be one of: -# 'Development Status :: 3 - Alpha' -# 'Development Status :: 4 - Beta' -# 'Development Status :: 5 - Production/Stable' -release_status = "Development Status :: 5 - Production/Stable" dependencies = [ - "google-api-core[grpc] >= 2.17.0, <3.0.0", + "google-api-core[grpc] >= 2.11.0, <3.0.0", + # Exclude incompatible versions of `google-auth` + # See https://github.com/googleapis/google-cloud-python/issues/12364 + "google-auth >= 2.14.1, <3.0.0,!=2.24.0,!=2.25.0", + "grpcio >= 1.33.2, < 2.0.0", + "grpcio >= 1.75.1, < 2.0.0; python_version >= '3.14'", + "proto-plus >= 1.22.3, <2.0.0", + "proto-plus >= 1.25.0, <2.0.0; python_version >= '3.13'", + "protobuf >= 4.25.8, < 8.0.0", "google-cloud-core >= 1.4.4, <3.0.0", - "google-auth >= 2.23.0, <3.0.0,!=2.24.0,!=2.25.0", "grpc-google-iam-v1 >= 0.12.4, <1.0.0", - "proto-plus >= 1.22.3, <2.0.0", - "proto-plus >= 1.25.0, <2.0.0; python_version>='3.13'", - "protobuf>=3.20.2,<7.0.0,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", "google-crc32c>=1.5.0, <2.0.0dev", ] -extras = {"libcst": "libcst >= 0.2.5"} - +extras = { + "libcst": "libcst >= 0.2.5", +} -# Setup boilerplate below this line. +url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-bigtable" package_root = os.path.abspath(os.path.dirname(__file__)) @@ -60,8 +64,6 @@ with io.open(readme_filename, encoding="utf-8") as readme_file: readme = readme_file.read() -# Only include packages under the 'google' namespace. Do not include tests, -# benchmarks, etc. packages = [ package for package in setuptools.find_namespace_packages() @@ -76,14 +78,13 @@ author="Google LLC", author_email="googleapis-packages@google.com", license="Apache 2.0", - url="https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-bigtable", + url=url, classifiers=[ release_status, "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Programming Language :: Python", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -95,9 +96,9 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, + python_requires=">=3.9", install_requires=dependencies, extras_require=extras, - python_requires=">=3.7", include_package_data=True, zip_safe=False, ) diff --git a/packages/google-cloud-bigtable/testing/.gitignore b/packages/google-cloud-bigtable/testing/.gitignore deleted file mode 100644 index b05fbd630881..000000000000 --- a/packages/google-cloud-bigtable/testing/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -test-env.sh -service-account.json -client-secrets.json \ No newline at end of file diff --git a/packages/google-cloud-bigtable/testing/constraints-3.10.txt b/packages/google-cloud-bigtable/testing/constraints-3.10.txt index e69de29bb2d1..7599dea499ed 100644 --- a/packages/google-cloud-bigtable/testing/constraints-3.10.txt +++ b/packages/google-cloud-bigtable/testing/constraints-3.10.txt @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +google-auth +grpcio +proto-plus +protobuf +# cryptography is a direct dependency of google-auth +cryptography diff --git a/packages/google-cloud-bigtable/testing/constraints-3.11.txt b/packages/google-cloud-bigtable/testing/constraints-3.11.txt index e69de29bb2d1..7599dea499ed 100644 --- a/packages/google-cloud-bigtable/testing/constraints-3.11.txt +++ b/packages/google-cloud-bigtable/testing/constraints-3.11.txt @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +google-auth +grpcio +proto-plus +protobuf +# cryptography is a direct dependency of google-auth +cryptography diff --git a/packages/google-cloud-bigtable/testing/constraints-3.12.txt b/packages/google-cloud-bigtable/testing/constraints-3.12.txt index e69de29bb2d1..7599dea499ed 100644 --- a/packages/google-cloud-bigtable/testing/constraints-3.12.txt +++ b/packages/google-cloud-bigtable/testing/constraints-3.12.txt @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# This constraints file is required for unit tests. +# List all library dependencies and extras in this file. +google-api-core +google-auth +grpcio +proto-plus +protobuf +# cryptography is a direct dependency of google-auth +cryptography diff --git a/packages/google-cloud-bigtable/testing/constraints-3.13.txt b/packages/google-cloud-bigtable/testing/constraints-3.13.txt index e69de29bb2d1..1e93c60e50aa 100644 --- a/packages/google-cloud-bigtable/testing/constraints-3.13.txt +++ b/packages/google-cloud-bigtable/testing/constraints-3.13.txt @@ -0,0 +1,12 @@ +# We use the constraints file for the latest Python version +# (currently this file) to check that the latest +# major versions of dependencies are supported in setup.py. +# List all library dependencies and extras in this file. +# Require the latest major version be installed for each dependency. +# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# Then this file should have google-cloud-foo>=1 +google-api-core>=2 +google-auth>=2 +grpcio>=1 +proto-plus>=1 +protobuf>=6 diff --git a/packages/google-cloud-bigtable/testing/constraints-3.14.txt b/packages/google-cloud-bigtable/testing/constraints-3.14.txt index e69de29bb2d1..1e93c60e50aa 100644 --- a/packages/google-cloud-bigtable/testing/constraints-3.14.txt +++ b/packages/google-cloud-bigtable/testing/constraints-3.14.txt @@ -0,0 +1,12 @@ +# We use the constraints file for the latest Python version +# (currently this file) to check that the latest +# major versions of dependencies are supported in setup.py. +# List all library dependencies and extras in this file. +# Require the latest major version be installed for each dependency. +# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# Then this file should have google-cloud-foo>=1 +google-api-core>=2 +google-auth>=2 +grpcio>=1 +proto-plus>=1 +protobuf>=6 diff --git a/packages/google-cloud-bigtable/testing/constraints-3.7.txt b/packages/google-cloud-bigtable/testing/constraints-3.7.txt deleted file mode 100644 index 023133380894..000000000000 --- a/packages/google-cloud-bigtable/testing/constraints-3.7.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List *all* library dependencies and extras in this file. -# Pin the version to the lower bound. -# -# e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", -# Then this file should have foo==1.14.0 -google-api-core==2.17.0 -google-auth==2.23.0 -google-cloud-core==2.0.0 -grpc-google-iam-v1==0.12.4 -proto-plus==1.22.3 -libcst==0.2.5 -protobuf==3.20.2 - diff --git a/packages/google-cloud-bigtable/testing/constraints-3.8.txt b/packages/google-cloud-bigtable/testing/constraints-3.8.txt deleted file mode 100644 index a7e4616c9efb..000000000000 --- a/packages/google-cloud-bigtable/testing/constraints-3.8.txt +++ /dev/null @@ -1,15 +0,0 @@ -# This constraints file is used to check that lower bounds -# are correct in setup.py -# List *all* library dependencies and extras in this file. -# Pin the version to the lower bound. -# -# e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", -# Then this file should have foo==1.14.0 -google-api-core==2.17.0 -google-auth==2.23.0 -google-cloud-core==2.0.0 -grpc-google-iam-v1==0.12.4 -proto-plus==1.22.3 -libcst==0.2.5 -protobuf==3.20.2 -pytest-asyncio==0.21.2 diff --git a/packages/google-cloud-bigtable/testing/constraints-3.9.txt b/packages/google-cloud-bigtable/testing/constraints-3.9.txt index e69de29bb2d1..dffda9791f3d 100644 --- a/packages/google-cloud-bigtable/testing/constraints-3.9.txt +++ b/packages/google-cloud-bigtable/testing/constraints-3.9.txt @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List all library dependencies and extras in this file, +# pinning their versions to their lower bounds. +# For example, if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0", +# then this file should have google-cloud-foo==1.14.0 +google-api-core==2.21.0 +google-cloud-core==2.0.0 +grpc-google-iam-v1==0.12.4 +google-auth==2.35.0 +# TODO(https://github.com/googleapis/gapic-generator-python/issues/2453) +# Add the minimum supported version of grpcio to constraints files +proto-plus==1.22.3 +protobuf==4.25.8 diff --git a/packages/google-cloud-bigtable/tests/unit/gapic/bigtable_admin_v2/test_bigtable_instance_admin.py b/packages/google-cloud-bigtable/tests/unit/gapic/bigtable_admin_v2/test_bigtable_instance_admin.py index b0cdbd36a233..53f15a597a29 100644 --- a/packages/google-cloud-bigtable/tests/unit/gapic/bigtable_admin_v2/test_bigtable_instance_admin.py +++ b/packages/google-cloud-bigtable/tests/unit/gapic/bigtable_admin_v2/test_bigtable_instance_admin.py @@ -24,7 +24,7 @@ import json import math -from collections.abc import AsyncIterable, Iterable +from collections.abc import AsyncIterable, Iterable, Mapping, Sequence import grpc import pytest @@ -43,7 +43,14 @@ except ImportError: # pragma: NO COVER HAS_GOOGLE_AUTH_AIO = False +import google.api_core.operation_async as operation_async # type: ignore import google.auth +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore +import google.iam.v1.options_pb2 as options_pb2 # type: ignore +import google.iam.v1.policy_pb2 as policy_pb2 # type: ignore +import google.protobuf.field_mask_pb2 as field_mask_pb2 # type: ignore +import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore +import google.type.expr_pb2 as expr_pb2 # type: ignore from google.api_core import ( client_options, future, @@ -51,7 +58,6 @@ grpc_helpers, grpc_helpers_async, operation, - operation_async, # type: ignore operations_v1, path_template, ) @@ -59,18 +65,8 @@ from google.api_core import retry as retries from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError -from google.iam.v1 import ( - iam_policy_pb2, # type: ignore - options_pb2, # type: ignore - policy_pb2, # type: ignore -) from google.longrunning import operations_pb2 # type: ignore from google.oauth2 import service_account -from google.protobuf import ( - field_mask_pb2, # type: ignore - timestamp_pb2, # type: ignore -) -from google.type import expr_pb2 # type: ignore from google.cloud.bigtable_admin_v2.services.bigtable_instance_admin import ( BigtableInstanceAdminAsyncClient, @@ -139,6 +135,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BigtableInstanceAdminClient._get_default_mtls_endpoint(None) is None assert ( @@ -161,6 +158,10 @@ def test__get_default_mtls_endpoint(): BigtableInstanceAdminClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + BigtableInstanceAdminClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1019,10 +1020,9 @@ def test_bigtable_instance_admin_client_get_mtls_endpoint_and_cert_source(client client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint, ) - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source(options) + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source(options) + ) assert api_endpoint == mock_api_endpoint assert cert_source is expected_cert_source @@ -1067,10 +1067,9 @@ def test_bigtable_instance_admin_client_get_mtls_endpoint_and_cert_source(client client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint, ) - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source(options) + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source(options) + ) assert api_endpoint == mock_api_endpoint assert cert_source is expected_cert_source @@ -1106,10 +1105,9 @@ def test_bigtable_instance_admin_client_get_mtls_endpoint_and_cert_source(client "google.auth.transport.mtls.default_client_cert_source", return_value=mock_client_cert_source, ): - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source() + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source() + ) assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT assert cert_source == mock_client_cert_source diff --git a/packages/google-cloud-bigtable/tests/unit/gapic/bigtable_admin_v2/test_bigtable_table_admin.py b/packages/google-cloud-bigtable/tests/unit/gapic/bigtable_admin_v2/test_bigtable_table_admin.py index 75ee59780133..b77c531feab0 100644 --- a/packages/google-cloud-bigtable/tests/unit/gapic/bigtable_admin_v2/test_bigtable_table_admin.py +++ b/packages/google-cloud-bigtable/tests/unit/gapic/bigtable_admin_v2/test_bigtable_table_admin.py @@ -24,7 +24,7 @@ import json import math -from collections.abc import AsyncIterable, Iterable +from collections.abc import AsyncIterable, Iterable, Mapping, Sequence import grpc import pytest @@ -43,7 +43,17 @@ except ImportError: # pragma: NO COVER HAS_GOOGLE_AUTH_AIO = False +import google.api_core.operation_async as operation_async # type: ignore import google.auth +import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore +import google.iam.v1.options_pb2 as options_pb2 # type: ignore +import google.iam.v1.policy_pb2 as policy_pb2 # type: ignore +import google.protobuf.any_pb2 as any_pb2 # type: ignore +import google.protobuf.duration_pb2 as duration_pb2 # type: ignore +import google.protobuf.field_mask_pb2 as field_mask_pb2 # type: ignore +import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore +import google.rpc.status_pb2 as status_pb2 # type: ignore +import google.type.expr_pb2 as expr_pb2 # type: ignore from google.api_core import ( client_options, future, @@ -51,7 +61,6 @@ grpc_helpers, grpc_helpers_async, operation, - operation_async, # type: ignore operations_v1, path_template, ) @@ -59,21 +68,8 @@ from google.api_core import retry as retries from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError -from google.iam.v1 import ( - iam_policy_pb2, # type: ignore - options_pb2, # type: ignore - policy_pb2, # type: ignore -) from google.longrunning import operations_pb2 # type: ignore from google.oauth2 import service_account -from google.protobuf import ( - any_pb2, # type: ignore - duration_pb2, # type: ignore - field_mask_pb2, # type: ignore - timestamp_pb2, # type: ignore -) -from google.rpc import status_pb2 # type: ignore -from google.type import expr_pb2 # type: ignore from google.cloud.bigtable_admin_v2.services.bigtable_table_admin import ( BaseBigtableTableAdminAsyncClient, @@ -138,6 +134,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BaseBigtableTableAdminClient._get_default_mtls_endpoint(None) is None assert ( @@ -160,6 +157,10 @@ def test__get_default_mtls_endpoint(): BaseBigtableTableAdminClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi ) + assert ( + BaseBigtableTableAdminClient._get_default_mtls_endpoint(custom_endpoint) + == custom_endpoint + ) def test__read_environment_variables(): @@ -1022,10 +1023,9 @@ def test_base_bigtable_table_admin_client_get_mtls_endpoint_and_cert_source( client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint, ) - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source(options) + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source(options) + ) assert api_endpoint == mock_api_endpoint assert cert_source is expected_cert_source @@ -1070,10 +1070,9 @@ def test_base_bigtable_table_admin_client_get_mtls_endpoint_and_cert_source( client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint, ) - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source(options) + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source(options) + ) assert api_endpoint == mock_api_endpoint assert cert_source is expected_cert_source @@ -1109,10 +1108,9 @@ def test_base_bigtable_table_admin_client_get_mtls_endpoint_and_cert_source( "google.auth.transport.mtls.default_client_cert_source", return_value=mock_client_cert_source, ): - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source() + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source() + ) assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT assert cert_source == mock_client_cert_source diff --git a/packages/google-cloud-bigtable/tests/unit/gapic/bigtable_v2/test_bigtable.py b/packages/google-cloud-bigtable/tests/unit/gapic/bigtable_v2/test_bigtable.py index 8ce4f4ea576a..2ff52a61ebe7 100644 --- a/packages/google-cloud-bigtable/tests/unit/gapic/bigtable_v2/test_bigtable.py +++ b/packages/google-cloud-bigtable/tests/unit/gapic/bigtable_v2/test_bigtable.py @@ -24,7 +24,7 @@ import json import math -from collections.abc import AsyncIterable, Iterable +from collections.abc import AsyncIterable, Iterable, Mapping, Sequence import grpc import pytest @@ -44,6 +44,9 @@ HAS_GOOGLE_AUTH_AIO = False import google.auth +import google.protobuf.duration_pb2 as duration_pb2 # type: ignore +import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore +import google.type.date_pb2 as date_pb2 # type: ignore from google.api_core import ( client_options, gapic_v1, @@ -56,11 +59,6 @@ from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.oauth2 import service_account -from google.protobuf import ( - duration_pb2, # type: ignore - timestamp_pb2, # type: ignore -) -from google.type import date_pb2 # type: ignore from google.cloud.bigtable_v2.services.bigtable import ( BigtableAsyncClient, @@ -123,6 +121,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BigtableClient._get_default_mtls_endpoint(None) is None assert BigtableClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -139,6 +138,7 @@ def test__get_default_mtls_endpoint(): == sandbox_mtls_endpoint ) assert BigtableClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert BigtableClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): @@ -916,10 +916,9 @@ def test_bigtable_client_get_mtls_endpoint_and_cert_source(client_class): client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint, ) - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source(options) + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source(options) + ) assert api_endpoint == mock_api_endpoint assert cert_source is expected_cert_source @@ -964,10 +963,9 @@ def test_bigtable_client_get_mtls_endpoint_and_cert_source(client_class): client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint, ) - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source(options) + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source(options) + ) assert api_endpoint == mock_api_endpoint assert cert_source is expected_cert_source @@ -1003,10 +1001,9 @@ def test_bigtable_client_get_mtls_endpoint_and_cert_source(client_class): "google.auth.transport.mtls.default_client_cert_source", return_value=mock_client_cert_source, ): - ( - api_endpoint, - cert_source, - ) = client_class.get_mtls_endpoint_and_cert_source() + api_endpoint, cert_source = ( + client_class.get_mtls_endpoint_and_cert_source() + ) assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT assert cert_source == mock_client_cert_source From 45d6ab4fd0e71c63a2c9a02d19665e3b74f3568c Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Fri, 3 Apr 2026 02:58:50 +0000 Subject: [PATCH 04/12] adjust formatting --- .../google/cloud/bigtable/data/_async/client.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_async/client.py b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_async/client.py index 3d825ba875c4..62d233bed3ba 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_async/client.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_async/client.py @@ -126,11 +126,11 @@ BigtableMetricsInterceptor as MetricsInterceptorType, ) from google.cloud.bigtable.data._sync_autogen.mutations_batcher import _MB_SIZE - from google.cloud.bigtable_v2.services.bigtable import ( - BigtableClient as GapicClient, # type: ignore + from google.cloud.bigtable_v2.services.bigtable import ( # type: ignore + BigtableClient as GapicClient, ) - from google.cloud.bigtable_v2.services.bigtable.transports import ( - BigtableGrpcTransport as TransportType, # type: ignore + from google.cloud.bigtable_v2.services.bigtable.transports import ( # type: ignore + BigtableGrpcTransport as TransportType, ) if TYPE_CHECKING: From ab970727988a5122ce64a7a3770d4963c49bcc53 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Fri, 3 Apr 2026 03:29:25 +0000 Subject: [PATCH 05/12] address feedback --- .../packages/google-cloud-bigtable/.repo-metadata.json | 2 +- packages/google-cloud-bigtable/.repo-metadata.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.librarian/generator-input/packages/google-cloud-bigtable/.repo-metadata.json b/.librarian/generator-input/packages/google-cloud-bigtable/.repo-metadata.json index 432f28596c8e..011989a371e5 100644 --- a/.librarian/generator-input/packages/google-cloud-bigtable/.repo-metadata.json +++ b/.librarian/generator-input/packages/google-cloud-bigtable/.repo-metadata.json @@ -58,7 +58,7 @@ "description": "Demonstrates of Cloud Bigtable using HappyBase. This sample creates a Bigtable client, connects to an instance and then to a table, then closes the connection.", "file": "main.py", "runnable": true, - "custom_content": "
usage: main.py [-h] [--table TABLE] project_id instance_id
usage: main.py [-h] [--table TABLE] project_id instance_id


positional arguments:
  project_id     Your Cloud Platform project ID.
  instance_id    ID of the Cloud Bigtable instance to connect to.


optional arguments:
  -h, --help     show this help message and exit
  --table TABLE  Existing table used in the quickstart. (default: my-table)usage: main.py [-h] [--table TABLE] project_id instance_id
usage: main.py [-h] [--table TABLE] project_id instance_id


positional arguments:
  project_id     Your Cloud Platform project ID.
  instance_id    ID of the Cloud Bigtable instance to connect to.


optional arguments:
  -h, --help     show this help message and exit
  --table TABLE  Existing table used in the quickstart. (default: my-table)
", "override_path": "quickstart_happybase" }, { diff --git a/packages/google-cloud-bigtable/.repo-metadata.json b/packages/google-cloud-bigtable/.repo-metadata.json index 432f28596c8e..011989a371e5 100644 --- a/packages/google-cloud-bigtable/.repo-metadata.json +++ b/packages/google-cloud-bigtable/.repo-metadata.json @@ -58,7 +58,7 @@ "description": "Demonstrates of Cloud Bigtable using HappyBase. This sample creates a Bigtable client, connects to an instance and then to a table, then closes the connection.", "file": "main.py", "runnable": true, - "custom_content": "
usage: main.py [-h] [--table TABLE] project_id instance_id
usage: main.py [-h] [--table TABLE] project_id instance_id


positional arguments:
  project_id     Your Cloud Platform project ID.
  instance_id    ID of the Cloud Bigtable instance to connect to.


optional arguments:
  -h, --help     show this help message and exit
  --table TABLE  Existing table used in the quickstart. (default: my-table)usage: main.py [-h] [--table TABLE] project_id instance_id
usage: main.py [-h] [--table TABLE] project_id instance_id


positional arguments:
  project_id     Your Cloud Platform project ID.
  instance_id    ID of the Cloud Bigtable instance to connect to.


optional arguments:
  -h, --help     show this help message and exit
  --table TABLE  Existing table used in the quickstart. (default: my-table)
", "override_path": "quickstart_happybase" }, { From b984329037c77430d6b1e1dc0b8db1c0e4c2c44d Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Fri, 3 Apr 2026 03:32:32 +0000 Subject: [PATCH 06/12] lint --- .../unit/data/execute_query/test_query_result_row_reader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/google-cloud-bigtable/tests/unit/data/execute_query/test_query_result_row_reader.py b/packages/google-cloud-bigtable/tests/unit/data/execute_query/test_query_result_row_reader.py index c2ccc679a19d..e14b41826cdd 100644 --- a/packages/google-cloud-bigtable/tests/unit/data/execute_query/test_query_result_row_reader.py +++ b/packages/google-cloud-bigtable/tests/unit/data/execute_query/test_query_result_row_reader.py @@ -170,7 +170,7 @@ def pass_values_to_byte_cursor(byte_cursor, iterable): returned_values = [] def intercept_return_values(func): - nonlocal intercept_return_values + nonlocal intercept_return_values # noqa: F824 def wrapped(*args, **kwargs): value = func(*args, **kwargs) From fa62ff29fc30da0016a389e7337946e82a99c904 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Fri, 3 Apr 2026 03:33:51 +0000 Subject: [PATCH 07/12] run nox -s generate_sync --- .../data/_sync_autogen/_mutate_rows.py | 8 +- .../bigtable/data/_sync_autogen/_read_rows.py | 3 - .../data/_sync_autogen/_swappable_channel.py | 5 +- .../bigtable/data/_sync_autogen/client.py | 53 ++++++------- .../data/_sync_autogen/metrics_interceptor.py | 7 +- .../data/_sync_autogen/mutations_batcher.py | 18 ++--- .../_sync_autogen/execute_query_iterator.py | 7 +- .../client_handler_data_sync_autogen.py | 4 +- .../admin_overlay/test_system_autogen.py | 11 +-- .../tests/system/data/test_system_autogen.py | 39 +++++---- .../data/_sync_autogen/test__mutate_rows.py | 5 +- .../data/_sync_autogen/test__read_rows.py | 6 +- .../_sync_autogen/test__swappable_channel.py | 1 - .../unit/data/_sync_autogen/test_client.py | 79 ++++++++----------- .../_sync_autogen/test_metrics_interceptor.py | 1 - .../_sync_autogen/test_mutations_batcher.py | 13 ++- .../test_read_rows_acceptance.py | 4 - .../_sync_autogen/test_query_iterator.py | 3 - 18 files changed, 105 insertions(+), 162 deletions(-) diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/_mutate_rows.py b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/_mutate_rows.py index 5bb4a81eea6a..fad8e2469ecb 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/_mutate_rows.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/_mutate_rows.py @@ -16,12 +16,9 @@ # This file is automatically generated by CrossSync. Do not edit manually. from __future__ import annotations - from typing import TYPE_CHECKING, Sequence - from google.api_core import exceptions as core_exceptions from google.api_core import retry as retries - import google.cloud.bigtable.data.exceptions as bt_exceptions import google.cloud.bigtable_v2.types.bigtable as types_pb from google.cloud.bigtable.data._cross_sync import CrossSync @@ -35,10 +32,10 @@ ) if TYPE_CHECKING: + from google.cloud.bigtable.data.mutations import RowMutationEntry from google.cloud.bigtable.data._sync_autogen.client import ( _DataApiTarget as TargetType, ) - from google.cloud.bigtable.data.mutations import RowMutationEntry from google.cloud.bigtable_v2.services.bigtable.client import ( BigtableClient as GapicClientType, ) @@ -137,8 +134,7 @@ def _run_attempt(self): GoogleAPICallError: if the gapic rpc fails""" request_entries = [self.mutations[idx].proto for idx in self.remaining_indices] active_request_indices = { - req_idx: orig_idx - for (req_idx, orig_idx) in enumerate(self.remaining_indices) + req_idx: orig_idx for req_idx, orig_idx in enumerate(self.remaining_indices) } self.remaining_indices = [] if not request_entries: diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/_read_rows.py b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/_read_rows.py index a74374988161..9ccde8b07761 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/_read_rows.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/_read_rows.py @@ -17,12 +17,9 @@ # This file is automatically generated by CrossSync. Do not edit manually. from __future__ import annotations - from typing import TYPE_CHECKING, Sequence - from google.api_core import retry as retries from google.api_core.retry import exponential_sleep_generator - from google.cloud.bigtable.data._cross_sync import CrossSync from google.cloud.bigtable.data._helpers import ( _attempt_timeout_generator, diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/_swappable_channel.py b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/_swappable_channel.py index 93f2b44a6df6..78ba129d98c5 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/_swappable_channel.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/_swappable_channel.py @@ -16,10 +16,9 @@ # This file is automatically generated by CrossSync. Do not edit manually. from __future__ import annotations - from typing import Callable - -from grpc import Channel, ChannelConnectivity +from grpc import ChannelConnectivity +from grpc import Channel class _WrappedChannel(Channel): diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/client.py b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/client.py index b465e7a0b0be..a5873ecc0931 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/client.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/client.py @@ -17,7 +17,6 @@ # This file is automatically generated by CrossSync. Do not edit manually. from __future__ import annotations - import abc import concurrent.futures import os @@ -25,8 +24,7 @@ import time import warnings from functools import partial -from typing import TYPE_CHECKING, Any, Callable, Iterable, Optional, Sequence, Set, cast - +from typing import TYPE_CHECKING, Any, Callable, Optional, Sequence, Set, cast import google.auth._default import google.auth.credentials from google.api_core import client_options as client_options_lib @@ -41,8 +39,7 @@ from google.cloud.environment_vars import BIGTABLE_EMULATOR from google.protobuf.internal.enum_type_wrapper import EnumTypeWrapper from google.protobuf.message import Message -from grpc import Channel, insecure_channel, intercept_channel - +from grpc import Channel from google.cloud.bigtable.client import _DEFAULT_BIGTABLE_EMULATOR_CLIENT from google.cloud.bigtable.data._cross_sync import CrossSync from google.cloud.bigtable.data._helpers import ( @@ -58,13 +55,6 @@ _WarmedInstanceKey, ) from google.cloud.bigtable.data._metrics import BigtableClientSideMetricsController -from google.cloud.bigtable.data._sync_autogen._swappable_channel import ( - SwappableChannel as SwappableChannelType, -) -from google.cloud.bigtable.data._sync_autogen.metrics_interceptor import ( - BigtableMetricsInterceptor as MetricsInterceptorType, -) -from google.cloud.bigtable.data._sync_autogen.mutations_batcher import _MB_SIZE from google.cloud.bigtable.data.exceptions import ( FailedQueryShardError, ShardedReadRowsExceptionGroup, @@ -88,10 +78,6 @@ RowFilterChain, StripValueTransformerFilter, ) -from google.cloud.bigtable_v2.services.bigtable import BigtableClient as GapicClient -from google.cloud.bigtable_v2.services.bigtable.transports import ( - BigtableGrpcTransport as TransportType, -) from google.cloud.bigtable_v2.services.bigtable.transports.base import ( DEFAULT_CLIENT_INFO, ) @@ -102,6 +88,19 @@ ReadModifyWriteRowRequest, SampleRowKeysRequest, ) +from typing import Iterable +from grpc import insecure_channel, intercept_channel +from google.cloud.bigtable.data._sync_autogen._swappable_channel import ( + SwappableChannel as SwappableChannelType, +) +from google.cloud.bigtable.data._sync_autogen.metrics_interceptor import ( + BigtableMetricsInterceptor as MetricsInterceptorType, +) +from google.cloud.bigtable.data._sync_autogen.mutations_batcher import _MB_SIZE +from google.cloud.bigtable_v2.services.bigtable import BigtableClient as GapicClient +from google.cloud.bigtable_v2.services.bigtable.transports import ( + BigtableGrpcTransport as TransportType, +) if TYPE_CHECKING: from google.cloud.bigtable.data._helpers import RowKeySamples, ShardedQuery @@ -320,7 +319,7 @@ def _ping_and_warm_instances( ], wait_for_ready=True, ) - for (instance_name, app_profile_id) in instance_list + for instance_name, app_profile_id in instance_list ] result_list = CrossSync._Sync_Impl.gather_partials( partial_list, return_exceptions=True, sync_executor=self._executor @@ -669,7 +668,7 @@ def execute_query( prepare_predicate = retries.if_exception_type( *[_get_error_type(e) for e in prepare_retryable_errors] ) - (prepare_operation_timeout, prepare_attempt_timeout) = _align_timeouts( + prepare_operation_timeout, prepare_attempt_timeout = _align_timeouts( prepare_operation_timeout, prepare_attempt_timeout ) prepare_sleep_generator = retries.exponential_sleep_generator(0.01, 2, 60) @@ -695,7 +694,7 @@ def execute_query( "prepared_query": prepare_result.prepared_query, "params": pb_params, } - (operation_timeout, attempt_timeout) = _align_timeouts( + operation_timeout, attempt_timeout = _align_timeouts( operation_timeout, attempt_timeout ) return CrossSync._Sync_Impl.ExecuteQueryIterator( @@ -896,7 +895,7 @@ def read_rows_stream( from any retries that failed google.api_core.exceptions.GoogleAPIError: raised if the request encounters an unrecoverable error """ - (operation_timeout, attempt_timeout) = _get_timeouts( + operation_timeout, attempt_timeout = _get_timeouts( operation_timeout, attempt_timeout, self ) retryable_excs = _get_retryable_errors(retryable_errors, self) @@ -1042,7 +1041,7 @@ def read_rows_sharded( ValueError: if the query_list is empty""" if not sharded_query: raise ValueError("empty sharded_query") - (operation_timeout, attempt_timeout) = _get_timeouts( + operation_timeout, attempt_timeout = _get_timeouts( operation_timeout, attempt_timeout, self ) rpc_timeout_generator = _attempt_timeout_generator( @@ -1085,7 +1084,7 @@ def read_rows_with_semaphore(query): raise ShardedReadRowsExceptionGroup( [ FailedQueryShardError(idx, sharded_query[idx], e) - for (idx, e) in error_dict.items() + for idx, e in error_dict.items() ], results_list, len(sharded_query), @@ -1175,7 +1174,7 @@ def sample_row_keys( from any retries that failed google.api_core.exceptions.GoogleAPIError: raised if the request encounters an unrecoverable error """ - (operation_timeout, attempt_timeout) = _get_timeouts( + operation_timeout, attempt_timeout = _get_timeouts( operation_timeout, attempt_timeout, self ) attempt_timeout_gen = _attempt_timeout_generator( @@ -1290,7 +1289,7 @@ def mutate_row( google.api_core.exceptions.GoogleAPIError: raised on non-idempotent operations that cannot be safely retried. ValueError: if invalid arguments are provided""" - (operation_timeout, attempt_timeout) = _get_timeouts( + operation_timeout, attempt_timeout = _get_timeouts( operation_timeout, attempt_timeout, self ) if not mutations: @@ -1362,7 +1361,7 @@ def bulk_mutate_rows( MutationsExceptionGroup: if one or more mutations fails Contains details about any failed entries in .exceptions ValueError: if invalid arguments are provided""" - (operation_timeout, attempt_timeout) = _get_timeouts( + operation_timeout, attempt_timeout = _get_timeouts( operation_timeout, attempt_timeout, self ) retryable_excs = _get_retryable_errors(retryable_errors, self) @@ -1415,7 +1414,7 @@ def check_and_mutate_row( bool indicating whether the predicate was true or false Raises: google.api_core.exceptions.GoogleAPIError: exceptions from grpc call""" - (operation_timeout, _) = _get_timeouts(operation_timeout, None, self) + operation_timeout, _ = _get_timeouts(operation_timeout, None, self) if true_case_mutations is not None and ( not isinstance(true_case_mutations, list) ): @@ -1470,7 +1469,7 @@ def read_modify_write_row( Raises: google.api_core.exceptions.GoogleAPIError: exceptions from grpc call ValueError: if invalid arguments are provided""" - (operation_timeout, _) = _get_timeouts(operation_timeout, None, self) + operation_timeout, _ = _get_timeouts(operation_timeout, None, self) if operation_timeout <= 0: raise ValueError("operation_timeout must be greater than 0") if rules is not None and (not isinstance(rules, list)): diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/metrics_interceptor.py b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/metrics_interceptor.py index 59749c67396c..fc60c6e4e89b 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/metrics_interceptor.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/metrics_interceptor.py @@ -15,18 +15,15 @@ # This file is automatically generated by CrossSync. Do not edit manually. from __future__ import annotations - import time from functools import wraps from typing import Sequence - -from grpc import UnaryStreamClientInterceptor, UnaryUnaryClientInterceptor - from google.cloud.bigtable.data._metrics.data_model import ( ActiveOperationMetric, OperationState, OperationType, ) +from grpc import UnaryStreamClientInterceptor, UnaryUnaryClientInterceptor def _with_active_operation(func): @@ -54,7 +51,7 @@ def _get_metadata(source) -> dict[str, str | bytes] | None: try: metadata: Sequence[tuple[str, str | bytes]] metadata = source.trailing_metadata() + source.initial_metadata() - return {k: v for (k, v) in metadata} + return {k: v for k, v in metadata} except Exception: return None diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/mutations_batcher.py b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/mutations_batcher.py index d14b476f87b8..41952f73ba98 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/mutations_batcher.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/mutations_batcher.py @@ -16,13 +16,11 @@ # This file is automatically generated by CrossSync. Do not edit manually. from __future__ import annotations - import atexit import concurrent.futures import warnings from collections import deque from typing import TYPE_CHECKING, Sequence, cast - from google.cloud.bigtable.data._cross_sync import CrossSync from google.cloud.bigtable.data._helpers import ( TABLE_DEFAULT, @@ -39,10 +37,10 @@ ) if TYPE_CHECKING: + from google.cloud.bigtable.data.mutations import RowMutationEntry from google.cloud.bigtable.data._sync_autogen.client import ( _DataApiTarget as TargetType, ) - from google.cloud.bigtable.data.mutations import RowMutationEntry _MB_SIZE = 1024 * 1024 @@ -201,7 +199,7 @@ def __init__( batch_retryable_errors: Sequence[type[Exception]] | TABLE_DEFAULT = TABLE_DEFAULT.MUTATE_ROWS, ): - (self._operation_timeout, self._attempt_timeout) = _get_timeouts( + self._operation_timeout, self._attempt_timeout = _get_timeouts( batch_operation_timeout, batch_attempt_timeout, table ) self._retryable_errors: list[type[Exception]] = _get_retryable_errors( @@ -210,7 +208,7 @@ def __init__( self._closed = CrossSync._Sync_Impl.Event() self._target = table self._staged_entries: list[RowMutationEntry] = [] - (self._staged_count, self._staged_bytes) = (0, 0) + self._staged_count, self._staged_bytes = (0, 0) self._flow_control = CrossSync._Sync_Impl._FlowControl( flow_control_max_mutation_count, flow_control_max_bytes ) @@ -291,8 +289,8 @@ def _schedule_flush(self) -> CrossSync._Sync_Impl.Future[None] | None: Future[None] | None: future representing the background task, if started""" if self._staged_entries: - (entries, self._staged_entries) = (self._staged_entries, []) - (self._staged_count, self._staged_bytes) = (0, 0) + entries, self._staged_entries = (self._staged_entries, []) + self._staged_count, self._staged_bytes = (0, 0) new_task = CrossSync._Sync_Impl.create_task( self._flush_internal, entries, sync_executor=self._sync_flush_executor ) @@ -371,14 +369,14 @@ def _raise_exceptions(self): Raises: MutationsExceptionGroup: exception group with all unreported exceptions""" if self._oldest_exceptions or self._newest_exceptions: - (oldest, self._oldest_exceptions) = (self._oldest_exceptions, []) + oldest, self._oldest_exceptions = (self._oldest_exceptions, []) newest = list(self._newest_exceptions) self._newest_exceptions.clear() - (entry_count, self._entries_processed_since_last_raise) = ( + entry_count, self._entries_processed_since_last_raise = ( self._entries_processed_since_last_raise, 0, ) - (exc_count, self._exceptions_since_last_raise) = ( + exc_count, self._exceptions_since_last_raise = ( self._exceptions_since_last_raise, 0, ) diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable/data/execute_query/_sync_autogen/execute_query_iterator.py b/packages/google-cloud-bigtable/google/cloud/bigtable/data/execute_query/_sync_autogen/execute_query_iterator.py index 373673ec6887..d00457724eb5 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable/data/execute_query/_sync_autogen/execute_query_iterator.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable/data/execute_query/_sync_autogen/execute_query_iterator.py @@ -16,13 +16,10 @@ # This file is automatically generated by CrossSync. Do not edit manually. from __future__ import annotations - from typing import TYPE_CHECKING, Any, Dict, Optional, Sequence, Tuple - from google.api_core import retry as retries from google.protobuf.internal.enum_type_wrapper import EnumTypeWrapper from google.protobuf.message import Message - from google.cloud.bigtable.data._cross_sync import CrossSync from google.cloud.bigtable.data._helpers import ( _attempt_timeout_generator, @@ -42,9 +39,7 @@ from google.cloud.bigtable_v2.types.bigtable import ( ExecuteQueryRequest as ExecuteQueryRequestPB, ) -from google.cloud.bigtable_v2.types.bigtable import ( - ExecuteQueryResponse, -) +from google.cloud.bigtable_v2.types.bigtable import ExecuteQueryResponse if TYPE_CHECKING: from google.cloud.bigtable.data import BigtableDataClient as DataClientType diff --git a/packages/google-cloud-bigtable/test_proxy/handlers/client_handler_data_sync_autogen.py b/packages/google-cloud-bigtable/test_proxy/handlers/client_handler_data_sync_autogen.py index 0e557f058f39..16b8382fca41 100644 --- a/packages/google-cloud-bigtable/test_proxy/handlers/client_handler_data_sync_autogen.py +++ b/packages/google-cloud-bigtable/test_proxy/handlers/client_handler_data_sync_autogen.py @@ -190,9 +190,7 @@ async def ExecuteQuery(self, request, **kwargs): app_profile_id = self.app_profile_id or request.get("app_profile_id", None) query = request.get("query") params = request.get("params") or {} - (formatted_params, parameter_types) = sql_encoding_helpers.convert_params( - params - ) + formatted_params, parameter_types = sql_encoding_helpers.convert_params(params) operation_timeout = ( kwargs.get("operation_timeout", self.per_operation_timeout) or 20 ) diff --git a/packages/google-cloud-bigtable/tests/system/admin_overlay/test_system_autogen.py b/packages/google-cloud-bigtable/tests/system/admin_overlay/test_system_autogen.py index adc5935140c9..d791da75ab13 100644 --- a/packages/google-cloud-bigtable/tests/system/admin_overlay/test_system_autogen.py +++ b/packages/google-cloud-bigtable/tests/system/admin_overlay/test_system_autogen.py @@ -18,15 +18,11 @@ import os from datetime import datetime, timedelta from typing import Tuple - import pytest -from google.api_core import operation as api_core_operation from google.cloud.environment_vars import BIGTABLE_EMULATOR - from google.cloud import bigtable_admin_v2 as admin_v2 from google.cloud.bigtable.data import mutations, read_rows_query from google.cloud.bigtable.data._cross_sync import CrossSync - from .conftest import ( BACKUP_PREFIX, DEFAULT_CLUSTER_LOCATIONS, @@ -42,6 +38,7 @@ TEST_TABLE_NAME, generate_unique_suffix, ) +from google.api_core import operation as api_core_operation if os.getenv(BIGTABLE_EMULATOR): pytest.skip( @@ -227,7 +224,7 @@ def test_optimize_restored_table( second_instance_storage_type, expect_optimize_operation, ): - (instance_with_backup, table_to_backup) = create_instance( + instance_with_backup, table_to_backup = create_instance( instance_admin_client, table_admin_client, data_client, @@ -235,7 +232,7 @@ def test_optimize_restored_table( instances_to_delete, admin_v2.StorageType.HDD, ) - (instance_to_restore, _) = create_instance( + instance_to_restore, _ = create_instance( instance_admin_client, table_admin_client, data_client, @@ -285,7 +282,7 @@ def test_wait_for_consistency( instances_to_delete, admin_overlay_project_id, ): - (instance, table) = create_instance( + instance, table = create_instance( instance_admin_client, table_admin_client, data_client, diff --git a/packages/google-cloud-bigtable/tests/system/data/test_system_autogen.py b/packages/google-cloud-bigtable/tests/system/data/test_system_autogen.py index 7ac045c1015d..00ddd426797b 100644 --- a/packages/google-cloud-bigtable/tests/system/data/test_system_autogen.py +++ b/packages/google-cloud-bigtable/tests/system/data/test_system_autogen.py @@ -18,22 +18,19 @@ import datetime import os import uuid - import pytest from google.api_core import retry from google.api_core.exceptions import ClientError, PermissionDenied from google.cloud.environment_vars import BIGTABLE_EMULATOR from google.type import date_pb2 - from google.cloud.bigtable.data._cross_sync import CrossSync from google.cloud.bigtable.data.execute_query.metadata import SqlType from google.cloud.bigtable.data.read_modify_write_rules import _MAX_INCREMENT_VALUE +from . import TEST_AGGREGATE_FAMILY, TEST_FAMILY, TEST_FAMILY_2 from google.cloud.bigtable_v2.services.bigtable.transports.grpc import ( _LoggingClientInterceptor as GapicInterceptor, ) -from . import TEST_AGGREGATE_FAMILY, TEST_FAMILY, TEST_FAMILY_2 - TARGETS = ["table"] if not os.environ.get(BIGTABLE_EMULATOR): TARGETS.append("authorized_view") @@ -260,7 +257,7 @@ def test_mutation_set_cell(self, target, temp_rows): """Ensure cells can be set properly""" row_key = b"bulk_mutate" new_value = uuid.uuid4().hex.encode() - (row_key, mutation) = self._create_row_and_mutation( + row_key, mutation = self._create_row_and_mutation( target, temp_rows, new_value=new_value ) target.mutate_row(row_key, mutation) @@ -314,7 +311,7 @@ def test_bulk_mutations_set_cell(self, client, target, temp_rows): from google.cloud.bigtable.data.mutations import RowMutationEntry new_value = uuid.uuid4().hex.encode() - (row_key, mutation) = self._create_row_and_mutation( + row_key, mutation = self._create_row_and_mutation( target, temp_rows, new_value=new_value ) bulk_mutation = RowMutationEntry(row_key, [mutation]) @@ -351,11 +348,11 @@ def test_mutations_batcher_context_manager(self, client, target, temp_rows): """test batcher with context manager. Should flush on exit""" from google.cloud.bigtable.data.mutations import RowMutationEntry - (new_value, new_value2) = [uuid.uuid4().hex.encode() for _ in range(2)] - (row_key, mutation) = self._create_row_and_mutation( + new_value, new_value2 = [uuid.uuid4().hex.encode() for _ in range(2)] + row_key, mutation = self._create_row_and_mutation( target, temp_rows, new_value=new_value ) - (row_key2, mutation2) = self._create_row_and_mutation( + row_key2, mutation2 = self._create_row_and_mutation( target, temp_rows, new_value=new_value2 ) bulk_mutation = RowMutationEntry(row_key, [mutation]) @@ -376,7 +373,7 @@ def test_mutations_batcher_timer_flush(self, client, target, temp_rows): from google.cloud.bigtable.data.mutations import RowMutationEntry new_value = uuid.uuid4().hex.encode() - (row_key, mutation) = self._create_row_and_mutation( + row_key, mutation = self._create_row_and_mutation( target, temp_rows, new_value=new_value ) bulk_mutation = RowMutationEntry(row_key, [mutation]) @@ -398,12 +395,12 @@ def test_mutations_batcher_count_flush(self, client, target, temp_rows): """batch should flush after flush_limit_mutation_count mutations""" from google.cloud.bigtable.data.mutations import RowMutationEntry - (new_value, new_value2) = [uuid.uuid4().hex.encode() for _ in range(2)] - (row_key, mutation) = self._create_row_and_mutation( + new_value, new_value2 = [uuid.uuid4().hex.encode() for _ in range(2)] + row_key, mutation = self._create_row_and_mutation( target, temp_rows, new_value=new_value ) bulk_mutation = RowMutationEntry(row_key, [mutation]) - (row_key2, mutation2) = self._create_row_and_mutation( + row_key2, mutation2 = self._create_row_and_mutation( target, temp_rows, new_value=new_value2 ) bulk_mutation2 = RowMutationEntry(row_key2, [mutation2]) @@ -430,12 +427,12 @@ def test_mutations_batcher_bytes_flush(self, client, target, temp_rows): """batch should flush after flush_limit_bytes bytes""" from google.cloud.bigtable.data.mutations import RowMutationEntry - (new_value, new_value2) = [uuid.uuid4().hex.encode() for _ in range(2)] - (row_key, mutation) = self._create_row_and_mutation( + new_value, new_value2 = [uuid.uuid4().hex.encode() for _ in range(2)] + row_key, mutation = self._create_row_and_mutation( target, temp_rows, new_value=new_value ) bulk_mutation = RowMutationEntry(row_key, [mutation]) - (row_key2, mutation2) = self._create_row_and_mutation( + row_key2, mutation2 = self._create_row_and_mutation( target, temp_rows, new_value=new_value2 ) bulk_mutation2 = RowMutationEntry(row_key2, [mutation2]) @@ -461,11 +458,11 @@ def test_mutations_batcher_no_flush(self, client, target, temp_rows): new_value = uuid.uuid4().hex.encode() start_value = b"unchanged" - (row_key, mutation) = self._create_row_and_mutation( + row_key, mutation = self._create_row_and_mutation( target, temp_rows, start_value=start_value, new_value=new_value ) bulk_mutation = RowMutationEntry(row_key, [mutation]) - (row_key2, mutation2) = self._create_row_and_mutation( + row_key2, mutation2 = self._create_row_and_mutation( target, temp_rows, start_value=start_value, new_value=new_value ) bulk_mutation2 = RowMutationEntry(row_key2, [mutation2]) @@ -936,9 +933,9 @@ def test_literal_value_filter( temp_rows.add_row(b"row_key_1", value=cell_value) query = ReadRowsQuery(row_filter=f) row_list = target.read_rows(query) - assert len(row_list) == bool(expect_match), ( - f"row {type(cell_value)}({cell_value}) not found with {type(filter_input)}({filter_input}) filter" - ) + assert len(row_list) == bool( + expect_match + ), f"row {type(cell_value)}({cell_value}) not found with {type(filter_input)}({filter_input}) filter" @pytest.mark.skipif( bool(os.environ.get(BIGTABLE_EMULATOR)), reason="emulator doesn't support SQL" diff --git a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test__mutate_rows.py b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test__mutate_rows.py index 03242aa0c64d..a9c841399098 100644 --- a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test__mutate_rows.py +++ b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test__mutate_rows.py @@ -18,7 +18,6 @@ import pytest from google.api_core.exceptions import DeadlineExceeded, Forbidden from google.rpc import status_pb2 - from google.cloud.bigtable.data._cross_sync import CrossSync from google.cloud.bigtable.data.mutations import DeleteAllFromRow, RowMutationEntry from google.cloud.bigtable_v2.types import MutateRowsResponse @@ -74,7 +73,6 @@ def _make_mock_gapic(self, mutation_list, error_dict=None): def test_ctor(self): """test that constructor sets all the attributes correctly""" from google.api_core.exceptions import Aborted, DeadlineExceeded - from google.cloud.bigtable.data._async._mutate_rows import _EntryWithProto from google.cloud.bigtable.data.exceptions import _MutateRowsIncomplete @@ -225,7 +223,6 @@ def test_mutate_rows_exception_retryable_eventually_pass(self, exc_type): def test_mutate_rows_incomplete_ignored(self): """MutateRowsIncomplete exceptions should not be added to error list""" from google.api_core.exceptions import DeadlineExceeded - from google.cloud.bigtable.data.exceptions import ( MutationsExceptionGroup, _MutateRowsIncomplete, @@ -263,7 +260,7 @@ def test_run_attempt_single_entry_success(self): instance._run_attempt() assert len(instance.remaining_indices) == 0 assert mock_gapic_fn.call_count == 1 - (_, kwargs) = mock_gapic_fn.call_args + _, kwargs = mock_gapic_fn.call_args assert kwargs["timeout"] == expected_timeout request = kwargs["request"] assert request.entries == [mutation._to_pb()] diff --git a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test__read_rows.py b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test__read_rows.py index a9744c5e9941..eb0343dd4a20 100644 --- a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test__read_rows.py +++ b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test__read_rows.py @@ -16,7 +16,6 @@ # This file is automatically generated by CrossSync. Do not edit manually. import pytest - from google.cloud.bigtable.data._cross_sync import CrossSync try: @@ -167,12 +166,11 @@ def test_revise_request_rowset_ranges( next_key = (last_key + "a").encode("utf-8") last_key = last_key.encode("utf-8") in_ranges = [ - RowRangePB(**{k: v.encode("utf-8") for (k, v) in r.items()}) + RowRangePB(**{k: v.encode("utf-8") for k, v in r.items()}) for r in in_ranges ] expected = [ - RowRangePB(**{k: v.encode("utf-8") for (k, v) in r.items()}) - for r in expected + RowRangePB(**{k: v.encode("utf-8") for k, v in r.items()}) for r in expected ] if with_key: row_keys = [next_key] diff --git a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test__swappable_channel.py b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test__swappable_channel.py index 25429bdc8a28..04f3f61c8d86 100644 --- a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test__swappable_channel.py +++ b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test__swappable_channel.py @@ -22,7 +22,6 @@ import mock import pytest from grpc import ChannelConnectivity - from google.cloud.bigtable.data._sync_autogen._swappable_channel import ( SwappableChannel as TargetType, ) diff --git a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_client.py b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_client.py index 2374808b6244..81cc0e67568b 100644 --- a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_client.py +++ b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_client.py @@ -15,23 +15,16 @@ # This file is automatically generated by CrossSync. Do not edit manually. from __future__ import annotations - import asyncio import re - import grpc import mock import pytest -from google.api_core import client_options, grpc_helpers +from google.api_core import client_options from google.api_core import exceptions as core_exceptions from google.auth.credentials import AnonymousCredentials - from google.cloud.bigtable.data import TABLE_DEFAULT, mutations from google.cloud.bigtable.data._cross_sync import CrossSync -from google.cloud.bigtable.data._sync_autogen._swappable_channel import SwappableChannel -from google.cloud.bigtable.data._sync_autogen.metrics_interceptor import ( - BigtableMetricsInterceptor, -) from google.cloud.bigtable.data.exceptions import InvalidChunk, _MutateRowsIncomplete from google.cloud.bigtable.data.mutations import DeleteAllFromRow from google.cloud.bigtable.data.read_modify_write_rules import ( @@ -52,6 +45,11 @@ str_type, str_val, ) +from google.api_core import grpc_helpers +from google.cloud.bigtable.data._sync_autogen._swappable_channel import SwappableChannel +from google.cloud.bigtable.data._sync_autogen.metrics_interceptor import ( + BigtableMetricsInterceptor, +) CrossSync._Sync_Impl.add_mapping("grpc_helpers", grpc_helpers) CrossSync._Sync_Impl.add_mapping("SwappableChannel", SwappableChannel) @@ -174,9 +172,9 @@ def test_veneer_grpc_headers(self): wrapped_user_agent_sorted = " ".join( sorted(client_info.to_user_agent().split(" ")) ) - assert VENEER_HEADER_REGEX.match(wrapped_user_agent_sorted), ( - f"'{wrapped_user_agent_sorted}' does not match {VENEER_HEADER_REGEX}" - ) + assert VENEER_HEADER_REGEX.match( + wrapped_user_agent_sorted + ), f"'{wrapped_user_agent_sorted}' does not match {VENEER_HEADER_REGEX}" client.close() def test__start_background_channel_refresh_task_exists(self): @@ -235,10 +233,9 @@ def test__ping_and_warm_instances(self): assert len(partial_list) == 4 grpc_call_args = channel.unary_unary().call_args_list for idx, (_, kwargs) in enumerate(grpc_call_args): - ( - expected_instance, - expected_app_profile, - ) = client_mock._active_instances[idx] + expected_instance, expected_app_profile = client_mock._active_instances[ + idx + ] request = kwargs["request"] assert request["name"] == expected_instance assert request["app_profile_id"] == expected_app_profile @@ -304,9 +301,9 @@ def test__manage_channel_first_sleep( pass sleep.assert_called_once() call_time = sleep.call_args[0][1] - assert abs(call_time - expected_sleep) < 0.1, ( - f"refresh_interval: {refresh_interval}, wait_time: {wait_time}, expected_sleep: {expected_sleep}" - ) + assert ( + abs(call_time - expected_sleep) < 0.1 + ), f"refresh_interval: {refresh_interval}, wait_time: {wait_time}, expected_sleep: {expected_sleep}" client.close() def test__manage_channel_ping_and_warm(self): @@ -322,9 +319,9 @@ def test__manage_channel_ping_and_warm(self): ) with mock.patch.object(*sleep_tuple) as sleep_mock: sleep_mock.side_effect = [None, asyncio.CancelledError] - ping_and_warm = client._ping_and_warm_instances = ( - CrossSync._Sync_Impl.Mock() - ) + ping_and_warm = ( + client._ping_and_warm_instances + ) = CrossSync._Sync_Impl.Mock() try: client._manage_channel(10) except asyncio.CancelledError: @@ -366,9 +363,9 @@ def test__manage_channel_sleeps(self, refresh_interval, num_cycles, expected_sle pass assert sleep.call_count == num_cycles total_sleep = sum([call[0][1] for call in sleep.call_args_list]) - assert abs(total_sleep - expected_sleep) < 0.5, ( - f"refresh_interval={refresh_interval}, num_cycles={num_cycles}, expected_sleep={expected_sleep}" - ) + assert ( + abs(total_sleep - expected_sleep) < 0.5 + ), f"refresh_interval={refresh_interval}, num_cycles={num_cycles}, expected_sleep={expected_sleep}" client.close() def test__manage_channel_random(self): @@ -752,7 +749,6 @@ def test_api_surface_arg_passthrough(self, method): def test_api_surface_context_manager(self, method): """get_table and get_authorized_view should work as context managers""" from functools import partial - from google.cloud.bigtable.data._helpers import _WarmedInstanceKey expected_table_id = "table-id" @@ -1652,7 +1648,7 @@ def test_read_row(self): ) assert row == expected_result assert read_rows.call_count == 1 - (args, kwargs) = read_rows.call_args_list[0] + args, kwargs = read_rows.call_args_list[0] assert kwargs["operation_timeout"] == expected_op_timeout assert kwargs["attempt_timeout"] == expected_req_timeout assert len(args) == 1 @@ -1683,7 +1679,7 @@ def test_read_row_w_filter(self): ) assert row == expected_result assert read_rows.call_count == 1 - (args, kwargs) = read_rows.call_args_list[0] + args, kwargs = read_rows.call_args_list[0] assert kwargs["operation_timeout"] == expected_op_timeout assert kwargs["attempt_timeout"] == expected_req_timeout assert len(args) == 1 @@ -1710,7 +1706,7 @@ def test_read_row_no_response(self): ) assert result is None assert read_rows.call_count == 1 - (args, kwargs) = read_rows.call_args_list[0] + args, kwargs = read_rows.call_args_list[0] assert kwargs["operation_timeout"] == expected_op_timeout assert kwargs["attempt_timeout"] == expected_req_timeout assert isinstance(args[0], ReadRowsQuery) @@ -1739,7 +1735,7 @@ def test_row_exists(self, return_value, expected_result): ) assert expected_result == result assert read_rows.call_count == 1 - (args, kwargs) = read_rows.call_args_list[0] + args, kwargs = read_rows.call_args_list[0] assert kwargs["operation_timeout"] == expected_op_timeout assert kwargs["attempt_timeout"] == expected_req_timeout assert isinstance(args[0], ReadRowsQuery) @@ -1776,14 +1772,11 @@ def test_read_rows_sharded_multiple_queries(self): with mock.patch.object( table.client._gapic_client, "read_rows" ) as read_rows: - read_rows.side_effect = ( - lambda *args, - **kwargs: CrossSync._Sync_Impl.TestReadRows._make_gapic_stream( - [ - CrossSync._Sync_Impl.TestReadRows._make_chunk(row_key=k) - for k in args[0].rows.row_keys - ] - ) + read_rows.side_effect = lambda *args, **kwargs: CrossSync._Sync_Impl.TestReadRows._make_gapic_stream( + [ + CrossSync._Sync_Impl.TestReadRows._make_chunk(row_key=k) + for k in args[0].rows.row_keys + ] ) query_1 = ReadRowsQuery(b"test_1") query_2 = ReadRowsQuery(b"test_2") @@ -1876,7 +1869,7 @@ def mock_call(*args, **kwargs): assert read_rows.call_count == num_queries rpc_start_list = [ starting_timeout - kwargs["operation_timeout"] - for (_, kwargs) in read_rows.call_args_list + for _, kwargs in read_rows.call_args_list ] eps = 0.01 assert all( @@ -1890,7 +1883,6 @@ def test_read_rows_sharded_expirary(self): """If the operation times out before all shards complete, should raise a ShardedReadRowsExceptionGroup""" from google.api_core.exceptions import DeadlineExceeded - from google.cloud.bigtable.data._helpers import _CONCURRENCY_LIMIT from google.cloud.bigtable.data.exceptions import ShardedReadRowsExceptionGroup @@ -1926,7 +1918,6 @@ def test_read_rows_sharded_negative_batch_timeout(self): They should raise DeadlineExceeded errors""" from google.api_core.exceptions import DeadlineExceeded - from google.cloud.bigtable.data._helpers import _CONCURRENCY_LIMIT from google.cloud.bigtable.data.exceptions import ShardedReadRowsExceptionGroup @@ -2010,7 +2001,7 @@ def test_sample_row_keys_default_timeout(self): ) as sample_row_keys: sample_row_keys.return_value = self._make_gapic_stream([]) result = table.sample_row_keys() - (_, kwargs) = sample_row_keys.call_args + _, kwargs = sample_row_keys.call_args assert abs(kwargs["timeout"] - expected_timeout) < 0.1 assert result == [] assert kwargs["retry"] is None @@ -2032,7 +2023,7 @@ def test_sample_row_keys_gapic_params(self): ) as sample_row_keys: sample_row_keys.return_value = self._make_gapic_stream([]) table.sample_row_keys(attempt_timeout=expected_timeout) - (args, kwargs) = sample_row_keys.call_args + args, kwargs = sample_row_keys.call_args assert len(args) == 0 assert len(kwargs) == 3 assert kwargs["timeout"] == expected_timeout @@ -2048,7 +2039,6 @@ def test_sample_row_keys_gapic_params(self): def test_sample_row_keys_retryable_errors(self, retryable_exception): """retryable errors should be retried until timeout""" from google.api_core.exceptions import DeadlineExceeded - from google.cloud.bigtable.data.exceptions import RetryExceptionGroup with self._make_client() as client: @@ -2149,7 +2139,6 @@ def test_mutate_row(self, mutation_arg): ) def test_mutate_row_retryable_errors(self, retryable_exception): from google.api_core.exceptions import DeadlineExceeded - from google.cloud.bigtable.data.exceptions import RetryExceptionGroup with self._make_client(project="project") as client: @@ -2228,7 +2217,6 @@ def _make_client(self, *args, **kwargs): def _mock_response(self, response_list): from google.rpc import status_pb2 - from google.cloud.bigtable_v2.types import MutateRowsResponse statuses = [] @@ -2500,7 +2488,6 @@ def test_bulk_mutate_error_index(self): FailedPrecondition, ServiceUnavailable, ) - from google.cloud.bigtable.data.exceptions import ( FailedMutationEntryError, MutationsExceptionGroup, diff --git a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_metrics_interceptor.py b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_metrics_interceptor.py index 20d7a62646dd..e89108e12bc6 100644 --- a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_metrics_interceptor.py +++ b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_metrics_interceptor.py @@ -17,7 +17,6 @@ import pytest from grpc import ClientCallDetails, RpcError - from google.cloud.bigtable.data._cross_sync import CrossSync from google.cloud.bigtable.data._metrics.data_model import ( ActiveOperationMetric, diff --git a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_mutations_batcher.py b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_mutations_batcher.py index c1ee196926bf..9f5bec2efb82 100644 --- a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_mutations_batcher.py +++ b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_mutations_batcher.py @@ -17,12 +17,10 @@ import asyncio import time - import google.api_core.exceptions as core_exceptions import google.api_core.retry import mock import pytest - from google.cloud.bigtable.data import TABLE_DEFAULT from google.cloud.bigtable.data._cross_sync import CrossSync from google.cloud.bigtable.data.exceptions import _MutateRowsIncomplete @@ -445,7 +443,7 @@ def test__start_flush_timer_w_empty_input(self, input_val): self._get_target_class(), "_schedule_flush" ) as flush_mock: with self._make_one() as instance: - (sleep_obj, sleep_method) = (instance._closed, "wait") + sleep_obj, sleep_method = (instance._closed, "wait") with mock.patch.object(sleep_obj, sleep_method) as sleep_mock: result = instance._timer_routine(input_val) assert sleep_mock.call_count == 0 @@ -461,7 +459,7 @@ def test__start_flush_timer_call_when_closed(self): with self._make_one() as instance: instance.close() flush_mock.reset_mock() - (sleep_obj, sleep_method) = (instance._closed, "wait") + sleep_obj, sleep_method = (instance._closed, "wait") with mock.patch.object(sleep_obj, sleep_method) as sleep_mock: instance._timer_routine(10) assert sleep_mock.call_count == 0 @@ -771,7 +769,6 @@ def gen(x): def _mock_gapic_return(self, num=5): from google.rpc import status_pb2 - from google.cloud.bigtable_v2.types import MutateRowsResponse def gen(num): @@ -818,7 +815,7 @@ def test__execute_mutate_rows(self): batch = [self._make_mutation()] result = instance._execute_mutate_rows(batch) assert start_operation.call_count == 1 - (args, kwargs) = mutate_rows.call_args + args, kwargs = mutate_rows.call_args assert args[0] == table.client._gapic_client assert args[1] == table assert args[2] == batch @@ -867,7 +864,7 @@ def test__raise_exceptions(self): assert list(exc.exceptions) == expected_exceptions assert str(expected_total) in str(exc) assert instance._entries_processed_since_last_raise == 0 - (instance._oldest_exceptions, instance._newest_exceptions) = ([], []) + instance._oldest_exceptions, instance._newest_exceptions = ([], []) instance._raise_exceptions() def test___enter__(self): @@ -909,7 +906,7 @@ def test_close_w_exceptions(self): assert list(exc.exceptions) == expected_exceptions assert str(expected_total) in str(exc) assert instance._entries_processed_since_last_raise == 0 - (instance._oldest_exceptions, instance._newest_exceptions) = ([], []) + instance._oldest_exceptions, instance._newest_exceptions = ([], []) def test__on_exit(self, recwarn): """Should raise warnings if unflushed mutations exist""" diff --git a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_read_rows_acceptance.py b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_read_rows_acceptance.py index 29332e712d35..0950576645e8 100644 --- a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_read_rows_acceptance.py +++ b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_read_rows_acceptance.py @@ -15,19 +15,15 @@ # This file is automatically generated by CrossSync. Do not edit manually. from __future__ import annotations - import os import warnings from itertools import zip_longest - import mock import pytest - from google.cloud.bigtable.data._cross_sync import CrossSync from google.cloud.bigtable.data.exceptions import InvalidChunk from google.cloud.bigtable.data.row import Row from google.cloud.bigtable_v2 import ReadRowsResponse - from ...v2_client.test_row_merger import ReadRowsTest, TestFile diff --git a/packages/google-cloud-bigtable/tests/unit/data/execute_query/_sync_autogen/test_query_iterator.py b/packages/google-cloud-bigtable/tests/unit/data/execute_query/_sync_autogen/test_query_iterator.py index 7c3efce32126..25666e8b9d3b 100644 --- a/packages/google-cloud-bigtable/tests/unit/data/execute_query/_sync_autogen/test_query_iterator.py +++ b/packages/google-cloud-bigtable/tests/unit/data/execute_query/_sync_autogen/test_query_iterator.py @@ -17,15 +17,12 @@ import concurrent.futures import gc - import pytest - from google.cloud.bigtable.data import exceptions from google.cloud.bigtable.data._cross_sync import CrossSync from google.cloud.bigtable.data.execute_query.metadata import ( _pb_metadata_to_metadata_types, ) - from ..sql_helpers import chunked_responses, column, int64_type, int_val, metadata try: From 6602218db56de4d86277048441abbd66b7860147 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Fri, 3 Apr 2026 03:34:47 +0000 Subject: [PATCH 08/12] add new line --- .../client-post-processing/bigtable-integration.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.librarian/generator-input/client-post-processing/bigtable-integration.yaml b/.librarian/generator-input/client-post-processing/bigtable-integration.yaml index c01af27a0252..34421b481340 100644 --- a/.librarian/generator-input/client-post-processing/bigtable-integration.yaml +++ b/.librarian/generator-input/client-post-processing/bigtable-integration.yaml @@ -959,4 +959,4 @@ replacements: @nox.session(python=DEFAULT_PYTHON_VERSION) def core_deps_from_source(session): """Run all tests with core dependencies installed from source, - count: 1 \ No newline at end of file + count: 1 From e73bc91bc7797cc128cc120cf1e445a5265f81cd Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Fri, 3 Apr 2026 03:36:01 +0000 Subject: [PATCH 09/12] Address feedback --- .../client-post-processing/bigtable-integration.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.librarian/generator-input/client-post-processing/bigtable-integration.yaml b/.librarian/generator-input/client-post-processing/bigtable-integration.yaml index 34421b481340..ee3dd391f13d 100644 --- a/.librarian/generator-input/client-post-processing/bigtable-integration.yaml +++ b/.librarian/generator-input/client-post-processing/bigtable-integration.yaml @@ -957,6 +957,11 @@ replacements: @nox.session(python=DEFAULT_PYTHON_VERSION) + @nox.parametrize( + "protobuf_implementation", + ["python", "upb"], + ) + def core_deps_from_source(session, protobuf_implementation): def core_deps_from_source(session): """Run all tests with core dependencies installed from source, count: 1 From 0d5c93c959ed6db891aeba89c6a8b88894e3187c Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Fri, 3 Apr 2026 03:36:27 +0000 Subject: [PATCH 10/12] update noxfile.py --- .../client-post-processing/bigtable-integration.yaml | 1 - packages/google-cloud-bigtable/noxfile.py | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.librarian/generator-input/client-post-processing/bigtable-integration.yaml b/.librarian/generator-input/client-post-processing/bigtable-integration.yaml index ee3dd391f13d..f5cef80c5476 100644 --- a/.librarian/generator-input/client-post-processing/bigtable-integration.yaml +++ b/.librarian/generator-input/client-post-processing/bigtable-integration.yaml @@ -962,6 +962,5 @@ replacements: ["python", "upb"], ) def core_deps_from_source(session, protobuf_implementation): - def core_deps_from_source(session): """Run all tests with core dependencies installed from source, count: 1 diff --git a/packages/google-cloud-bigtable/noxfile.py b/packages/google-cloud-bigtable/noxfile.py index 17437ae25794..b9883960a59e 100644 --- a/packages/google-cloud-bigtable/noxfile.py +++ b/packages/google-cloud-bigtable/noxfile.py @@ -559,7 +559,11 @@ def generate_sync(session): @nox.session(python=DEFAULT_PYTHON_VERSION) -def core_deps_from_source(session): +@nox.parametrize( + "protobuf_implementation", + ["python", "upb"], +) +def core_deps_from_source(session, protobuf_implementation): """Run all tests with core dependencies installed from source, rather than pulling the dependencies from PyPI. """ From 334fabb2399bdc1fd853a63507df63aae8a1dc48 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Fri, 3 Apr 2026 03:39:21 +0000 Subject: [PATCH 11/12] clean up --- .../client-post-processing/bigtable-integration.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.librarian/generator-input/client-post-processing/bigtable-integration.yaml b/.librarian/generator-input/client-post-processing/bigtable-integration.yaml index f5cef80c5476..4ed17231fd7e 100644 --- a/.librarian/generator-input/client-post-processing/bigtable-integration.yaml +++ b/.librarian/generator-input/client-post-processing/bigtable-integration.yaml @@ -11,8 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -description: Integrate Google Cloud Logging Handwritten code -# TODO(Fill in issue number below to add more context) +description: Integrate Google Cloud Bigtable Handwritten code url: https://github.com/googleapis/gapic-generator-python/issues/123 replacements: - paths: [ From dc088b6b0c676850c6acba3c43ad4b3123e808db Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Fri, 3 Apr 2026 03:45:00 +0000 Subject: [PATCH 12/12] lint --- .../tests/system/data/test_system_autogen.py | 6 +-- .../unit/data/_sync_autogen/test_client.py | 37 ++++++++++--------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/packages/google-cloud-bigtable/tests/system/data/test_system_autogen.py b/packages/google-cloud-bigtable/tests/system/data/test_system_autogen.py index 00ddd426797b..396f7b1a0605 100644 --- a/packages/google-cloud-bigtable/tests/system/data/test_system_autogen.py +++ b/packages/google-cloud-bigtable/tests/system/data/test_system_autogen.py @@ -933,9 +933,9 @@ def test_literal_value_filter( temp_rows.add_row(b"row_key_1", value=cell_value) query = ReadRowsQuery(row_filter=f) row_list = target.read_rows(query) - assert len(row_list) == bool( - expect_match - ), f"row {type(cell_value)}({cell_value}) not found with {type(filter_input)}({filter_input}) filter" + assert len(row_list) == bool(expect_match), ( + f"row {type(cell_value)}({cell_value}) not found with {type(filter_input)}({filter_input}) filter" + ) @pytest.mark.skipif( bool(os.environ.get(BIGTABLE_EMULATOR)), reason="emulator doesn't support SQL" diff --git a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_client.py b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_client.py index 81cc0e67568b..0d5e47b1072b 100644 --- a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_client.py +++ b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_client.py @@ -172,9 +172,9 @@ def test_veneer_grpc_headers(self): wrapped_user_agent_sorted = " ".join( sorted(client_info.to_user_agent().split(" ")) ) - assert VENEER_HEADER_REGEX.match( - wrapped_user_agent_sorted - ), f"'{wrapped_user_agent_sorted}' does not match {VENEER_HEADER_REGEX}" + assert VENEER_HEADER_REGEX.match(wrapped_user_agent_sorted), ( + f"'{wrapped_user_agent_sorted}' does not match {VENEER_HEADER_REGEX}" + ) client.close() def test__start_background_channel_refresh_task_exists(self): @@ -301,9 +301,9 @@ def test__manage_channel_first_sleep( pass sleep.assert_called_once() call_time = sleep.call_args[0][1] - assert ( - abs(call_time - expected_sleep) < 0.1 - ), f"refresh_interval: {refresh_interval}, wait_time: {wait_time}, expected_sleep: {expected_sleep}" + assert abs(call_time - expected_sleep) < 0.1, ( + f"refresh_interval: {refresh_interval}, wait_time: {wait_time}, expected_sleep: {expected_sleep}" + ) client.close() def test__manage_channel_ping_and_warm(self): @@ -319,9 +319,9 @@ def test__manage_channel_ping_and_warm(self): ) with mock.patch.object(*sleep_tuple) as sleep_mock: sleep_mock.side_effect = [None, asyncio.CancelledError] - ping_and_warm = ( - client._ping_and_warm_instances - ) = CrossSync._Sync_Impl.Mock() + ping_and_warm = client._ping_and_warm_instances = ( + CrossSync._Sync_Impl.Mock() + ) try: client._manage_channel(10) except asyncio.CancelledError: @@ -363,9 +363,9 @@ def test__manage_channel_sleeps(self, refresh_interval, num_cycles, expected_sle pass assert sleep.call_count == num_cycles total_sleep = sum([call[0][1] for call in sleep.call_args_list]) - assert ( - abs(total_sleep - expected_sleep) < 0.5 - ), f"refresh_interval={refresh_interval}, num_cycles={num_cycles}, expected_sleep={expected_sleep}" + assert abs(total_sleep - expected_sleep) < 0.5, ( + f"refresh_interval={refresh_interval}, num_cycles={num_cycles}, expected_sleep={expected_sleep}" + ) client.close() def test__manage_channel_random(self): @@ -1772,11 +1772,14 @@ def test_read_rows_sharded_multiple_queries(self): with mock.patch.object( table.client._gapic_client, "read_rows" ) as read_rows: - read_rows.side_effect = lambda *args, **kwargs: CrossSync._Sync_Impl.TestReadRows._make_gapic_stream( - [ - CrossSync._Sync_Impl.TestReadRows._make_chunk(row_key=k) - for k in args[0].rows.row_keys - ] + read_rows.side_effect = ( + lambda *args, + **kwargs: CrossSync._Sync_Impl.TestReadRows._make_gapic_stream( + [ + CrossSync._Sync_Impl.TestReadRows._make_chunk(row_key=k) + for k in args[0].rows.row_keys + ] + ) ) query_1 = ReadRowsQuery(b"test_1") query_2 = ReadRowsQuery(b"test_2")