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 @@ -227,7 +227,8 @@ def _get_http_options():
request_url = "{host}{uri}".format(host=self._host, uri=transcoded_request['uri'])
method = transcoded_request['method']
{# TODO(https://github.com/googleapis/gapic-generator-python/issues/2137): Remove `type: ignore` once version check is added for google-api-core. #}
raise core_exceptions.format_http_response_error(response, method, request_url, payload) # type: ignore
{# Add `# fmt: skip` to keep `# type: ignore` on the same line #}
raise core_exceptions.format_http_response_error(response, method, request_url, payload) # type: ignore # fmt: skip
{% else %}
raise core_exceptions.from_http_response(response)
{% endif %}{# is_async #}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):

DEFAULT_ENDPOINT = {% if service.host %}"{{ service.host }}"{% else %}None{% endif %}

DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore
{# Add `# fmt: skip` to keep `# type: ignore` on the same line #}
DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore # fmt: skip
DEFAULT_ENDPOINT
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ class {{service.name}}RestTransport(_Base{{ service.name }}RestTransport):
{{method.output.ident}}]:
# The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
# In C++ this would require a dynamic_cast
return self._{{method.name}}(self._session, self._host, self._interceptor) # type: ignore
{# Add `# fmt: skip` to keep `# type: ignore` on the same line #}
return self._{{method.name}}(self._session, self._host, self._interceptor) # type: ignore # fmt: skip

{% endfor %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import sys

__version__ = package_version.__version__

if sys.version_info >= (3, 8): # pragma: NO COVER
{# Add `# fmt: skip` to keep `# pragma: NO COVER` on the same line #}
if sys.version_info >= (3, 8): # pragma: NO COVER # fmt: skip
from importlib import metadata
else: # pragma: NO COVER
{# Add `# fmt: skip` to keep `# pragma: NO COVER` on the same line #}
else: # pragma: NO COVER # fmt: skip
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused why the skip tag is needed here. Is ruff doing anything to this line? Or is this just in case?

# TODO(https://github.com/googleapis/python-api-core/issues/835): Remove
# this code path once we drop support for Python 3.7
import importlib_metadata as metadata
Expand Down Expand Up @@ -46,7 +48,8 @@ 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
{# Add `# fmt: skip` to keep `# pragma: NO COVER` on the same line #}
if hasattr(api_core, "check_python_version") and hasattr(api_core, "check_dependency_versions"): # pragma: NO COVER # fmt: skip
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of skipping the formatting, can this be broken into multiple lines? This is 129 characters, so it will stand out quite a bit

{# 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ except ImportError: # pragma: NO COVER
`add_google_api_core_version_header_import` to add the necessary import statements.
#}
{% if service_version %}
if HAS_GOOGLE_API_CORE_VERSION_HEADER: # pragma: NO COVER
{# Add `# fmt: skip` to keep `# pragma: NO COVER` on the same line #}
if HAS_GOOGLE_API_CORE_VERSION_HEADER: # pragma: NO COVER # fmt: skip
metadata = tuple(metadata) + (
version_header.to_api_version_header("{{ service_version }}"),
)
Expand Down Expand Up @@ -215,7 +216,8 @@ def _get_http_options():
# Jsonify the query params
query_params = _Base{{ service_name }}RestTransport._Base{{method_name}}._get_query_params_json(transcoded_request)

if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER
{# Add `# fmt: skip` to keep `# pragma: NO COVER` on the same line #}
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER # fmt: skip
request_url = "{host}{uri}".format(host=self._host, uri=transcoded_request['uri'])
method = transcoded_request['method']
try:
Expand Down Expand Up @@ -257,7 +259,8 @@ def _get_http_options():
request_url = "{host}{uri}".format(host=self._host, uri=transcoded_request['uri'])
method = transcoded_request['method']
{# TODO(https://github.com/googleapis/gapic-generator-python/issues/2137): Remove `type: ignore` once version check is added for google-api-core. #}
raise core_exceptions.format_http_response_error(response, method, request_url, payload) # type: ignore
{# Add `# fmt: skip` to keep `# type: ignore` on the same line #}
raise core_exceptions.format_http_response_error(response, method, request_url, payload) # type: ignore # fmt: skip
{% else %}
raise core_exceptions.from_http_response(response)
{% endif %}{# is_async #}
Expand Down Expand Up @@ -355,7 +358,8 @@ See related issue: https://github.com/googleapis/gapic-generator-python/issues/2
{% macro wrap_async_method_macro() %}
def _wrap_method(self, func, *args, **kwargs):
{# TODO: Remove `pragma: NO COVER` once https://github.com/googleapis/python-api-core/pull/688 is merged. #}
if self._wrap_with_kind: # pragma: NO COVER
{# Add `# fmt: skip` to keep `# pragma: NO COVER` on the same line #}
if self._wrap_with_kind: # pragma: NO COVER # fmt: skip
kwargs["kind"] = self.kind
return gapic_v1.method_async.wrap_method(func, *args, **kwargs)
{% endmacro %}
Expand Down Expand Up @@ -489,7 +493,8 @@ class {{ async_method_name_prefix }}{{ service.name }}RestInterceptor:

@property
def {{ name|snake_case }}(self):
return self.{{ name|make_private }}(self._session, self._host, self._interceptor) # type: ignore
{# Add `# fmt: skip` to keep `# type: ignore` on the same line #}
return self.{{ name|make_private }}(self._session, self._host, self._interceptor) # type: ignore # fmt: skip

class {{ name|make_private }}(_Base{{ service.name }}RestTransport._Base{{name}}, {{ async_method_name_prefix }}{{service.name}}RestStub):
def __hash__(self):
Expand Down Expand Up @@ -535,7 +540,8 @@ class {{ name|make_private }}(_Base{{ service.name }}RestTransport._Base{{name}}
resp = {{ sig.response_type }}()
resp = json_format.Parse(content, resp)
resp = {{ await_prefix }}self._interceptor.post_{{ name|snake_case }}(resp)
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER
{# Add `# fmt: skip` to keep `# pragma: NO COVER` on the same line #}
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER # fmt: skip
try:
response_payload = json_format.MessageToJson(resp)
except:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ class {{ service.async_client_name }}:
Returns:
{{ service.async_client_name }}: The constructed client.
"""
return {{ service.client_name }}.from_service_account_info.__func__({{ service.async_client_name }}, info, *args, **kwargs) # type: ignore
{# Add `# fmt: skip` to keep `# type: ignore` on the same line #}
return {{ service.client_name }}.from_service_account_info.__func__({{ service.async_client_name }}, info, *args, **kwargs) # type: ignore # fmt: skip

@classmethod
def from_service_account_file(cls, filename: str, *args, **kwargs):
Expand All @@ -114,7 +115,8 @@ class {{ service.async_client_name }}:
Returns:
{{ service.async_client_name }}: The constructed client.
"""
return {{ service.client_name }}.from_service_account_file.__func__({{ service.async_client_name }}, filename, *args, **kwargs) # type: ignore
{# Add `# fmt: skip` to keep `# type: ignore` on the same line #}
return {{ service.client_name }}.from_service_account_file.__func__({{ service.async_client_name }}, filename, *args, **kwargs) # type: ignore # fmt: skip
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be broken up?


from_service_account_json = from_service_account_file

Expand Down Expand Up @@ -150,7 +152,8 @@ class {{ service.async_client_name }}:
Raises:
google.auth.exceptions.MutualTLSChannelError: If any errors happen.
"""
return {{ service.client_name }}.get_mtls_endpoint_and_cert_source(client_options) # type: ignore
{# Add `# fmt: skip` to keep `# type: ignore` on the same line #}
return {{ service.client_name }}.get_mtls_endpoint_and_cert_source(client_options) # type: ignore # fmt: skip

@property
def transport(self) -> {{ service.name }}Transport:
Expand Down Expand Up @@ -252,7 +255,8 @@ class {{ service.async_client_name }}:

)

if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER
{# Add ` # fmt: skip` to keep `# pragma: NO COVER` on the same line #}
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER # fmt: skip
_LOGGER.debug(
"Created client `{{ service.meta.address.proto_package_versioned }}.{{ service.async_client_name }}`.",
extra = {
Expand Down Expand Up @@ -727,7 +731,8 @@ class {{ service.async_client_name }}:

DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__)

if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER
{# Add `# fmt: skip` to keep `# pragma: NO COVER` on the same line #}
if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER # fmt: skip
DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ class {{ service.client_name }}Meta(type):
_transport_registry["rest"] = {{ service.name }}RestTransport
{# TODO(https://github.com/googleapis/gapic-generator-python/issues/2121): Remove this condition when async rest is GA. #}
{% if rest_async_io_enabled %}
if HAS_ASYNC_REST_DEPENDENCIES: # pragma: NO COVER
{# Add `# fmt: skip` to keep `# pragma: NO COVER` on the same line #}
if HAS_ASYNC_REST_DEPENDENCIES: # pragma: NO COVER # fmt: skip
_transport_registry["rest_asyncio"] = Async{{ service.name }}RestTransport
{% endif %}{# if rest_async_io_enabled #}
{% endif %}
Expand All @@ -127,7 +128,8 @@ class {{ service.client_name }}Meta(type):
{# TODO(https://github.com/googleapis/gapic-generator-python/issues/2121): Remove this condition when async rest is GA. #}
{% if rest_async_io_enabled %}
{# NOTE: `pragma: NO COVER` is needed since the coverage for presubmits isn't combined. #}
if label == "rest_asyncio" and not HAS_ASYNC_REST_DEPENDENCIES: # pragma: NO COVER
{# Add ` # fmt: skip` to keep `# pragma: NO COVER` on the same line #}
if label == "rest_asyncio" and not HAS_ASYNC_REST_DEPENDENCIES: # pragma: NO COVER # fmt: skip
raise ASYNC_REST_EXCEPTION
{% endif %}
if label:
Expand Down Expand Up @@ -175,7 +177,8 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
# Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead.
DEFAULT_ENDPOINT = {% if service.host %}"{{ service.host }}"{% else %}None{% endif %}

DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore
{# Add `# fmt: skip` to keep `# type: ignore` on the same line #}
DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore # fmt: skip
DEFAULT_ENDPOINT
)

Expand All @@ -197,7 +200,8 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.)
"""
# check if google-auth version supports should_use_client_cert for automatic mTLS enablement
if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER
{# Add `# fmt: skip` to keep `# pragma: NO COVER` on the same line #}
if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER # fmt: skip
return mtls.should_use_client_cert()
else: # pragma: NO COVER
# if unsupported, fallback to reading from env var
Expand Down Expand Up @@ -568,7 +572,8 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
# Initialize the universe domain validation.
self._is_universe_domain_valid = False

if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER
{# Add ` # fmt: skip` to keep `# pragma: NO COVER` on the same line #}
if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER # fmt: skip
# Setup logging.
client_logging.initialize_logging()

Expand Down Expand Up @@ -660,7 +665,8 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
)

if "async" not in str(self._transport):
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER
{# Add `# fmt: skip` to keep `# pragma: NO COVER` on the same line #}
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER # fmt: skip
_LOGGER.debug(
"Created client `{{ service.meta.address.proto_package_versioned }}.{{ service.client_name }}`.",
extra = {
Expand Down Expand Up @@ -1014,7 +1020,8 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):

DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__)

if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER
{# Add ` # fmt: skip` to keep `# pragma: NO COVER` on the same line #}
if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER # fmt: skip
DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__

__all__ = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ _transport_registry['grpc_asyncio'] = {{ service.name }}GrpcAsyncIOTransport
{% if 'rest' in opts.transport %}
_transport_registry['rest'] = {{ service.name }}RestTransport
{% if rest_async_io_enabled %}
if HAS_REST_ASYNC: # pragma: NO COVER
{# Add ` # fmt: skip` to keep `# pragma: NO COVER` on the same line #}
if HAS_REST_ASYNC: # pragma: NO COVER # fmt: skip
_transport_registry['rest_asyncio'] = Async{{ service.name }}RestTransport
{% endif %}{# if rest_async_io_enabled #}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ from {{ (api.naming.module_namespace + (api.naming.versioned_module_name,) + ser

DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__)

if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER
{# Add `# fmt: skip` to keep `# type: ignore` on the same line #}
if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER # fmt: skip
DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class _LoggingClientAIOInterceptor(grpc.aio.UnaryUnaryClientInterceptor): # pra
async def intercept_unary_unary(self, continuation, client_call_details, request):
{{ shared_macros.unary_request_interceptor_common(service) }}
response = await continuation(client_call_details, request)
if logging_enabled: # pragma: NO COVER
if logging_enabled:
response_metadata = await response.trailing_metadata()
# Convert gRPC metadata `<class 'grpc.aio._metadata.Metadata'>` to list of tuples
metadata = dict([(k, str(v)) for k, v in response_metadata]) if response_metadata else None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
rest_version=f"requests@{requests_version}",
)

if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER
{# Add `# fmt: skip` to keep `# pragma: NO COVER` on the same line #}
if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER # fmt: skip
DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__


Expand Down Expand Up @@ -263,7 +264,8 @@ class {{service.name}}RestTransport(_Base{{ service.name }}RestTransport):
resp = self._interceptor.post_{{ method.name|snake_case }}(resp)
response_metadata = [(k, str(v)) for k, v in response.headers.items()]
resp, _ = self._interceptor.post_{{ method.name|snake_case }}_with_metadata(resp, response_metadata)
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER
{# Add `# fmt: skip` to keep `# pragma: NO COVER` on the same line #}
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER # fmt: skip
{# TODO(https://github.com/googleapis/gapic-generator-python/issues/2389): #}
{# Depending how we want to log (a) receiving a streaming response vs (b) exposing the next streamed item to the user, we could possibly want to log something here #}
{# (a) should always happen in api-core #}
Expand Down Expand Up @@ -311,7 +313,8 @@ class {{service.name}}RestTransport(_Base{{ service.name }}RestTransport):
{{method.output.ident}}]:
# The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
# In C++ this would require a dynamic_cast
return self._{{method.name}}(self._session, self._host, self._interceptor) # type: ignore
{# Add `# fmt: skip` to keep `# type: ignore` on the same line #}
return self._{{method.name}}(self._session, self._host, self._interceptor) # type: ignore # fmt: skip

{% endfor %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
rest_version=f"google-auth@{google.auth.__version__}",
)

if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER
{# Add `# fmt: skip` to keep `# pragma: NO COVER` on the same line #}
if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER # fmt: skip
DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__

{{ shared_macros.create_interceptor_class(api, service, method, is_async=True) }}
Expand Down Expand Up @@ -222,7 +223,8 @@ class Async{{service.name}}RestTransport(_Base{{ service.name }}RestTransport):
resp = await self._interceptor.post_{{ method.name|snake_case }}(resp)
response_metadata = [(k, str(v)) for k, v in response.headers.items()]
resp, _ = await self._interceptor.post_{{ method.name|snake_case }}_with_metadata(resp, response_metadata)
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER
{# Add `# fmt: skip` to keep `# pragma: NO COVER` on the same line #}
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER # fmt: skip
{# TODO(https://github.com/googleapis/gapic-generator-python/issues/2389): #}
{# Depending how we want to log (a) receiving a streaming response vs (b) exposing the next streamed item to the user, we could possibly want to log something here #}
{# (a) should always happen in api-core #}
Expand Down Expand Up @@ -318,7 +320,8 @@ class Async{{service.name}}RestTransport(_Base{{ service.name }}RestTransport):
def {{method.transport_safe_name|snake_case}}(self) -> Callable[
[{{method.input.ident}}],
{{method.output.ident}}]:
return self._{{method.name}}(self._session, self._host, self._interceptor) # type: ignore
{# Add `# fmt: skip` to keep `# type: ignore` on the same line #}
return self._{{method.name}}(self._session, self._host, self._interceptor) # type: ignore # fmt: skip

{% endfor %}
{% for name, sig in api.mixin_api_signatures.items() %}
Expand Down
Loading
Loading