Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ def test_{{ method_name }}_field_headers():
assert (
'x-goog-request-params',
'{% for field_header in method.field_headers -%}
{{ field_header.raw }}={{ method.input.get_field(field_header.disambiguated).mock_value|trim("'") }}
{{ field_header.raw }}={{ method.input.get_field(field_header.disambiguated).mock_value|trim('"') }}
{%- if not loop.last %}&{% endif %}
{%- endfor -%}',
) in kw['metadata']
Expand Down
4 changes: 2 additions & 2 deletions gapic/schema/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def rel(self, address: "Address") -> str:
# created, so there is no way for one nested class to reference
# another at class instantiation time.
if self.parent and address.parent and self.parent[0] == address.parent[0]:
return f"'{'.'.join(self.parent)}.{self.name}'"
return f"\"{'.'.join(self.parent)}.{self.name}\""

# Edge case: Similar to above, if this is a message that is
# referencing a nested message that it contains, we need
Expand All @@ -333,7 +333,7 @@ def rel(self, address: "Address") -> str:
# identifier. It is guaranteed to work all the time because
# it bumps name resolution until a time when all types in a module
# are guaranteed to be fully defined.
return f"'{'.'.join(self.parent + (self.name,))}'"
return f"\"{'.'.join(self.parent + (self.name,))}\""

# Return the usual `module.Name`.
return str(self)
Expand Down
2 changes: 1 addition & 1 deletion gapic/schema/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def primitive_mock_as_str(self) -> str:
answer = self.primitive_mock()

if isinstance(answer, str):
answer = f"'{answer}'"
answer = f'"{answer}"'
else:
answer = str(answer)

Expand Down
12 changes: 5 additions & 7 deletions gapic/templates/%namespace/%name/__init__.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,24 @@ from {% if api.naming.module_namespace %}{{ api.naming.module_namespace|join('.'
#}

__all__ = (
{%- filter indent %}
{% for subpackage, _ in api.subpackages|dictsort %}
'{{ subpackage }}',
"{{ subpackage }}",
{% endfor %}
{% for service in api.services.values()|sort(attribute='name')
if service.meta.address.subpackage == api.subpackage_view %}
'{{ service.client_name }}',
"{{ service.client_name }}",
{% if 'grpc' in opts.transport %}
'{{ service.async_client_name }}',
"{{ service.async_client_name }}",
{% endif %}
{% endfor %}
{% for proto in api.protos.values()|sort(attribute='module_name')
if proto.meta.address.subpackage == api.subpackage_view %}
{% for message in proto.messages.values()|sort(attribute='name') %}
'{{ message.name }}',
"{{ message.name }}",
{% endfor %}
{% for enum in proto.enums.values()|sort(attribute='name')
if proto.meta.address.subpackage == api.subpackage_view %}
'{{ enum.name }}',
"{{ enum.name }}",
{% endfor %}{% endfor %}
{% endfilter %}
)
{% endblock %}
119 changes: 65 additions & 54 deletions gapic/templates/%namespace/%name_%version/%sub/__init__.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ from .types.{{ proto.module_name }} import {{ enum.name }}
{% endfor %}
{% endfor %}

if hasattr(api_core, "check_python_version") and hasattr(api_core, "check_dependency_versions"): # pragma: NO COVER
{# TODO(api_core): remove `type:ignore` below when minimum version of api_core makes the else clause unnecessary. #}
api_core.check_python_version("{{package_path}}") # type: ignore
api_core.check_dependency_versions("{{package_path}}") # type: ignore
else: # pragma: NO COVER
if hasattr(api_core, "check_python_version") and hasattr(api_core, "check_dependency_versions"): # pragma: NO COVER
api_core.check_python_version("{{package_path}}") # type: ignore
api_core.check_dependency_versions("{{package_path}}") # type: ignore
else: # pragma: NO COVER
{# TODO(api_core): Remove this try-catch when we require api-core at a version that
supports the changes in https://github.com/googleapis/python-api-core/pull/832

Expand All @@ -66,20 +65,24 @@ else: # pragma: NO COVER
_py_version_str = sys.version.split()[0]
_package_label = "{{package_path}}"
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)
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)
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.
Expand Down Expand Up @@ -117,51 +120,59 @@ else: # pragma: NO COVER
_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)
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/")
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/"
)

{# Define __all__.
This requires the full set of imported names, so we iterate over
them again.
-#}
__all__ = (
{% filter sort_lines -%}
{% for subpackage in api.subpackages -%}
'{{ subpackage }}',
{% endfor -%}


{% with imported_names = [] %}
__all__ = ({% for subpackage in api.subpackages %}
{% do imported_names.append(subpackage) %}
{% endfor %}
{% for service in api.services.values()
if service.meta.address.subpackage == api.subpackage_view -%}
'{{ service.client_name }}',
if service.meta.address.subpackage == api.subpackage_view %}
{% do imported_names.append(service.client_name) %}
{% if 'grpc' in opts.transport %}
'{{ service.async_client_name }}',
{% do imported_names.append(service.async_client_name) %}
{% endif %}
{% endfor -%}
{% endfor %}
{% for proto in api.protos.values()
if proto.meta.address.subpackage == api.subpackage_view -%}
{% for message in proto.messages.values()|sort(attribute='name') -%}
'{{ message.name }}',
{% endfor -%}
{% for enum in proto.enums.values() -%}
'{{ enum.name }}',
{% endfor -%}
{% endfor -%}
{% endfilter %}
if proto.meta.address.subpackage == api.subpackage_view %}
{% for message in proto.messages.values()|sort(attribute='name') %}
{% do imported_names.append(message.name) %}
{% endfor %}
{% for enum in proto.enums.values() %}
{% do imported_names.append(enum.name) %}
{% endfor %}
{% endfor %}
{% for name in imported_names|sort %}
"{{ name }}",
{% endfor %}
)
{% endwith %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ from .async_client import {{ service.async_client_name }}
{% endif %}

__all__ = (
'{{ service.client_name }}',
"{{ service.client_name }}",
{% if 'grpc' in opts.transport %}
'{{ service.async_client_name }}',
"{{ service.async_client_name }}",
{% endif %}
)
{% endblock %}
Loading
Loading