Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: minor typo in ads template #664

Merged
merged 11 commits into from
Oct 16, 2020
32 changes: 0 additions & 32 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ workflows:
filters:
tags:
only: /^v\d+\.\d+\.\d+$/
- showcase-unit-alternative-templates-3.6:
requires:
- unit-3.6
filters:
tags:
only: /^v\d+\.\d+\.\d+$/
- showcase-unit-alternative-templates-3.7:
requires:
- unit-3.7
Expand Down Expand Up @@ -100,7 +94,6 @@ workflows:
requires:
- docs
- mypy
- showcase-unit-alternative-templates-3.6
- showcase-unit-alternative-templates-3.7
- showcase-unit-alternative-templates-3.8
- showcase-mypy-alternative-templates
Expand All @@ -111,7 +104,6 @@ workflows:
requires:
- docs
- mypy
- showcase-unit-alternative-templates-3.6
- showcase-unit-alternative-templates-3.7
- showcase-unit-alternative-templates-3.8
- showcase-mypy-alternative-templates
Expand Down Expand Up @@ -424,30 +416,6 @@ jobs:
- run:
name: Run unit tests.
command: nox -s showcase_unit-3.8
showcase-unit-alternative-templates-3.6:
docker:
- image: python:3.6-slim
steps:
- checkout
- run:
name: Install system dependencies.
command: |
apt-get update
apt-get install -y curl pandoc unzip gcc
- run:
name: Install protoc 3.12.1.
command: |
mkdir -p /usr/src/protoc/
curl --location https://github.com/google/protobuf/releases/download/v3.12.1/protoc-3.12.1-linux-x86_64.zip --output /usr/src/protoc/protoc-3.12.1.zip
cd /usr/src/protoc/
unzip protoc-3.12.1.zip
ln -s /usr/src/protoc/bin/protoc /usr/local/bin/protoc
- run:
name: Install nox.
command: pip install nox
- run:
name: Run unit tests.
command: nox -s showcase_unit_alternative_templates-3.6
showcase-unit-alternative-templates-3.7:
docker:
- image: python:3.7-slim
Expand Down
1 change: 0 additions & 1 deletion .github/sync-repo-settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ branchProtectionRules:
- 'ci/circleci: showcase-unit-3.7'
- 'ci/circleci: showcase-unit-3.8'
- 'ci/circleci: showcase-unit-add-iam-methods'
- 'ci/circleci: showcase-unit-alternative-templates-3.6'
- 'ci/circleci: showcase-unit-alternative-templates-3.7'
- 'ci/circleci: showcase-unit-alternative-templates-3.8'
- 'ci/circleci: style-check'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ class {{ service.name }}Transport(metaclass=abc.ABCMeta):
credentials identify the application to the service; if none
are specified, the client will attempt to ascertain the
credentials from the environment.
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
The client info used to send a user-agent string along with
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
The client info used to send a user-agent string along with
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
your own client library.
"""
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
Expand Down Expand Up @@ -89,7 +89,7 @@ class {{ service.name }}Transport(metaclass=abc.ABCMeta):
{% if method.retry.max_backoff %}maximum={{ method.retry.max_backoff }},{% endif %}
{% if method.retry.backoff_multiplier %}multiplier={{ method.retry.backoff_multiplier }},{% endif %}
predicate=retries.if_exception_type(
{%- for ex in method.retry.retryable_exceptions|sort(attribute='__name__) %}
{%- for ex in method.retry.retryable_exceptions|sort(attribute='__name__') %}
exceptions.{{ ex.__name__ }},
{%- endfor %}
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{% extends '_base.py.j2' %}

{% block content %}
from typing import Callable, Dict, Tuple
import warnings
from typing import Callable, Dict, Optional, Sequence, Tuple

from google.api_core import grpc_helpers # type: ignore
{%- if service.has_lro %}
Expand All @@ -10,7 +11,7 @@ from google.api_core import operations_v1 # type: ignore
from google.api_core import gapic_v1 # type: ignore
from google import auth # type: ignore
from google.auth import credentials # type: ignore

from google.auth.transport.grpc import SslCredentials # type: ignore

import grpc # type: ignore

Expand Down Expand Up @@ -38,8 +39,13 @@ class {{ service.name }}GrpcTransport({{ service.name }}Transport):
def __init__(self, *,
host: str{% if service.host %} = '{{ service.host }}'{% endif %},
credentials: credentials.Credentials = None,
credentials_file: str = None,
scopes: Sequence[str] = None,
channel: grpc.Channel = None,
api_mtls_endpoint: str = None,
client_cert_source: Callable[[], Tuple[bytes, bytes]] = None,
ssl_channel_credentials: grpc.ChannelCredentials = None,
quota_project_id: Optional[str] = None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
) -> None:
"""Instantiate the transport.
Expand All @@ -53,14 +59,29 @@ class {{ service.name }}GrpcTransport({{ service.name }}Transport):
are specified, the client will attempt to ascertain the
credentials from the environment.
This argument is ignored if ``channel`` is provided.
credentials_file (Optional[str]): A file with credentials that can
be loaded with :func:`google.auth.load_credentials_from_file`.
This argument is ignored if ``channel`` is provided.
scopes (Optional(Sequence[str])): A list of scopes. This argument is
ignored if ``channel`` is provided.
channel (Optional[grpc.Channel]): A ``Channel`` instance through
which to make calls.
api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint.
If provided, it overrides the ``host`` argument and tries to create
a mutual TLS channel with client SSL credentials from
``client_cert_source`` or applicatin default SSL credentials.
client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]):
Deprecated. A callback to provide client SSL certificate bytes and
private key bytes, both in PEM format. It is ignored if
``api_mtls_endpoint`` is None.
ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials
for grpc channel. It is ignored if ``channel`` is provided.
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
The client info used to send a user-agent string along with
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
quota_project_id (Optional[str]): An optional project to use for billing
and quota.
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
The client info used to send a user-agent string along with
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
your own client library.

Raises:
Expand All @@ -74,14 +95,41 @@ class {{ service.name }}GrpcTransport({{ service.name }}Transport):

# If a channel was explicitly provided, set it.
self._grpc_channel = channel
elif api_mtls_endpoint:
warnings.warn("api_mtls_endpoint and client_cert_source are deprecated", DeprecationWarning)

host = api_mtls_endpoint if ":" in api_mtls_endpoint else api_mtls_endpoint + ":443"

if credentials is None:
credentials, _ = auth.default(scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id)

# Create SSL credentials with client_cert_source or application
# default SSL credentials.
if client_cert_source:
cert, key = client_cert_source()
ssl_credentials = grpc.ssl_channel_credentials(
certificate_chain=cert, private_key=key
)
else:
ssl_credentials = SslCredentials().ssl_credentials

# create a new channel. The provided one is ignored.
self._grpc_channel = type(self).create_channel(
host,
credentials=credentials,
credentials_file=credentials_file,
ssl_credentials=ssl_credentials,
scopes=scopes or self.AUTH_SCOPES,
quota_project_id=quota_project_id,
)
else:
host = host if ":" in host else host + ":443"

if credentials is None:
credentials, _ = auth.default(scopes=self.AUTH_SCOPES)

# create a new channel. The provided one is ignored.
self._grpc_channel = grpc_helpers.create_channel(
self._grpc_channel = type(self).create_channel(
host,
credentials=credentials,
ssl_credentials=ssl_channel_credentials,
Expand All @@ -102,6 +150,7 @@ class {{ service.name }}GrpcTransport({{ service.name }}Transport):
def create_channel(cls,
host: str{% if service.host %} = '{{ service.host }}'{% endif %},
credentials: credentials.Credentials = None,
scopes: Optional[Sequence[str]] = None,
**kwargs) -> grpc.Channel:
"""Create and return a gRPC channel object.
Args:
Expand All @@ -111,6 +160,9 @@ class {{ service.name }}GrpcTransport({{ service.name }}Transport):
credentials identify this application to the service. If
none are specified, the client will attempt to ascertain
the credentials from the environment.
scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
service. These are only used when credentials are not specified and
are passed to :func:`google.auth.default`.
kwargs (Optional[dict]): Keyword arguments, which are passed to the
channel creation.
Returns:
Expand All @@ -119,26 +171,14 @@ class {{ service.name }}GrpcTransport({{ service.name }}Transport):
return grpc_helpers.create_channel(
host,
credentials=credentials,
scopes=cls.AUTH_SCOPES,
scopes=scopes or cls.AUTH_SCOPES,
**kwargs
)

@property
def grpc_channel(self) -> grpc.Channel:
"""Create the channel designed to connect to this service.

This property caches on the instance; repeated calls return
the same channel.
"""Return the channel designed to connect to this service.
"""
# Sanity check: Only create a new channel if we do not already
# have one.
if not hasattr(self, '_grpc_channel'):
self._grpc_channel = self.create_channel(
self._host,
credentials=self._credentials,
)

# Return the channel from cache.
return self._grpc_channel
{%- if service.has_lro %}

Expand Down
2 changes: 1 addition & 1 deletion gapic/ads-templates/noxfile.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def unit(session):
'--cov-config=.coveragerc',
'--cov-report=term',
'--cov-report=html',
os.path.join('tests', 'unit', '{{ api.naming.versioned_module_name }}'),
os.path.join('tests', 'unit', 'gapic', '{{ api.naming.versioned_module_name }}'),
)


Expand Down
2 changes: 1 addition & 1 deletion gapic/ads-templates/setup.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ setuptools.setup(
'grpc-google-iam-v1',
{%- endif %}
),
python_requires='>={% if opts.lazy_import %}3.7{% else %}3.6{% endif %}',{# Lazy import requires module-level getattr #}
python_requires='>=3.7',{# Lazy import requires module-level getattr #}
setup_requires=[
'libcst >= 0.2.5',
],
Expand Down
Loading