@@ -9,81 +9,83 @@ __version__ = package_version.__version__
99
1010
1111import google.api_core as api_core
12-
13- if hasattr(api_core, "check_python_version") and hasattr(api_core, "check_dependency_versions"): # pragma: NO COVER
14- {# TODO(api_core): remove `type:ignore` below when minimum version of api_core makes the else clause unnecessary. #}
15- api_core.check_python_version("{{package_path}}") # type: ignore
16- api_core.check_dependency_versions("{{package_path}}") # type: ignore
17- else: # pragma: NO COVER
18- {# TODO(api_core): Remove this try-catch when we require api-core at a version that
19- supports the changes in https://github.com/googleapis/python-api-core/pull/832
20-
21- In the meantime, please ensure the functionality here mirrors the
22- equivalent functionality in api_core, in those two functions above.
23- #}
24- # An older version of api_core is installed, which does not define the
25- # functions above. We do equivalent checks manually.
26-
27- import warnings
28- import sys
29-
30- _py_version_str = sys.version.split()[0]
31- _package_label = "{{package_path}}"
32- if sys.version_info < (3, 9):
33- warnings.warn("You are using a non-supported Python version " +
34- f"({_py_version_str}). Google will not post any further " +
35- f"updates to {_package_label} supporting this Python version. " +
36- "Please upgrade to the latest Python version, or at " +
37- f"least to Python 3.9, and then update {_package_label}.",
38- FutureWarning)
39- if sys.version_info[:2] == (3, 9):
40- warnings.warn(f"You are using a Python version ({_py_version_str}) " +
41- f"which Google will stop supporting in {_package_label} when " +
42- "it reaches its end of life (October 2025). Please " +
43- "upgrade to the latest Python version, or at " +
44- "least Python 3.10, before then, and " +
45- f"then update {_package_label}.",
46- FutureWarning)
47-
48- from packaging.version import parse as parse_version
49-
50- if sys.version_info < (3, 8):
51- import pkg_resources
52-
53- def _get_version(dependency_name):
54- try:
55- version_string = pkg_resources.get_distribution(dependency_name).version
56- return (parse_version(version_string), version_string)
57- except pkg_resources.DistributionNotFound:
58- return (None, "--")
59- else:
60- from importlib import metadata
61-
62- def _get_version(dependency_name):
63- try:
64- version_string = metadata.version("requests")
65- parsed_version = parse_version(version_string)
66- return (parsed_version.release, version_string)
67- except metadata.PackageNotFoundError:
12+ try:
13+ if hasattr(api_core, "check_python_version") and hasattr(api_core, "check_dependency_versions"): # pragma: NO COVER
14+ {# TODO(api_core): remove `type:ignore` below when minimum version of api_core makes the else clause unnecessary. #}
15+ api_core.check_python_version("{{package_path}}") # type: ignore
16+ api_core.check_dependency_versions("{{package_path}}") # type: ignore
17+ else: # pragma: NO COVER
18+ {# TODO(api_core): Remove this try-catch when we require api-core at a version that
19+ supports the changes in https://github.com/googleapis/python-api-core/pull/832
20+
21+ In the meantime, please ensure the functionality here mirrors the
22+ equivalent functionality in api_core, in those two functions above.
23+ #}
24+ # An older version of api_core is installed, which does not define the
25+ # functions above. We do equivalent checks manually.
26+
27+ import warnings
28+ import sys
29+
30+ _py_version_str = sys.version.split()[0]
31+ _package_label = "{{package_path}}"
32+ if sys.version_info < (3, 9):
33+ warnings.warn("You are using a non-supported Python version " +
34+ f"({_py_version_str}). Google will not post any further " +
35+ f"updates to {_package_label} supporting this Python version. " +
36+ "Please upgrade to the latest Python version, or at " +
37+ f"least to Python 3.9, and then update {_package_label}.",
38+ FutureWarning)
39+ if sys.version_info[:2] == (3, 9):
40+ warnings.warn(f"You are using a Python version ({_py_version_str}) " +
41+ f"which Google will stop supporting in {_package_label} when " +
42+ "it reaches its end of life (October 2025). Please " +
43+ "upgrade to the latest Python version, or at " +
44+ "least Python 3.10, before then, and " +
45+ f"then update {_package_label}.",
46+ FutureWarning)
47+
48+ from packaging.version import parse as parse_version
49+
50+ if sys.version_info < (3, 8):
51+ import pkg_resources
52+
53+ def _get_version(dependency_name):
54+ try:
55+ version_string = pkg_resources.get_distribution(dependency_name).version
56+ return (parse_version(version_string), version_string)
57+ except pkg_resources.DistributionNotFound:
6858 return (None, "--")
69-
70- _dependency_package = "google.protobuf"
71- _next_supported_version = "4.25.8"
72- _next_supported_version_tuple = (4, 25, 8)
73- (_version_used, _version_used_string) = _get_version(_dependency_package)
74- if _version_used and _version_used < _next_supported_version_tuple:
75- warnings.warn(f"Package {_package_label} depends on " +
76- f"{_dependency_package}, currently installed at version " +
77- f"{_version_used_string}. Future updates to " +
78- f"{_package_label} will require {_dependency_package} at " +
79- f"version {_next_supported_version} or higher. Please ensure " +
80- "that either (a) your Python environment doesn't pin the " +
81- f"version of {_dependency_package}, so that updates to " +
82- f"{_package_label} can require the higher version, or " +
83- "(b) you manually update your Python environment to use at " +
84- f"least version {_next_supported_version} of " +
85- f"{_dependency_package}.",
86- FutureWarning)
59+ else:
60+ from importlib import metadata
61+
62+ def _get_version(dependency_name):
63+ try:
64+ version_string = metadata.version("requests")
65+ parsed_version = parse_version(version_string)
66+ return (parsed_version.release, version_string)
67+ except metadata.PackageNotFoundError:
68+ return (None, "--")
69+
70+ _dependency_package = "google.protobuf"
71+ _next_supported_version = "4.25.8"
72+ _next_supported_version_tuple = (4, 25, 8)
73+ (_version_used, _version_used_string) = _get_version(_dependency_package)
74+ if _version_used and _version_used < _next_supported_version_tuple:
75+ warnings.warn(f"Package {_package_label} depends on " +
76+ f"{_dependency_package}, currently installed at version " +
77+ f"{_version_used_string}. Future updates to " +
78+ f"{_package_label} will require {_dependency_package} at " +
79+ f"version {_next_supported_version} or higher. Please ensure " +
80+ "that either (a) your Python environment doesn't pin the " +
81+ f"version of {_dependency_package}, so that updates to " +
82+ f"{_package_label} can require the higher version, or " +
83+ "(b) you manually update your Python environment to use at " +
84+ f"least version {_next_supported_version} of " +
85+ f"{_dependency_package}.",
86+ FutureWarning)
87+ except Exception as exception: # pragma: NO COVER
88+ warnings.warn(f"Unexpected exception: {exception}")
8789
8890{# Import subpackages. -#}
8991{% for subpackage , _ in api .subpackages |dictsort %}
0 commit comments