From cdade7c450e2b0a57cda924014879e42b3295a2b Mon Sep 17 00:00:00 2001 From: Lidi Zheng Date: Wed, 15 Jan 2020 11:04:58 -0800 Subject: [PATCH] Clean-up loggers and imports in Cython --- .../grpcio/grpc/_cython/_cygrpc/aio/call.pyx.pxi | 3 --- .../grpc/_cython/_cygrpc/aio/callback_common.pxd.pxi | 2 -- .../grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi | 2 -- .../grpcio/grpc/_cython/_cygrpc/arguments.pyx.pxi | 2 -- src/python/grpcio/grpc/_cython/_cygrpc/call.pyx.pxi | 2 -- .../grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi | 4 ---- .../grpc/_cython/_cygrpc/completion_queue.pyx.pxi | 4 ---- .../grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi | 5 ----- .../grpcio/grpc/_cython/_cygrpc/fork_posix.pyx.pxi | 5 ----- .../grpcio/grpc/_cython/_cygrpc/fork_windows.pyx.pxi | 2 -- .../grpcio/grpc/_cython/_cygrpc/grpc_gevent.pyx.pxi | 1 - .../grpcio/grpc/_cython/_cygrpc/grpc_string.pyx.pxi | 3 --- src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi | 8 -------- src/python/grpcio/grpc/_cython/cygrpc.pxd | 2 ++ src/python/grpcio/grpc/_cython/cygrpc.pyx | 11 ++++++++++- 15 files changed, 12 insertions(+), 44 deletions(-) diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pyx.pxi index 64f89bb5575..20f7b13d084 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/aio/call.pyx.pxi @@ -12,9 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -cimport cpython -import grpc - _EMPTY_FLAGS = 0 _EMPTY_MASK = 0 diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/aio/callback_common.pxd.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/aio/callback_common.pxd.pxi index e48d48385b7..e99f78a18af 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/aio/callback_common.pxd.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/aio/callback_common.pxd.pxi @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -cimport cpython - cdef class CallbackFailureHandler: cdef str _core_function_name diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi index 5e0108464a5..5b3b98cd162 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi @@ -17,8 +17,6 @@ import inspect import traceback -# TODO(https://github.com/grpc/grpc/issues/20850) refactor this. -_LOGGER = logging.getLogger(__name__) cdef int _EMPTY_FLAG = 0 diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/arguments.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/arguments.pyx.pxi index e121ea60395..9df308cdbcd 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/arguments.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/arguments.pyx.pxi @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -cimport cpython - cdef class _GrpcArgWrapper: diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/call.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/call.pyx.pxi index 6e4574af8d5..bdd155bea94 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/call.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/call.pyx.pxi @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -cimport cpython - cdef class Call: diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi index c31ca14fc89..01baa5288ef 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi @@ -12,10 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -cimport cpython - -import threading -import time _INTERNAL_CALL_ERROR_MESSAGE_FORMAT = ( 'Internal gRPC call error %d. ' + diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi index 325e72afa0a..a47403ac51c 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi @@ -12,10 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -cimport cpython - -import threading -import time cdef int _INTERRUPT_CHECK_PERIOD_MS = 200 diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi index 3da31bbb275..3cbf09c04ba 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi @@ -12,11 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -cimport cpython - -import grpc -import threading - def _spawn_callback_in_thread(cb_func, args): ForkManagedThread(target=cb_func, args=args).start() diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/fork_posix.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/fork_posix.pyx.pxi index b294a55903b..55c8673dd4d 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/fork_posix.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/fork_posix.pyx.pxi @@ -12,11 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import logging -import os -import threading - -_LOGGER = logging.getLogger(__name__) _AWAIT_THREADS_TIMEOUT_SECONDS = 5 diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/fork_windows.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/fork_windows.pyx.pxi index 8dc1ef3b1ad..9167cb45173 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/fork_windows.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/fork_windows.pyx.pxi @@ -13,8 +13,6 @@ # limitations under the License. -import threading - # No-op implementations for Windows. def fork_handlers_and_grpc_init(): diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/grpc_gevent.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/grpc_gevent.pyx.pxi index 1f59cfd159d..05e185ddd47 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/grpc_gevent.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/grpc_gevent.pyx.pxi @@ -13,7 +13,6 @@ # limitations under the License. # distutils: language=c++ -cimport cpython from libc cimport string import errno gevent_g = None diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/grpc_string.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/grpc_string.pyx.pxi index 9621f9b59a2..14925b0dae9 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/grpc_string.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/grpc_string.pyx.pxi @@ -12,9 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import logging - -_LOGGER = logging.getLogger(__name__) # This function will ascii encode unicode string inputs if necessary. # In Python3, unicode strings are the default str type. diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi index 4ce554d078f..a3be6bae479 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi @@ -12,14 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -cimport cpython - -import logging -import time -import grpc - -_LOGGER = logging.getLogger(__name__) - cdef class Server: diff --git a/src/python/grpcio/grpc/_cython/cygrpc.pxd b/src/python/grpcio/grpc/_cython/cygrpc.pxd index 0ffd586104e..5fd77e03eae 100644 --- a/src/python/grpcio/grpc/_cython/cygrpc.pxd +++ b/src/python/grpcio/grpc/_cython/cygrpc.pxd @@ -13,6 +13,8 @@ # limitations under the License. # distutils: language=c++ +cimport cpython + include "_cygrpc/grpc.pxi" include "_cygrpc/arguments.pxd.pxi" diff --git a/src/python/grpcio/grpc/_cython/cygrpc.pyx b/src/python/grpcio/grpc/_cython/cygrpc.pyx index 09f2bfef42c..2e6401b01d1 100644 --- a/src/python/grpcio/grpc/_cython/cygrpc.pyx +++ b/src/python/grpcio/grpc/_cython/cygrpc.pyx @@ -15,8 +15,14 @@ cimport cpython -import os.path +import logging +import os import sys +import threading +import time + +import grpc + try: import asyncio except ImportError: @@ -25,6 +31,9 @@ except ImportError: # Asyncio package is not available we just skip it. pass +# The only copy of Python logger for the Cython extension +_LOGGER = logging.getLogger(__name__) + # TODO(atash): figure out why the coverage tool gets confused about the Cython # coverage plugin when the following files don't have a '.pxi' suffix. include "_cygrpc/grpc_string.pyx.pxi"