@@ -46,11 +46,10 @@ from .types.{{ proto.module_name }} import {{ enum.name }}
4646{% endfor %}
4747{% endfor %}
4848
49- if hasattr(api_core, "check_python_version") and hasattr(api_core, "check_dependency_versions"): # pragma: NO COVER
50- {# TODO(api_core): remove `type:ignore` below when minimum version of api_core makes the else clause unnecessary. #}
51- api_core.check_python_version("{{package_path}}") # type: ignore
52- api_core.check_dependency_versions("{{package_path}}") # type: ignore
53- else: # pragma: NO COVER
49+ if hasattr(api_core, "check_python_version") and hasattr(api_core, "check_dependency_versions"): # pragma: NO COVER
50+ api_core.check_python_version("{{package_path}}") # type: ignore
51+ api_core.check_dependency_versions("{{package_path}}") # type: ignore
52+ else: # pragma: NO COVER
5453{# TODO(api_core): Remove this try-catch when we require api-core at a version that
5554 supports the changes in https://github.com/googleapis/python-api-core/pull/832
5655
@@ -66,20 +65,24 @@ else: # pragma: NO COVER
6665 _py_version_str = sys.version.split()[0]
6766 _package_label = "{{package_path}}"
6867 if sys.version_info < (3, 9):
69- warnings.warn("You are using a non-supported Python version " +
70- f"({_py_version_str}). Google will not post any further " +
71- f"updates to {_package_label} supporting this Python version. " +
72- "Please upgrade to the latest Python version, or at " +
73- f"least to Python 3.9, and then update {_package_label}.",
74- FutureWarning)
68+ warnings.warn(
69+ "You are using a non-supported Python version "
70+ + f"({_py_version_str}). Google will not post any further "
71+ + f"updates to {_package_label} supporting this Python version. "
72+ + "Please upgrade to the latest Python version, or at "
73+ + f"least to Python 3.9, and then update {_package_label}.",
74+ FutureWarning,
75+ )
7576 if sys.version_info[:2] == (3, 9):
76- warnings.warn(f"You are using a Python version ({_py_version_str}) " +
77- f"which Google will stop supporting in {_package_label} in " +
78- "January 2026. Please " +
79- "upgrade to the latest Python version, or at " +
80- "least to Python 3.10, before then, and " +
81- f"then update {_package_label}.",
82- FutureWarning)
77+ warnings.warn(
78+ f"You are using a Python version ({_py_version_str}) "
79+ + f"which Google will stop supporting in {_package_label} in "
80+ + "January 2026. Please "
81+ + "upgrade to the latest Python version, or at "
82+ + "least to Python 3.10, before then, and "
83+ + f"then update {_package_label}.",
84+ FutureWarning,
85+ )
8386
8487 def parse_version_to_tuple(version_string: str):
8588 """Safely converts a semantic version string to a comparable tuple of integers.
@@ -117,51 +120,59 @@ else: # pragma: NO COVER
117120 _recommendation = " (we recommend 6.x)"
118121 (_version_used, _version_used_string) = _get_version(_dependency_package)
119122 if _version_used and _version_used < _next_supported_version_tuple:
120- warnings.warn(f"Package {_package_label} depends on " +
121- f"{_dependency_package}, currently installed at version " +
122- f"{_version_used_string}. Future updates to " +
123- f"{_package_label} will require {_dependency_package} at " +
124- f"version {_next_supported_version} or higher{_recommendation}." +
125- " Please ensure " +
126- "that either (a) your Python environment doesn't pin the " +
127- f"version of {_dependency_package}, so that updates to " +
128- f"{_package_label} can require the higher version, or " +
129- "(b) you manually update your Python environment to use at " +
130- f"least version {_next_supported_version} of " +
131- f"{_dependency_package}.",
132- FutureWarning)
123+ warnings.warn(
124+ f"Package {_package_label} depends on "
125+ + f"{_dependency_package}, currently installed at version "
126+ + f"{_version_used_string}. Future updates to "
127+ + f"{_package_label} will require {_dependency_package} at "
128+ + f"version {_next_supported_version} or higher{_recommendation}."
129+ + " Please ensure "
130+ + "that either (a) your Python environment doesn't pin the "
131+ + f"version of {_dependency_package}, so that updates to "
132+ + f"{_package_label} can require the higher version, or "
133+ + "(b) you manually update your Python environment to use at "
134+ + f"least version {_next_supported_version} of "
135+ + f"{_dependency_package}.",
136+ FutureWarning,
137+ )
133138 except Exception:
134- warnings.warn("Could not determine the version of Python " +
135- "currently being used. To continue receiving " +
136- "updates for {_package_label}, ensure you are " +
137- "using a supported version of Python; see " +
138- "https://devguide.python.org/versions/")
139+ warnings.warn(
140+ "Could not determine the version of Python "
141+ + "currently being used. To continue receiving "
142+ + "updates for {_package_label}, ensure you are "
143+ + "using a supported version of Python; see "
144+ + "https://devguide.python.org/versions/"
145+ )
139146
140147{# Define __all__.
141148 This requires the full set of imported names, so we iterate over
142149 them again.
143150-#}
144- __all__ = (
145- {% filter sort_lines -%}
146- {% for subpackage in api .subpackages -%}
147- '{{ subpackage }}',
148- {% endfor -%}
151+
152+
153+ {% with imported_names = [] %}
154+ __all__ = ({% for subpackage in api .subpackages %}
155+ {% do imported_names .append (subpackage ) %}
156+ {% endfor %}
149157 {% for service in api .services .values ()
150- if service .meta .address .subpackage == api .subpackage_view - %}
151- '{{ service.client_name }}',
158+ if service .meta .address .subpackage == api .subpackage_view %}
159+ {% do imported_names . append ( service .client_name ) %}
152160 {% if 'grpc' in opts .transport %}
153- '{{ service.async_client_name }}',
161+ {% do imported_names . append ( service .async_client_name ) %}
154162 {% endif %}
155- {% endfor - %}
163+ {% endfor %}
156164 {% for proto in api .protos .values ()
157- if proto .meta .address .subpackage == api .subpackage_view -%}
158- {% for message in proto .messages .values ()|sort (attribute ='name' ) -%}
159- '{{ message.name }}',
160- {% endfor -%}
161- {% for enum in proto .enums .values () -%}
162- '{{ enum.name }}',
163- {% endfor -%}
164- {% endfor -%}
165- {% endfilter %}
165+ if proto .meta .address .subpackage == api .subpackage_view %}
166+ {% for message in proto .messages .values ()|sort (attribute ='name' ) %}
167+ {% do imported_names .append (message .name ) %}
168+ {% endfor %}
169+ {% for enum in proto .enums .values () %}
170+ {% do imported_names .append (enum .name ) %}
171+ {% endfor %}
172+ {% endfor %}
173+ {% for name in imported_names |sort %}
174+ "{{ name }}",
175+ {% endfor %}
166176)
177+ {% endwith %}
167178{% endblock %}
0 commit comments