Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .librarian/state.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
image: us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/python-librarian-generator@sha256:8e2c32496077054105bd06c54a59d6a6694287bc053588e24debe6da6920ad91
image: us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/python-librarian-generator@sha256:eec191fc4904c204cd717c79812cd66997b5559776483ee223f69c8f43e99224
libraries:
- id: google-cloud-spanner
version: 3.60.0
Expand Down
3 changes: 3 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input`
# The source of truth for this file is `.librarian/generator-input`


Apache License
Version 2.0, January 2004
Expand Down
3 changes: 3 additions & 0 deletions docs/_static/custom.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input`
# The source of truth for this file is `.librarian/generator-input`

div#python2-eol {
border-color: red;
border-width: medium;
Expand Down
3 changes: 3 additions & 0 deletions docs/_templates/layout.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input`
# The source of truth for this file is `.librarian/generator-input`


{% extends "!layout.html" %}
{%- block content %}
Expand Down
4 changes: 4 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input`
# The source of truth for this file is `.librarian/generator-input`


import sys
import os
import shlex
Expand Down
3 changes: 3 additions & 0 deletions docs/multiprocessing.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input`
# The source of truth for this file is `.librarian/generator-input`

.. note::

Because this client uses :mod:`grpc` library, it is safe to
Expand Down
3 changes: 3 additions & 0 deletions docs/spanner_admin_database_v1/database_admin.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input`
# The source of truth for this file is `.librarian/generator-input`

DatabaseAdmin
-------------------------------

Expand Down
3 changes: 3 additions & 0 deletions docs/spanner_admin_database_v1/services_.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input`
# The source of truth for this file is `.librarian/generator-input`

Services for Google Cloud Spanner Admin Database v1 API
=======================================================
.. toctree::
Expand Down
3 changes: 3 additions & 0 deletions docs/spanner_admin_database_v1/types_.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input`
# The source of truth for this file is `.librarian/generator-input`

Types for Google Cloud Spanner Admin Database v1 API
====================================================

Expand Down
3 changes: 3 additions & 0 deletions docs/spanner_admin_instance_v1/instance_admin.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input`
# The source of truth for this file is `.librarian/generator-input`

InstanceAdmin
-------------------------------

Expand Down
3 changes: 3 additions & 0 deletions docs/spanner_admin_instance_v1/services_.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input`
# The source of truth for this file is `.librarian/generator-input`

Services for Google Cloud Spanner Admin Instance v1 API
=======================================================
.. toctree::
Expand Down
3 changes: 3 additions & 0 deletions docs/spanner_admin_instance_v1/types_.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input`
# The source of truth for this file is `.librarian/generator-input`

Types for Google Cloud Spanner Admin Instance v1 API
====================================================

Expand Down
3 changes: 3 additions & 0 deletions docs/spanner_v1/services_.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input`
# The source of truth for this file is `.librarian/generator-input`

Services for Google Cloud Spanner v1 API
========================================
.. toctree::
Expand Down
3 changes: 3 additions & 0 deletions docs/spanner_v1/spanner.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input`
# The source of truth for this file is `.librarian/generator-input`

Spanner
-------------------------

Expand Down
3 changes: 3 additions & 0 deletions docs/spanner_v1/types_.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input`
# The source of truth for this file is `.librarian/generator-input`

Types for Google Cloud Spanner v1 API
=====================================

Expand Down
108 changes: 108 additions & 0 deletions google/cloud/spanner_admin_database_v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,24 @@
# 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`

from google.cloud.spanner_admin_database_v1 import gapic_version as package_version

import google.api_core as api_core
import sys

__version__ = package_version.__version__

if sys.version_info >= (3, 8): # pragma: NO COVER
from importlib import metadata
else: # pragma: NO COVER
# TODO(https://github.com/googleapis/python-api-core/issues/835): Remove
# this code path once we drop support for Python 3.7
import importlib_metadata as metadata


from .services.database_admin import DatabaseAdminClient
from .services.database_admin import DatabaseAdminAsyncClient
Expand Down Expand Up @@ -83,6 +97,100 @@
from .types.spanner_database_admin import UpdateDatabaseRequest
from .types.spanner_database_admin import RestoreSourceType

if hasattr(api_core, "check_python_version") and hasattr(
api_core, "check_dependency_versions"
): # pragma: NO COVER
api_core.check_python_version("google.cloud.spanner_admin_database_v1") # type: ignore
api_core.check_dependency_versions("google.cloud.spanner_admin_database_v1") # type: ignore
else: # pragma: NO COVER
# An older version of api_core is installed which does not define the
# functions above. We do equivalent checks manually.
try:
import warnings
import sys

_py_version_str = sys.version.split()[0]
_package_label = "google.cloud.spanner_admin_database_v1"
if sys.version_info < (3, 9):
warnings.warn(
"You are using a non-supported Python version "
+ f"({_py_version_str}). Google will not post any further "
+ f"updates to {_package_label} supporting this Python version. "
+ "Please upgrade to the latest Python version, or at "
+ f"least to Python 3.9, and then update {_package_label}.",
FutureWarning,
)
if sys.version_info[:2] == (3, 9):
warnings.warn(
f"You are using a Python version ({_py_version_str}) "
+ f"which Google will stop supporting in {_package_label} in "
+ "January 2026. Please "
+ "upgrade to the latest Python version, or at "
+ "least to Python 3.10, before then, and "
+ f"then update {_package_label}.",
FutureWarning,
)

def parse_version_to_tuple(version_string: str):
"""Safely converts a semantic version string to a comparable tuple of integers.
Example: "4.25.8" -> (4, 25, 8)
Ignores non-numeric parts and handles common version formats.
Args:
version_string: Version string in the format "x.y.z" or "x.y.z<suffix>"
Returns:
Tuple of integers for the parsed version string.
"""
parts = []
for part in version_string.split("."):
try:
parts.append(int(part))
except ValueError:
# If it's a non-numeric part (e.g., '1.0.0b1' -> 'b1'), stop here.
# This is a simplification compared to 'packaging.parse_version', but sufficient
# for comparing strictly numeric semantic versions.
break
return tuple(parts)

def _get_version(dependency_name):
try:
version_string: str = metadata.version(dependency_name)
parsed_version = parse_version_to_tuple(version_string)
return (parsed_version, version_string)
except Exception:
# Catch exceptions from metadata.version() (e.g., PackageNotFoundError)
# or errors during parse_version_to_tuple
return (None, "--")

_dependency_package = "google.protobuf"
_next_supported_version = "4.25.8"
_next_supported_version_tuple = (4, 25, 8)
_recommendation = " (we recommend 6.x)"
(_version_used, _version_used_string) = _get_version(_dependency_package)
if _version_used and _version_used < _next_supported_version_tuple:
warnings.warn(
f"Package {_package_label} depends on "
+ f"{_dependency_package}, currently installed at version "
+ f"{_version_used_string}. Future updates to "
+ f"{_package_label} will require {_dependency_package} at "
+ f"version {_next_supported_version} or higher{_recommendation}."
+ " Please ensure "
+ "that either (a) your Python environment doesn't pin the "
+ f"version of {_dependency_package}, so that updates to "
+ f"{_package_label} can require the higher version, or "
+ "(b) you manually update your Python environment to use at "
+ f"least version {_next_supported_version} of "
+ f"{_dependency_package}.",
FutureWarning,
)
except Exception:
warnings.warn(
"Could not determine the version of Python "
+ "currently being used. To continue receiving "
+ "updates for {_package_label}, ensure you are "
+ "using a supported version of Python; see "
+ "https://devguide.python.org/versions/"
)
Comment on lines +105 to +192

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This else block has a couple of issues:

  1. NameError in except block: The _package_label variable is defined inside the try block (line 113). If an exception occurs before this line (e.g., on import sys), the except block will try to access _package_label and raise a NameError.
  2. Incorrect string formatting: The warning message in the except block (lines 187-191) uses string concatenation with + but includes "{_package_label}", which will be treated as a literal string instead of an interpolated variable.
  3. Style: The long warning messages are constructed with a mix of f-strings and + concatenation. Using a single, multi-line f-string would be more readable and consistent.

To resolve this, you should define _package_label before the try block and use f-strings for the warning messages.

else:  # pragma: NO COVER
    # An older version of api_core is installed which does not define the
    # functions above. We do equivalent checks manually.
    _package_label = "google.cloud.spanner_admin_database_v1"
    try:
        import warnings
        import sys

        _py_version_str = sys.version.split()[0]
        if sys.version_info < (3, 9):
            warnings.warn(
                (f"You are using a non-supported Python version ({_py_version_str}). "
                 f"Google will not post any further updates to {_package_label} "
                 f"supporting this Python version. Please upgrade to the latest "
                 f"Python version, or at least to Python 3.9, and then update "
                 f"{_package_label}."),
                FutureWarning,
            )
        if sys.version_info[:2] == (3, 9):
            warnings.warn(
                (f"You are using a Python version ({_py_version_str}) which Google "
                 f"will stop supporting in {_package_label} in January 2026. "
                 f"Please upgrade to the latest Python version, or at least to "
                 f"Python 3.10, before then, and then update {_package_label}."),
                FutureWarning,
            )

        def parse_version_to_tuple(version_string: str):
            """Safely converts a semantic version string to a comparable tuple of integers.
            Example: "4.25.8" -> (4, 25, 8)
            Ignores non-numeric parts and handles common version formats.
            Args:
                version_string: Version string in the format "x.y.z" or "x.y.z<suffix>"
            Returns:
                Tuple of integers for the parsed version string.
            """
            parts = []
            for part in version_string.split("."):
                try:
                    parts.append(int(part))
                except ValueError:
                    # If it's a non-numeric part (e.g., '1.0.0b1' -> 'b1'), stop here.
                    # This is a simplification compared to 'packaging.parse_version', but sufficient
                    # for comparing strictly numeric semantic versions.
                    break
            return tuple(parts)

        def _get_version(dependency_name):
            try:
                version_string: str = metadata.version(dependency_name)
                parsed_version = parse_version_to_tuple(version_string)
                return (parsed_version, version_string)
            except Exception:
                # Catch exceptions from metadata.version() (e.g., PackageNotFoundError)
                # or errors during parse_version_to_tuple
                return (None, "--")

        _dependency_package = "google.protobuf"
        _next_supported_version = "4.25.8"
        _next_supported_version_tuple = (4, 25, 8)
        _recommendation = " (we recommend 6.x)"
        (_version_used, _version_used_string) = _get_version(_dependency_package)
        if _version_used and _version_used < _next_supported_version_tuple:
            warnings.warn(
                (f"Package {_package_label} depends on {_dependency_package}, "
                 f"currently installed at version {_version_used_string}. Future "
                 f"updates to {_package_label} will require {_dependency_package} at "
                 f"version {_next_supported_version} or higher{_recommendation}. "
                 f"Please ensure that either (a) your Python environment doesn't "
                 f"pin the version of {_dependency_package}, so that updates to "
                 f"{_package_label} can require the higher version, or (b) you "
                 f"manually update your Python environment to use at least version "
                 f"{_next_supported_version} of {_dependency_package}."),
                FutureWarning,
            )
    except Exception:
        warnings.warn(
            f"Could not determine the version of Python currently being used. "
            f"To continue receiving updates for {_package_label}, ensure you are "
            f"using a supported version of Python; see "
            f"https://devguide.python.org/versions/"
        )


__all__ = (
"DatabaseAdminAsyncClient",
"AddSplitPointsRequest",
Expand Down
4 changes: 4 additions & 0 deletions google/cloud/spanner_admin_database_v1/gapic_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@
# 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`

__version__ = "3.60.0" # {x-release-please-version}
4 changes: 4 additions & 0 deletions google/cloud/spanner_admin_database_v1/py.typed
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Marker file for PEP 561.
# The google-cloud-spanner-admin-database package uses inline types.

# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input`
# The source of truth for this file is `.librarian/generator-input`

3 changes: 3 additions & 0 deletions google/cloud/spanner_admin_database_v1/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
# 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`
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
# 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`

from .client import DatabaseAdminClient
from .async_client import DatabaseAdminAsyncClient

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
# 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 logging as std_logging
from collections import OrderedDict
import re
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
# 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`

from collections import OrderedDict
from http import HTTPStatus
import json
Expand Down Expand Up @@ -172,6 +176,34 @@ def _get_default_mtls_endpoint(api_endpoint):
_DEFAULT_ENDPOINT_TEMPLATE = "spanner.{UNIVERSE_DOMAIN}"
_DEFAULT_UNIVERSE = "googleapis.com"

@staticmethod
def _use_client_cert_effective():
"""Returns whether client certificate should be used for mTLS if the
google-auth version supports should_use_client_cert automatic mTLS enablement.

Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var.

Returns:
bool: whether client certificate should be used for mTLS
Raises:
ValueError: (If using a version of google-auth without should_use_client_cert and
GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.)
"""
# check if google-auth version supports should_use_client_cert for automatic mTLS enablement
if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER
return mtls.should_use_client_cert()
else: # pragma: NO COVER
# if unsupported, fallback to reading from env var
use_client_cert_str = os.getenv(
"GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
).lower()
if use_client_cert_str not in ("true", "false"):
raise ValueError(
"Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be"
" either `true` or `false`"
)
return use_client_cert_str == "true"

@classmethod
def from_service_account_info(cls, info: dict, *args, **kwargs):
"""Creates an instance of this client using the provided credentials
Expand Down Expand Up @@ -518,20 +550,16 @@ def get_mtls_endpoint_and_cert_source(
)
if client_options is None:
client_options = client_options_lib.ClientOptions()
use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")
use_client_cert = DatabaseAdminClient._use_client_cert_effective()
use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto")
if use_client_cert not in ("true", "false"):
raise ValueError(
"Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
)
if use_mtls_endpoint not in ("auto", "never", "always"):
raise MutualTLSChannelError(
"Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
)

# Figure out the client cert source to use.
client_cert_source = None
if use_client_cert == "true":
if use_client_cert:
if client_options.client_cert_source:
client_cert_source = client_options.client_cert_source
elif mtls.has_default_client_cert_source():
Expand Down Expand Up @@ -563,20 +591,14 @@ def _read_environment_variables():
google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT
is not any of ["auto", "never", "always"].
"""
use_client_cert = os.getenv(
"GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
).lower()
use_client_cert = DatabaseAdminClient._use_client_cert_effective()
use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower()
universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN")
if use_client_cert not in ("true", "false"):
raise ValueError(
"Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
)
if use_mtls_endpoint not in ("auto", "never", "always"):
raise MutualTLSChannelError(
"Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
)
return use_client_cert == "true", use_mtls_endpoint, universe_domain_env
return use_client_cert, use_mtls_endpoint, universe_domain_env

@staticmethod
def _get_client_cert_source(provided_cert_source, use_cert_flag):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
# 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`

from google.api_core import gapic_v1
from google.api_core import retry as retries
from google.api_core import retry_async as retries_async
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input`
# The source of truth for this file is `.librarian/generator-input`


transport inheritance structure
_______________________________
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
# 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`

from collections import OrderedDict
from typing import Dict, Type

Expand Down
Loading
Loading