Skip to content

Commit

Permalink
Upgrade yapf to 0.20.0
Browse files Browse the repository at this point in the history
Upgrade yapf version to 0.20.0 and reformat Python files.
  • Loading branch information
mehrdada committed Jan 2, 2018
1 parent 63392f6 commit 87cd994
Show file tree
Hide file tree
Showing 135 changed files with 1,750 additions and 1,146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@


class _ClientCallDetails(
collections.namedtuple('_ClientCallDetails',
('method', 'timeout', 'metadata',
'credentials')), grpc.ClientCallDetails):
collections.namedtuple(
'_ClientCallDetails',
('method', 'timeout', 'metadata', 'credentials')),
grpc.ClientCallDetails):
pass


Expand All @@ -33,7 +34,10 @@ def intercept_call(client_call_details, request_iterator, request_streaming,
metadata = []
if client_call_details.metadata is not None:
metadata = list(client_call_details.metadata)
metadata.append((header, value,))
metadata.append((
header,
value,
))
client_call_details = _ClientCallDetails(
client_call_details.method, client_call_details.timeout, metadata,
client_call_details.credentials)
Expand Down
10 changes: 5 additions & 5 deletions examples/python/multiplex/multiplex_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def guide_get_one_feature(route_guide_stub, point):


def guide_get_feature(route_guide_stub):
guide_get_one_feature(
route_guide_stub,
route_guide_pb2.Point(latitude=409146138, longitude=-746188906))
guide_get_one_feature(route_guide_stub,
route_guide_pb2.Point(
latitude=409146138, longitude=-746188906))
guide_get_one_feature(route_guide_stub,
route_guide_pb2.Point(latitude=0, longitude=0))

Expand Down Expand Up @@ -101,8 +101,8 @@ def generate_messages():
def guide_route_chat(route_guide_stub):
responses = route_guide_stub.RouteChat(generate_messages())
for response in responses:
print("Received message %s at %s" %
(response.message, response.location))
print("Received message %s at %s" % (response.message,
response.location))


def run():
Expand Down
4 changes: 2 additions & 2 deletions examples/python/multiplex/multiplex_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def serve():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
helloworld_pb2_grpc.add_GreeterServicer_to_server(_GreeterServicer(),
server)
route_guide_pb2_grpc.add_RouteGuideServicer_to_server(_RouteGuideServicer(),
server)
route_guide_pb2_grpc.add_RouteGuideServicer_to_server(
_RouteGuideServicer(), server)
server.add_insecure_port('[::]:50051')
server.start()
try:
Expand Down
18 changes: 14 additions & 4 deletions examples/python/multiplex/run_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@

from grpc_tools import protoc

protoc.main(('', '-I../../protos', '--python_out=.', '--grpc_python_out=.',
'../../protos/helloworld.proto',))
protoc.main(('', '-I../../protos', '--python_out=.', '--grpc_python_out=.',
'../../protos/route_guide.proto',))
protoc.main((
'',
'-I../../protos',
'--python_out=.',
'--grpc_python_out=.',
'../../protos/helloworld.proto',
))
protoc.main((
'',
'-I../../protos',
'--python_out=.',
'--grpc_python_out=.',
'../../protos/route_guide.proto',
))
9 changes: 5 additions & 4 deletions examples/python/route_guide/route_guide_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ def guide_get_one_feature(stub, point):


def guide_get_feature(stub):
guide_get_one_feature(
stub, route_guide_pb2.Point(latitude=409146138, longitude=-746188906))
guide_get_one_feature(stub,
route_guide_pb2.Point(
latitude=409146138, longitude=-746188906))
guide_get_one_feature(stub, route_guide_pb2.Point(latitude=0, longitude=0))


Expand Down Expand Up @@ -94,8 +95,8 @@ def generate_messages():
def guide_route_chat(stub):
responses = stub.RouteChat(generate_messages())
for response in responses:
print("Received message %s at %s" %
(response.message, response.location))
print("Received message %s at %s" % (response.message,
response.location))


def run():
Expand Down
4 changes: 2 additions & 2 deletions examples/python/route_guide/route_guide_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def RouteChat(self, request_iterator, context):

def serve():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
route_guide_pb2_grpc.add_RouteGuideServicer_to_server(RouteGuideServicer(),
server)
route_guide_pb2_grpc.add_RouteGuideServicer_to_server(
RouteGuideServicer(), server)
server.add_insecure_port('[::]:50051')
server.start()
try:
Expand Down
9 changes: 7 additions & 2 deletions examples/python/route_guide/run_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@

from grpc_tools import protoc

protoc.main(('', '-I../../protos', '--python_out=.', '--grpc_python_out=.',
'../../protos/route_guide.proto',))
protoc.main((
'',
'-I../../protos',
'--python_out=.',
'--grpc_python_out=.',
'../../protos/route_guide.proto',
))
24 changes: 13 additions & 11 deletions src/python/grpcio/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ def _get_grpc_custom_bdist(decorated_basename, target_bdist_basename):
with open(bdist_path, 'w') as bdist_file:
bdist_file.write(bdist_data)
except IOError as error:
raise CommandError('{}\n\nCould not write grpcio bdist: {}'
.format(traceback.format_exc(), error.message))
raise CommandError('{}\n\nCould not write grpcio bdist: {}'.format(
traceback.format_exc(), error.message))
return bdist_path


Expand Down Expand Up @@ -141,7 +141,8 @@ def run(self):
with open(glossary_filepath, 'a') as glossary_filepath:
glossary_filepath.write(API_GLOSSARY)
sphinx.main(
['', os.path.join('doc', 'src'), os.path.join('doc', 'build')])
['', os.path.join('doc', 'src'),
os.path.join('doc', 'build')])


class BuildProjectMetadata(setuptools.Command):
Expand Down Expand Up @@ -189,10 +190,11 @@ def check_and_update_cythonization(extensions):
for source in extension.sources:
base, file_ext = os.path.splitext(source)
if file_ext == '.pyx':
generated_pyx_source = next((base + gen_ext
for gen_ext in ('.c', '.cpp',)
if os.path.isfile(base + gen_ext)),
None)
generated_pyx_source = next(
(base + gen_ext for gen_ext in (
'.c',
'.cpp',
) if os.path.isfile(base + gen_ext)), None)
if generated_pyx_source:
generated_pyx_sources.append(generated_pyx_source)
else:
Expand Down Expand Up @@ -299,10 +301,10 @@ class Gather(setuptools.Command):
"""Command to gather project dependencies."""

description = 'gather dependencies for grpcio'
user_options = [
('test', 't', 'flag indicating to gather test dependencies'),
('install', 'i', 'flag indicating to gather install dependencies')
]
user_options = [('test', 't',
'flag indicating to gather test dependencies'),
('install', 'i',
'flag indicating to gather install dependencies')]

def initialize_options(self):
self.test = False
Expand Down
74 changes: 53 additions & 21 deletions src/python/grpcio/grpc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1376,8 +1376,8 @@ def metadata_call_credentials(metadata_plugin, name=None):
A CallCredentials.
"""
from grpc import _plugin_wrapping # pylint: disable=cyclic-import
return _plugin_wrapping.metadata_plugin_call_credentials(metadata_plugin,
name)
return _plugin_wrapping.metadata_plugin_call_credentials(
metadata_plugin, name)


def access_token_call_credentials(access_token):
Expand Down Expand Up @@ -1631,25 +1631,57 @@ def server(thread_pool,
################################### __all__ #################################

__all__ = (
'FutureTimeoutError', 'FutureCancelledError', 'Future',
'ChannelConnectivity', 'StatusCode', 'RpcError', 'RpcContext', 'Call',
'ChannelCredentials', 'CallCredentials', 'AuthMetadataContext',
'AuthMetadataPluginCallback', 'AuthMetadataPlugin', 'ClientCallDetails',
'ServerCertificateConfiguration', 'ServerCredentials',
'UnaryUnaryMultiCallable', 'UnaryStreamMultiCallable',
'StreamUnaryMultiCallable', 'StreamStreamMultiCallable',
'UnaryUnaryClientInterceptor', 'UnaryStreamClientInterceptor',
'StreamUnaryClientInterceptor', 'StreamStreamClientInterceptor', 'Channel',
'ServicerContext', 'RpcMethodHandler', 'HandlerCallDetails',
'GenericRpcHandler', 'ServiceRpcHandler', 'Server', 'ServerInterceptor',
'unary_unary_rpc_method_handler', 'unary_stream_rpc_method_handler',
'stream_unary_rpc_method_handler', 'stream_stream_rpc_method_handler',
'method_handlers_generic_handler', 'ssl_channel_credentials',
'metadata_call_credentials', 'access_token_call_credentials',
'composite_call_credentials', 'composite_channel_credentials',
'ssl_server_credentials', 'ssl_server_certificate_configuration',
'dynamic_ssl_server_credentials', 'channel_ready_future',
'insecure_channel', 'secure_channel', 'intercept_channel', 'server',)
'FutureTimeoutError',
'FutureCancelledError',
'Future',
'ChannelConnectivity',
'StatusCode',
'RpcError',
'RpcContext',
'Call',
'ChannelCredentials',
'CallCredentials',
'AuthMetadataContext',
'AuthMetadataPluginCallback',
'AuthMetadataPlugin',
'ClientCallDetails',
'ServerCertificateConfiguration',
'ServerCredentials',
'UnaryUnaryMultiCallable',
'UnaryStreamMultiCallable',
'StreamUnaryMultiCallable',
'StreamStreamMultiCallable',
'UnaryUnaryClientInterceptor',
'UnaryStreamClientInterceptor',
'StreamUnaryClientInterceptor',
'StreamStreamClientInterceptor',
'Channel',
'ServicerContext',
'RpcMethodHandler',
'HandlerCallDetails',
'GenericRpcHandler',
'ServiceRpcHandler',
'Server',
'ServerInterceptor',
'unary_unary_rpc_method_handler',
'unary_stream_rpc_method_handler',
'stream_unary_rpc_method_handler',
'stream_stream_rpc_method_handler',
'method_handlers_generic_handler',
'ssl_channel_credentials',
'metadata_call_credentials',
'access_token_call_credentials',
'composite_call_credentials',
'composite_channel_credentials',
'ssl_server_credentials',
'ssl_server_certificate_configuration',
'dynamic_ssl_server_credentials',
'channel_ready_future',
'insecure_channel',
'secure_channel',
'intercept_channel',
'server',
)

############################### Extension Shims ################################

Expand Down
4 changes: 3 additions & 1 deletion src/python/grpcio/grpc/_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def __call__(self, context, callback):
if self._is_jwt:
future = self._pool.submit(
self._credentials.get_access_token,
additional_claims={'aud': context.service_url})
additional_claims={
'aud': context.service_url
})
else:
future = self._pool.submit(self._credentials.get_access_token)
future.add_done_callback(_create_get_token_callback(callback))
Expand Down
Loading

0 comments on commit 87cd994

Please sign in to comment.