|
6 | 6 | from {{package_path}} import gapic_version as package_version |
7 | 7 |
|
8 | 8 | import google.api_core as api_core |
9 | | -import sys |
10 | 9 |
|
11 | 10 | __version__ = package_version.__version__ |
12 | 11 |
|
13 | | -from importlib import metadata |
14 | | - |
15 | 12 | # PEP 0810: Explicit Lazy Imports |
16 | 13 | # Python 3.15+ natively intercepts and defers these imports. |
17 | 14 | # Developers can disable this behavior and force eager imports. |
@@ -63,87 +60,8 @@ from .types.{{ proto.module_name }} import {{ enum.name }} |
63 | 60 | {% endfor %} |
64 | 61 | {% endfor %} |
65 | 62 |
|
66 | | -if hasattr(api_core, "check_python_version") and hasattr(api_core, "check_dependency_versions"): # pragma: NO COVER |
67 | | - {# TODO(api_core): remove `type:ignore` below when minimum version of api_core makes the else clause unnecessary. #} |
68 | | - api_core.check_python_version("{{package_path}}") # type: ignore |
69 | | - api_core.check_dependency_versions("{{package_path}}") # type: ignore |
70 | | -else: # pragma: NO COVER |
71 | | -{# TODO(api_core): Remove this try-catch when we require api-core at a version that |
72 | | - supports the changes in https://github.com/googleapis/python-api-core/pull/832 |
73 | | -
|
74 | | - In the meantime, please ensure the functionality here mirrors the |
75 | | - equivalent functionality in api_core, in those two functions above. |
76 | | -#} |
77 | | - # An older version of api_core is installed which does not define the |
78 | | - # functions above. We do equivalent checks manually. |
79 | | - try: |
80 | | - import warnings |
81 | | - |
82 | | - _py_version_str = sys.version.split()[0] |
83 | | - _package_label = "{{package_path}}" |
84 | | - if sys.version_info < (3, 10): |
85 | | - warnings.warn("You are using a non-supported Python version " + |
86 | | - f"({_py_version_str}). Google will not post any further " + |
87 | | - f"updates to {_package_label} supporting this Python version. " + |
88 | | - "Please upgrade to the latest Python version, or at " + |
89 | | - f"least to Python 3.10, and then update {_package_label}.", |
90 | | - FutureWarning) |
91 | | - |
92 | | - def parse_version_to_tuple(version_string: str): |
93 | | - """Safely converts a semantic version string to a comparable tuple of integers. |
94 | | - Example: "6.33.5" -> (6, 33, 5) |
95 | | - Ignores non-numeric parts and handles common version formats. |
96 | | - Args: |
97 | | - version_string: Version string in the format "x.y.z" or "x.y.z<suffix>" |
98 | | - Returns: |
99 | | - Tuple of integers for the parsed version string. |
100 | | - """ |
101 | | - parts = [] |
102 | | - for part in version_string.split("."): |
103 | | - try: |
104 | | - parts.append(int(part)) |
105 | | - except ValueError: |
106 | | - # If it's a non-numeric part (e.g., '1.0.0b1' -> 'b1'), stop here. |
107 | | - # This is a simplification compared to 'packaging.parse_version', but sufficient |
108 | | - # for comparing strictly numeric semantic versions. |
109 | | - break |
110 | | - return tuple(parts) |
111 | | - |
112 | | - def _get_version(dependency_name): |
113 | | - try: |
114 | | - version_string: str = metadata.version(dependency_name) |
115 | | - parsed_version = parse_version_to_tuple(version_string) |
116 | | - return (parsed_version, version_string) |
117 | | - except Exception: |
118 | | - # Catch exceptions from metadata.version() (e.g., PackageNotFoundError) |
119 | | - # or errors during parse_version_to_tuple |
120 | | - return (None, "--") |
121 | | - |
122 | | - _dependency_package = "google.protobuf" |
123 | | - _next_supported_version = "6.33.5" |
124 | | - _next_supported_version_tuple = (6, 33, 5) |
125 | | - _recommendation = " (we recommend 7.x)" |
126 | | - (_version_used, _version_used_string) = _get_version(_dependency_package) |
127 | | - if _version_used and _version_used < _next_supported_version_tuple: |
128 | | - warnings.warn(f"Package {_package_label} depends on " + |
129 | | - f"{_dependency_package}, currently installed at version " + |
130 | | - f"{_version_used_string}. Future updates to " + |
131 | | - f"{_package_label} will require {_dependency_package} at " + |
132 | | - f"version {_next_supported_version} or higher{_recommendation}." + |
133 | | - " Please ensure " + |
134 | | - "that either (a) your Python environment doesn't pin the " + |
135 | | - f"version of {_dependency_package}, so that updates to " + |
136 | | - f"{_package_label} can require the higher version, or " + |
137 | | - "(b) you manually update your Python environment to use at " + |
138 | | - f"least version {_next_supported_version} of " + |
139 | | - f"{_dependency_package}.", |
140 | | - FutureWarning) |
141 | | - except Exception: |
142 | | - warnings.warn("Could not determine the version of Python " + |
143 | | - "currently being used. To continue receiving " + |
144 | | - "updates for {_package_label}, ensure you are " + |
145 | | - "using a supported version of Python; see " + |
146 | | - "https://devguide.python.org/versions/") |
| 63 | +api_core.check_python_version("{{package_path}}") |
| 64 | +api_core.check_dependency_versions("{{package_path}}") |
147 | 65 |
|
148 | 66 | {# Define __all__. |
149 | 67 | This requires the full set of imported names, so we iterate over |
|
0 commit comments