|
13 | 13 | # See the License for the specific language governing permissions and |
14 | 14 | # limitations under the License. |
15 | 15 | # |
| 16 | + |
| 17 | +# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input` |
| 18 | +# The source of truth for this file is `.librarian/generator-input` |
| 19 | + |
16 | 20 | from google.cloud.bigtable_admin_v2 import gapic_version as package_version |
17 | 21 |
|
| 22 | +import google.api_core as api_core |
| 23 | +import sys |
| 24 | + |
18 | 25 | __version__ = package_version.__version__ |
19 | 26 |
|
| 27 | +if sys.version_info >= (3, 8): # pragma: NO COVER |
| 28 | + from importlib import metadata |
| 29 | +else: # pragma: NO COVER |
| 30 | + # TODO(https://github.com/googleapis/python-api-core/issues/835): Remove |
| 31 | + # this code path once we drop support for Python 3.7 |
| 32 | + import importlib_metadata as metadata |
| 33 | + |
20 | 34 |
|
21 | 35 | from .services.bigtable_instance_admin import BigtableInstanceAdminClient |
22 | 36 | from .services.bigtable_instance_admin import BigtableInstanceAdminAsyncClient |
|
143 | 157 | from .types.table import RestoreSourceType |
144 | 158 | from .types.types import Type |
145 | 159 |
|
| 160 | +if hasattr(api_core, "check_python_version") and hasattr( |
| 161 | + api_core, "check_dependency_versions" |
| 162 | +): # pragma: NO COVER |
| 163 | + api_core.check_python_version("google.cloud.bigtable_admin_v2") # type: ignore |
| 164 | + api_core.check_dependency_versions("google.cloud.bigtable_admin_v2") # type: ignore |
| 165 | +else: # pragma: NO COVER |
| 166 | + # An older version of api_core is installed which does not define the |
| 167 | + # functions above. We do equivalent checks manually. |
| 168 | + try: |
| 169 | + import warnings |
| 170 | + import sys |
| 171 | + |
| 172 | + _py_version_str = sys.version.split()[0] |
| 173 | + _package_label = "google.cloud.bigtable_admin_v2" |
| 174 | + if sys.version_info < (3, 9): |
| 175 | + warnings.warn( |
| 176 | + "You are using a non-supported Python version " |
| 177 | + + f"({_py_version_str}). Google will not post any further " |
| 178 | + + f"updates to {_package_label} supporting this Python version. " |
| 179 | + + "Please upgrade to the latest Python version, or at " |
| 180 | + + f"least to Python 3.9, and then update {_package_label}.", |
| 181 | + FutureWarning, |
| 182 | + ) |
| 183 | + if sys.version_info[:2] == (3, 9): |
| 184 | + warnings.warn( |
| 185 | + f"You are using a Python version ({_py_version_str}) " |
| 186 | + + f"which Google will stop supporting in {_package_label} in " |
| 187 | + + "January 2026. Please " |
| 188 | + + "upgrade to the latest Python version, or at " |
| 189 | + + "least to Python 3.10, before then, and " |
| 190 | + + f"then update {_package_label}.", |
| 191 | + FutureWarning, |
| 192 | + ) |
| 193 | + |
| 194 | + def parse_version_to_tuple(version_string: str): |
| 195 | + """Safely converts a semantic version string to a comparable tuple of integers. |
| 196 | + Example: "4.25.8" -> (4, 25, 8) |
| 197 | + Ignores non-numeric parts and handles common version formats. |
| 198 | + Args: |
| 199 | + version_string: Version string in the format "x.y.z" or "x.y.z<suffix>" |
| 200 | + Returns: |
| 201 | + Tuple of integers for the parsed version string. |
| 202 | + """ |
| 203 | + parts = [] |
| 204 | + for part in version_string.split("."): |
| 205 | + try: |
| 206 | + parts.append(int(part)) |
| 207 | + except ValueError: |
| 208 | + # If it's a non-numeric part (e.g., '1.0.0b1' -> 'b1'), stop here. |
| 209 | + # This is a simplification compared to 'packaging.parse_version', but sufficient |
| 210 | + # for comparing strictly numeric semantic versions. |
| 211 | + break |
| 212 | + return tuple(parts) |
| 213 | + |
| 214 | + def _get_version(dependency_name): |
| 215 | + try: |
| 216 | + version_string: str = metadata.version(dependency_name) |
| 217 | + parsed_version = parse_version_to_tuple(version_string) |
| 218 | + return (parsed_version, version_string) |
| 219 | + except Exception: |
| 220 | + # Catch exceptions from metadata.version() (e.g., PackageNotFoundError) |
| 221 | + # or errors during parse_version_to_tuple |
| 222 | + return (None, "--") |
| 223 | + |
| 224 | + _dependency_package = "google.protobuf" |
| 225 | + _next_supported_version = "4.25.8" |
| 226 | + _next_supported_version_tuple = (4, 25, 8) |
| 227 | + _recommendation = " (we recommend 6.x)" |
| 228 | + (_version_used, _version_used_string) = _get_version(_dependency_package) |
| 229 | + if _version_used and _version_used < _next_supported_version_tuple: |
| 230 | + warnings.warn( |
| 231 | + f"Package {_package_label} depends on " |
| 232 | + + f"{_dependency_package}, currently installed at version " |
| 233 | + + f"{_version_used_string}. Future updates to " |
| 234 | + + f"{_package_label} will require {_dependency_package} at " |
| 235 | + + f"version {_next_supported_version} or higher{_recommendation}." |
| 236 | + + " Please ensure " |
| 237 | + + "that either (a) your Python environment doesn't pin the " |
| 238 | + + f"version of {_dependency_package}, so that updates to " |
| 239 | + + f"{_package_label} can require the higher version, or " |
| 240 | + + "(b) you manually update your Python environment to use at " |
| 241 | + + f"least version {_next_supported_version} of " |
| 242 | + + f"{_dependency_package}.", |
| 243 | + FutureWarning, |
| 244 | + ) |
| 245 | + except Exception: |
| 246 | + warnings.warn( |
| 247 | + "Could not determine the version of Python " |
| 248 | + + "currently being used. To continue receiving " |
| 249 | + + "updates for {_package_label}, ensure you are " |
| 250 | + + "using a supported version of Python; see " |
| 251 | + + "https://devguide.python.org/versions/" |
| 252 | + ) |
| 253 | + |
146 | 254 | __all__ = ( |
147 | 255 | "BaseBigtableTableAdminAsyncClient", |
148 | 256 | "BigtableInstanceAdminAsyncClient", |
|
0 commit comments