Skip to content

Commit

Permalink
Run Black on Generated libraries (#6666)
Browse files Browse the repository at this point in the history
* blacken appveyor

* Blacken all gen'd libraries not under PR
  • Loading branch information
crwilcox authored Nov 28, 2018
1 parent 656a6a7 commit 47b8b60
Show file tree
Hide file tree
Showing 21 changed files with 354 additions and 359 deletions.
2 changes: 2 additions & 0 deletions packages/google-cloud-speech/google/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

try:
import pkg_resources

pkg_resources.declare_namespace(__name__)
except ImportError:
import pkgutil

__path__ = pkgutil.extend_path(__path__, __name__)
2 changes: 2 additions & 0 deletions packages/google-cloud-speech/google/cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

try:
import pkg_resources

pkg_resources.declare_namespace(__name__)
except ImportError:
import pkgutil

__path__ = pkgutil.extend_path(__path__, __name__)
6 changes: 1 addition & 5 deletions packages/google-cloud-speech/google/cloud/speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,4 @@
from google.cloud.speech_v1 import enums
from google.cloud.speech_v1 import types

__all__ = (
'enums',
'types',
'SpeechClient',
)
__all__ = ("enums", "types", "SpeechClient")
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,4 @@ class SpeechClient(SpeechHelpers, speech_client.SpeechClient):
types = types


__all__ = (
'enums',
'SpeechClient',
'types',
)
__all__ = ("enums", "SpeechClient", "types")
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class AudioEncoding(enum.IntEnum):
RTP header is replaced with a single byte containing the block length.
Only Speex wideband is supported. ``sample_rate_hertz`` must be 16000.
"""

ENCODING_UNSPECIFIED = 0
LINEAR16 = 1
FLAC = 2
Expand All @@ -97,5 +98,6 @@ class SpeechEventType(enum.IntEnum):
sent if ``single_utterance`` was set to ``true``, and is not used
otherwise.
"""

SPEECH_EVENT_UNSPECIFIED = 0
END_OF_SINGLE_UTTERANCE = 1
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,18 @@
from google.cloud.speech_v1.proto import cloud_speech_pb2_grpc
from google.longrunning import operations_pb2

_GAPIC_LIBRARY_VERSION = pkg_resources.get_distribution(
'google-cloud-speech', ).version
_GAPIC_LIBRARY_VERSION = pkg_resources.get_distribution("google-cloud-speech").version


class SpeechClient(object):
"""Service that implements Google Cloud Speech API."""

SERVICE_ADDRESS = 'speech.googleapis.com:443'
SERVICE_ADDRESS = "speech.googleapis.com:443"
"""The default address of the service."""

# The name of the interface for this client. This is the key used to
# find the method configuration in the client_config dictionary.
_INTERFACE_NAME = 'google.cloud.speech.v1.Speech'
_INTERFACE_NAME = "google.cloud.speech.v1.Speech"

@classmethod
def from_service_account_file(cls, filename, *args, **kwargs):
Expand All @@ -63,19 +62,20 @@ def from_service_account_file(cls, filename, *args, **kwargs):
Returns:
SpeechClient: The constructed client.
"""
credentials = service_account.Credentials.from_service_account_file(
filename)
kwargs['credentials'] = credentials
credentials = service_account.Credentials.from_service_account_file(filename)
kwargs["credentials"] = credentials
return cls(*args, **kwargs)

from_service_account_json = from_service_account_file

def __init__(self,
transport=None,
channel=None,
credentials=None,
client_config=None,
client_info=None):
def __init__(
self,
transport=None,
channel=None,
credentials=None,
client_config=None,
client_info=None,
):
"""Constructor.
Args:
Expand Down Expand Up @@ -109,18 +109,19 @@ def __init__(self,
# Raise deprecation warnings for things we want to go away.
if client_config is not None:
warnings.warn(
'The `client_config` argument is deprecated.',
"The `client_config` argument is deprecated.",
PendingDeprecationWarning,
stacklevel=2)
stacklevel=2,
)
else:
client_config = speech_client_config.config

if channel:
warnings.warn(
'The `channel` argument is deprecated; use '
'`transport` instead.',
"The `channel` argument is deprecated; use " "`transport` instead.",
PendingDeprecationWarning,
stacklevel=2)
stacklevel=2,
)

# Instantiate the transport.
# The transport is responsible for handling serialization and
Expand All @@ -134,19 +135,19 @@ def __init__(self,
else:
if credentials:
raise ValueError(
'Received both a transport instance and '
'credentials; these are mutually exclusive.')
"Received both a transport instance and "
"credentials; these are mutually exclusive."
)
self.transport = transport
else:
self.transport = speech_grpc_transport.SpeechGrpcTransport(
address=self.SERVICE_ADDRESS,
channel=channel,
credentials=credentials,
address=self.SERVICE_ADDRESS, channel=channel, credentials=credentials
)

if client_info is None:
client_info = google.api_core.gapic_v1.client_info.ClientInfo(
gapic_version=_GAPIC_LIBRARY_VERSION, )
gapic_version=_GAPIC_LIBRARY_VERSION
)
else:
client_info.gapic_version = _GAPIC_LIBRARY_VERSION
self._client_info = client_info
Expand All @@ -156,7 +157,8 @@ def __init__(self,
# (Ordinarily, these are the defaults specified in the `*_config.py`
# file next to this one.)
self._method_configs = google.api_core.gapic_v1.config.parse_method_configs(
client_config['interfaces'][self._INTERFACE_NAME], )
client_config["interfaces"][self._INTERFACE_NAME]
)

# Save a dictionary of cached API call functions.
# These are the actual callables which invoke the proper
Expand All @@ -165,12 +167,14 @@ def __init__(self,
self._inner_api_calls = {}

# Service calls
def recognize(self,
config,
audio,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None):
def recognize(
self,
config,
audio,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Performs synchronous speech recognition: receive results after all audio
has been sent and processed.
Expand Down Expand Up @@ -220,28 +224,29 @@ def recognize(self,
ValueError: If the parameters are invalid.
"""
# Wrap the transport method to add retry and timeout logic.
if 'recognize' not in self._inner_api_calls:
if "recognize" not in self._inner_api_calls:
self._inner_api_calls[
'recognize'] = google.api_core.gapic_v1.method.wrap_method(
self.transport.recognize,
default_retry=self._method_configs['Recognize'].retry,
default_timeout=self._method_configs['Recognize'].timeout,
client_info=self._client_info,
)
"recognize"
] = google.api_core.gapic_v1.method.wrap_method(
self.transport.recognize,
default_retry=self._method_configs["Recognize"].retry,
default_timeout=self._method_configs["Recognize"].timeout,
client_info=self._client_info,
)

request = cloud_speech_pb2.RecognizeRequest(
config=config,
audio=audio,
request = cloud_speech_pb2.RecognizeRequest(config=config, audio=audio)
return self._inner_api_calls["recognize"](
request, retry=retry, timeout=timeout, metadata=metadata
)
return self._inner_api_calls['recognize'](
request, retry=retry, timeout=timeout, metadata=metadata)

def long_running_recognize(self,
config,
audio,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None):

def long_running_recognize(
self,
config,
audio,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Performs asynchronous speech recognition: receive results via the
google.longrunning.Operations interface. Returns either an
Expand Down Expand Up @@ -302,35 +307,36 @@ def long_running_recognize(self,
ValueError: If the parameters are invalid.
"""
# Wrap the transport method to add retry and timeout logic.
if 'long_running_recognize' not in self._inner_api_calls:
if "long_running_recognize" not in self._inner_api_calls:
self._inner_api_calls[
'long_running_recognize'] = google.api_core.gapic_v1.method.wrap_method(
self.transport.long_running_recognize,
default_retry=self._method_configs['LongRunningRecognize'].
retry,
default_timeout=self.
_method_configs['LongRunningRecognize'].timeout,
client_info=self._client_info,
)
"long_running_recognize"
] = google.api_core.gapic_v1.method.wrap_method(
self.transport.long_running_recognize,
default_retry=self._method_configs["LongRunningRecognize"].retry,
default_timeout=self._method_configs["LongRunningRecognize"].timeout,
client_info=self._client_info,
)

request = cloud_speech_pb2.LongRunningRecognizeRequest(
config=config,
audio=audio,
config=config, audio=audio
)
operation = self._inner_api_calls["long_running_recognize"](
request, retry=retry, timeout=timeout, metadata=metadata
)
operation = self._inner_api_calls['long_running_recognize'](
request, retry=retry, timeout=timeout, metadata=metadata)
return google.api_core.operation.from_gapic(
operation,
self.transport._operations_client,
cloud_speech_pb2.LongRunningRecognizeResponse,
metadata_type=cloud_speech_pb2.LongRunningRecognizeMetadata,
)

def streaming_recognize(self,
requests,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None):
def streaming_recognize(
self,
requests,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Performs bidirectional streaming speech recognition: receive results while
sending audio. This method is only available via the gRPC API (not REST).
Expand Down Expand Up @@ -372,16 +378,16 @@ def streaming_recognize(self,
ValueError: If the parameters are invalid.
"""
# Wrap the transport method to add retry and timeout logic.
if 'streaming_recognize' not in self._inner_api_calls:
if "streaming_recognize" not in self._inner_api_calls:
self._inner_api_calls[
'streaming_recognize'] = google.api_core.gapic_v1.method.wrap_method(
self.transport.streaming_recognize,
default_retry=self._method_configs['StreamingRecognize'].
retry,
default_timeout=self._method_configs['StreamingRecognize'].
timeout,
client_info=self._client_info,
)
"streaming_recognize"
] = google.api_core.gapic_v1.method.wrap_method(
self.transport.streaming_recognize,
default_retry=self._method_configs["StreamingRecognize"].retry,
default_timeout=self._method_configs["StreamingRecognize"].timeout,
client_info=self._client_info,
)

return self._inner_api_calls['streaming_recognize'](
requests, retry=retry, timeout=timeout, metadata=metadata)
return self._inner_api_calls["streaming_recognize"](
requests, retry=retry, timeout=timeout, metadata=metadata
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"google.cloud.speech.v1.Speech": {
"retry_codes": {
"idempotent": ["DEADLINE_EXCEEDED", "UNAVAILABLE"],
"non_idempotent": []
"non_idempotent": [],
},
"retry_params": {
"default": {
Expand All @@ -13,26 +13,26 @@
"initial_rpc_timeout_millis": 1000000,
"rpc_timeout_multiplier": 1.0,
"max_rpc_timeout_millis": 1000000,
"total_timeout_millis": 5000000
"total_timeout_millis": 5000000,
}
},
"methods": {
"Recognize": {
"timeout_millis": 200000,
"retry_codes_name": "idempotent",
"retry_params_name": "default"
"retry_params_name": "default",
},
"LongRunningRecognize": {
"timeout_millis": 200000,
"retry_codes_name": "non_idempotent",
"retry_params_name": "default"
"retry_params_name": "default",
},
"StreamingRecognize": {
"timeout_millis": 200000,
"retry_codes_name": "idempotent",
"retry_params_name": "default"
}
}
"retry_params_name": "default",
},
},
}
}
}
Loading

0 comments on commit 47b8b60

Please sign in to comment.