Skip to content
This repository was archived by the owner on Feb 26, 2026. It is now read-only.

Commit 9ee7bae

Browse files
committed
linting
1 parent d725eff commit 9ee7bae

File tree

8 files changed

+56
-38
lines changed

8 files changed

+56
-38
lines changed

google/cloud/logging_v2/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def __init__(
148148
self._use_grpc = _USE_GRPC
149149
else:
150150
self._use_grpc = _use_grpc
151-
151+
152152
self._handlers = set()
153153

154154
@property

google/cloud/logging_v2/handlers/handlers.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,10 @@ def emit(self, record):
216216

217217
# send off request
218218
if self.transport is None:
219-
self.transport = self._transport_cls(self.client, self.name, resource=self.resource)
220-
219+
self.transport = self._transport_cls(
220+
self.client, self.name, resource=self.resource
221+
)
222+
221223
self.transport.send(
222224
record,
223225
message,
@@ -238,13 +240,13 @@ def flush(self):
238240
super(CloudLoggingHandler, self).flush()
239241
if self.transport is not None:
240242
self.transport.flush()
241-
243+
242244
def close(self):
243-
"""Closes the log handler and cleans up all Transport objects used.
244-
"""
245+
"""Closes the log handler and cleans up all Transport objects used."""
245246
self.transport.close()
246247
self.transport = None
247248

249+
248250
def _format_and_parse_message(record, formatter_handler):
249251
"""
250252
Helper function to apply formatting to a LogRecord message,

google/cloud/logging_v2/handlers/transports/background_thread.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@
3838
_WORKER_TERMINATOR = object()
3939
_LOGGER = logging.getLogger(__name__)
4040

41-
_CLOSE_THREAD_SHUTDOWN_ERROR_MSG = "CloudLoggingHandler shutting down, cannot send logs entries to Cloud Logging due to " \
42-
"inconsistent threading behavior at shutdown. To avoid this issue, flush the logging handler " \
41+
_CLOSE_THREAD_SHUTDOWN_ERROR_MSG = (
42+
"CloudLoggingHandler shutting down, cannot send logs entries to Cloud Logging due to "
43+
"inconsistent threading behavior at shutdown. To avoid this issue, flush the logging handler "
4344
"manually or switch to StructuredLogHandler."
45+
)
4446

4547

4648
def _get_many(queue_, *, max_items=None, max_latency=0):
@@ -212,7 +214,7 @@ def _close(self):
212214
"""Callback that attempts to send pending logs before termination."""
213215
if not self.is_alive:
214216
return
215-
217+
216218
# Print different messages to the user depending on whether or not the
217219
# program is shutting down. This is because this function now handles both
218220
# the atexit handler and the regular close.
@@ -224,16 +226,22 @@ def _close(self):
224226
file=sys.stderr,
225227
)
226228
else:
227-
print(_CLOSE_THREAD_SHUTDOWN_ERROR_MSG,file=sys.stderr,)
229+
print(
230+
_CLOSE_THREAD_SHUTDOWN_ERROR_MSG,
231+
file=sys.stderr,
232+
)
228233

229-
if self.stop(grace_period=self._grace_period) and threading.main_thread().is_alive():
234+
if (
235+
self.stop(grace_period=self._grace_period)
236+
and threading.main_thread().is_alive()
237+
):
230238
print("Sent all pending logs.", file=sys.stderr)
231239
else:
232240
print(
233241
"Failed to send %d pending logs." % (self._queue.qsize(),),
234242
file=sys.stderr,
235243
)
236-
244+
237245
self._thread = None
238246

239247
def enqueue(self, record, message, **kwargs):
@@ -267,12 +275,13 @@ def flush(self):
267275

268276
def close(self):
269277
"""Signals the worker thread to stop, then closes the transport thread.
270-
278+
271279
This call should be followed up by disowning the transport object.
272280
"""
273281
atexit.unregister(self._close)
274282
self._close()
275283

284+
276285
class BackgroundThreadTransport(Transport):
277286
"""Asynchronous transport that uses a background thread."""
278287

@@ -332,4 +341,4 @@ def flush(self):
332341

333342
def close(self):
334343
"""Closes the worker thread."""
335-
self.worker.stop(grace_period=self.grace_period)
344+
self.worker.stop(grace_period=self.grace_period)

google/cloud/logging_v2/handlers/transports/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ def close(self):
5858
5959
This call should be followed up by disowning the transport.
6060
"""
61-
pass
61+
pass

google/cloud/logging_v2/handlers/transports/sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ def close(self):
6565
6666
This call is usually followed up by cleaning up the reference to the transport.
6767
"""
68-
self.logger = None
68+
self.logger = None

tests/unit/handlers/test_handlers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ def test_emit_with_encoded_json(self):
800800
None,
801801
),
802802
)
803-
803+
804804
def test_emit_after_close(self):
805805
from google.cloud.logging_v2.logger import _GLOBAL_RESOURCE
806806

@@ -885,7 +885,7 @@ def test_format_with_arguments(self):
885885
None,
886886
),
887887
)
888-
888+
889889
def test_close(self):
890890
from google.cloud.logging_v2.logger import _GLOBAL_RESOURCE
891891

@@ -1234,6 +1234,6 @@ def send(
12341234
http_request,
12351235
source_location,
12361236
)
1237-
1237+
12381238
def close(self):
12391239
self.close_called = True

tests/unit/handlers/transports/test_background_thread.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ class Test_Worker(unittest.TestCase):
182182

183183
def setUp(self):
184184
import sys
185+
185186
print("In method", self._testMethodName, file=sys.stderr)
186187

187188
@staticmethod
@@ -197,14 +198,16 @@ def _start_with_thread_patch(self, worker):
197198
with mock.patch("threading.Thread", new=_Thread) as thread_mock:
198199
worker.start()
199200
return thread_mock
200-
201+
201202
@staticmethod
202203
@contextlib.contextmanager
203204
def _init_atexit_mock():
204205
atexit_mock = _AtexitMock()
205-
with mock.patch.multiple("atexit", register=atexit_mock.register, unregister=atexit_mock.unregister):
206+
with mock.patch.multiple(
207+
"atexit", register=atexit_mock.register, unregister=atexit_mock.unregister
208+
):
206209
yield atexit_mock
207-
210+
208211
@staticmethod
209212
@contextlib.contextmanager
210213
def _init_main_thread_is_alive_mock(is_alive):
@@ -214,7 +217,6 @@ def _init_main_thread_is_alive_mock(is_alive):
214217
main_thread_obj_mock.is_alive = mock.Mock(return_value=is_alive)
215218
yield
216219

217-
218220
def test_constructor(self):
219221
logger = _Logger(self.NAME)
220222
grace_period = 50
@@ -320,7 +322,10 @@ def test__close_did_not_join(self):
320322
self.assertFalse(worker.is_alive)
321323

322324
def test__close_main_thread_not_alive(self):
323-
from google.cloud.logging_v2.handlers.transports.background_thread import _CLOSE_THREAD_SHUTDOWN_ERROR_MSG
325+
from google.cloud.logging_v2.handlers.transports.background_thread import (
326+
_CLOSE_THREAD_SHUTDOWN_ERROR_MSG,
327+
)
328+
324329
worker = self._make_one(_Logger(self.NAME))
325330

326331
with mock.patch("sys.stderr", new_callable=StringIO) as stderr_mock:
@@ -329,8 +334,11 @@ def test__close_main_thread_not_alive(self):
329334
self._start_with_thread_patch(worker)
330335
self._enqueue_record(worker, "test")
331336
worker._close()
332-
333-
self.assertRegex(stderr_mock.getvalue(), re.compile("^%s$" % _CLOSE_THREAD_SHUTDOWN_ERROR_MSG, re.MULTILINE))
337+
338+
self.assertRegex(
339+
stderr_mock.getvalue(),
340+
re.compile("^%s$" % _CLOSE_THREAD_SHUTDOWN_ERROR_MSG, re.MULTILINE),
341+
)
334342

335343
def test_close_unregister_atexit(self):
336344
worker = self._make_one(_Logger(self.NAME))
@@ -341,7 +349,6 @@ def test_close_unregister_atexit(self):
341349
worker.close()
342350
self.assertNotIn(worker._close, atexit_mock.registered_funcs)
343351

344-
345352
@staticmethod
346353
def _enqueue_record(worker, message, levelno=logging.INFO, **kw):
347354
record = logging.LogRecord("testing", levelno, None, None, message, None, None)
@@ -464,7 +471,7 @@ def test__thread_main_main_thread_terminated(self):
464471
self._enqueue_record(worker, "1")
465472
self._enqueue_record(worker, "2")
466473
worker._thread_main()
467-
474+
468475
self.assertFalse(worker._cloud_logger._batch.commit_called)
469476

470477
@mock.patch("time.time", autospec=True, return_value=1)
@@ -635,9 +642,9 @@ def logger(self, name, resource=None): # pylint: disable=unused-argument
635642
class _AtexitMock(object):
636643
def __init__(self):
637644
self.registered_funcs = set()
638-
645+
639646
def register(self, func):
640647
self.registered_funcs.add(func)
641-
648+
642649
def unregister(self, func):
643-
self.registered_funcs.remove(func)
650+
self.registered_funcs.remove(func)

tests/unit/test_client.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ def test_setup_logging_w_extra_kwargs_structured_log(self):
932932
}
933933
self.assertEqual(kwargs, expected_kwargs)
934934
self.assertIn(handler, client._handlers)
935-
935+
936936
def test_flush_handlers_cloud_logging_handler(self):
937937
import io
938938
from google.cloud.logging.handlers import CloudLoggingHandler
@@ -958,11 +958,11 @@ def test_flush_handlers_cloud_logging_handler(self):
958958

959959
(handler,) = args
960960
self.assertIsInstance(handler, CloudLoggingHandler)
961-
961+
962962
handler.flush = mock.Mock()
963963
client.flush_handlers()
964964
handler.flush.assert_called_once_with()
965-
965+
966966
def test_flush_handlers_cloud_logging_handler_no_setup_logging(self):
967967
from google.cloud.logging.handlers import CloudLoggingHandler
968968

@@ -973,7 +973,7 @@ def test_flush_handlers_cloud_logging_handler_no_setup_logging(self):
973973

974974
handler = CloudLoggingHandler(client)
975975
self.assertIn(handler, client._handlers)
976-
976+
977977
handler.flush = mock.Mock()
978978
client.flush_handlers()
979979
handler.flush.assert_called_once_with()
@@ -1035,7 +1035,7 @@ def test_close_cloud_logging_handler(self):
10351035

10361036
(handler,) = args
10371037
self.assertIsInstance(handler, CloudLoggingHandler)
1038-
1038+
10391039
handler.close = mock.Mock()
10401040
with contextlib.closing(client):
10411041
pass
@@ -1053,7 +1053,7 @@ def test_close_cloud_logging_handler_no_setup_logging(self):
10531053

10541054
handler = CloudLoggingHandler(client)
10551055
self.assertIn(handler, client._handlers)
1056-
1056+
10571057
handler.close = mock.Mock()
10581058
with contextlib.closing(client):
10591059
pass
@@ -1104,4 +1104,4 @@ def __init__(self, *responses):
11041104
def api_request(self, **kw):
11051105
self._called_with = kw
11061106
response, self._responses = self._responses[0], self._responses[1:]
1107-
return response
1107+
return response

0 commit comments

Comments
 (0)