Skip to content

Commit 1ce6f51

Browse files
author
Victoria Hall
committed
formatting fixes
1 parent af36a6e commit 1ce6f51

File tree

6 files changed

+35
-27
lines changed

6 files changed

+35
-27
lines changed

azure_functions_worker/dispatcher.py

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def get_sync_tp_workers_set(self):
140140
"""We don't know the exact value of the threadcount set for the Python
141141
3.9 scenarios (as we'll start passing only None by default), and we
142142
need to get that information.
143+
143144
Ref: concurrent.futures.thread.ThreadPoolExecutor.__init__._max_workers
144145
"""
145146
return self._sync_call_tp._max_workers
@@ -193,19 +194,19 @@ async def dispatch_forever(self): # sourcery skip: swap-if-expression
193194

194195
root_logger.setLevel(log_level)
195196
root_logger.addHandler(logging_handler)
196-
logger.info("Switched to gRPC logging.")
197+
logger.info('Switched to gRPC logging.')
197198
logging_handler.flush()
198199

199200
try:
200201
await forever
201202
finally:
202-
logger.warning("Detaching gRPC logging due to exception.")
203+
logger.warning('Detaching gRPC logging due to exception.')
203204
logging_handler.flush()
204205
root_logger.removeHandler(logging_handler)
205206

206207
# Reenable console logging when there's an exception
207208
enable_console_logging()
208-
logger.warning("Switched to console logging due to exception.")
209+
logger.warning('Switched to console logging due to exception.')
209210
finally:
210211
DispatcherMeta.__current_dispatcher__ = None
211212

@@ -235,12 +236,12 @@ def on_logging(self, record: logging.LogRecord,
235236
elif record.levelno >= logging.DEBUG:
236237
log_level = protos.RpcLog.Debug
237238
else:
238-
log_level = getattr(protos.RpcLog, "None")
239+
log_level = getattr(protos.RpcLog, 'None')
239240

240241
if is_system_log_category(record.name):
241-
log_category = protos.RpcLog.RpcLogCategory.Value("System")
242+
log_category = protos.RpcLog.RpcLogCategory.Value('System')
242243
else: # customers using logging will yield 'root' in record.name
243-
log_category = protos.RpcLog.RpcLogCategory.Value("User")
244+
log_category = protos.RpcLog.RpcLogCategory.Value('User')
244245

245246
log = dict(
246247
level=log_level,
@@ -251,7 +252,7 @@ def on_logging(self, record: logging.LogRecord,
251252

252253
invocation_id = get_current_invocation_id()
253254
if invocation_id is not None:
254-
log["invocation_id"] = invocation_id
255+
log['invocation_id'] = invocation_id
255256

256257
self._grpc_resp_queue.put_nowait(
257258
protos.StreamingMessage(
@@ -270,21 +271,21 @@ def worker_id(self) -> str:
270271
@staticmethod
271272
def _serialize_exception(exc: Exception):
272273
try:
273-
message = f"{type(exc).__name__}: {exc}"
274+
message = f'{type(exc).__name__}: {exc}'
274275
except Exception:
275276
message = ('Unhandled exception in function. '
276277
'Could not serialize original exception message.')
277278

278279
try:
279280
stack_trace = marshall_exception_trace(exc)
280281
except Exception:
281-
stack_trace = ""
282+
stack_trace = ''
282283

283284
return protos.RpcException(message=message, stack_trace=stack_trace)
284285

285286
async def _dispatch_grpc_request(self, request):
286-
content_type = request.WhichOneof("content")
287-
request_handler = getattr(self, f"_handle__{content_type}", None)
287+
content_type = request.WhichOneof('content')
288+
request_handler = getattr(self, f'_handle__{content_type}', None)
288289
if request_handler is None:
289290
# Don't crash on unknown messages. Some of them can be ignored;
290291
# and if something goes really wrong the host can always just
@@ -356,16 +357,16 @@ def update_opentelemetry_status(self):
356357
async def _handle__worker_init_request(self, request):
357358
worker_init_request = request.worker_init_request
358359
config_manager.set_config(
359-
os.path.join(worker_init_request.function_app_directory, "az-config.json")
360+
os.path.join(worker_init_request.function_app_directory, 'az-config.json')
360361
)
361362
logger.info(
362-
"Received WorkerInitRequest, "
363-
"python version %s, "
364-
"worker version %s, "
365-
"request ID %s. "
366-
"App Settings state: %s. "
367-
"To enable debug level logging, please refer to "
368-
"https://aka.ms/python-enable-debug-logging",
363+
'Received WorkerInitRequest, '
364+
'python version %s, '
365+
'worker version %s, '
366+
'request ID %s. '
367+
'App Settings state: %s. '
368+
'To enable debug level logging, please refer to '
369+
'https://aka.ms/python-enable-debug-logging',
369370
sys.version,
370371
VERSION,
371372
self.request_id,
@@ -441,7 +442,7 @@ def load_function_metadata(self, function_app_directory, caller_info):
441442
"""
442443
script_file_name = config_manager.get_app_setting(
443444
setting=PYTHON_SCRIPT_FILE_NAME,
444-
default_value=f"{PYTHON_SCRIPT_FILE_NAME_DEFAULT}")
445+
default_value=f'{PYTHON_SCRIPT_FILE_NAME_DEFAULT}')
445446

446447
logger.debug(
447448
'Received load metadata request from %s, request ID %s, '
@@ -469,7 +470,7 @@ async def _handle__functions_metadata_request(self, request):
469470
script_file_name)
470471

471472
logger.info(
472-
"Received WorkerMetadataRequest, request ID %s, " "function_path: %s",
473+
'Received WorkerMetadataRequest, request ID %s, ' 'function_path: %s',
473474
self.request_id,
474475
function_path,
475476
)
@@ -659,7 +660,7 @@ async def _handle__invocation_request(self, request):
659660
# for a customer's threads
660661
fi_context.thread_local_storage.invocation_id = invocation_id
661662
if fi.requires_context:
662-
args["context"] = fi_context
663+
args['context'] = fi_context
663664

664665
if fi.output_types:
665666
for name in fi.output_types:
@@ -767,7 +768,7 @@ async def _handle__function_environment_reload_request(self, request):
767768
os.environ[var] = env_vars[var]
768769
config_manager.set_config(
769770
os.path.join(
770-
func_env_reload_request.function_app_directory, "az-config.json"
771+
func_env_reload_request.function_app_directory, 'az-config.json'
771772
)
772773
)
773774

@@ -799,7 +800,8 @@ async def _handle__function_environment_reload_request(self, request):
799800
if config_manager.is_envvar_true(PYTHON_ENABLE_INIT_INDEXING):
800801
try:
801802
self.load_function_metadata(
802-
directory, caller_info="environment_reload_request")
803+
directory,
804+
caller_info="environment_reload_request")
803805

804806
if HttpV2Registry.http_v2_enabled():
805807
capabilities[HTTP_URI] = \
@@ -819,7 +821,8 @@ async def _handle__function_environment_reload_request(self, request):
819821
success_response = protos.FunctionEnvironmentReloadResponse(
820822
capabilities=capabilities,
821823
worker_metadata=self.get_worker_metadata(),
822-
result=protos.StatusResult(status=protos.StatusResult.Success))
824+
result=protos.StatusResult(
825+
status=protos.StatusResult.Success))
823826

824827
return protos.StreamingMessage(
825828
request_id=self.request_id,
@@ -855,7 +858,7 @@ def index_functions(self, function_path: str, function_dir: str):
855858
func_binding_logs = fx_bindings_logs.get(func)
856859
for binding in func.get_bindings():
857860
deferred_binding_info = func_binding_logs.get(
858-
binding.name) \
861+
binding.name)\
859862
if func_binding_logs.get(binding.name) else ""
860863
indexed_function_bindings_logs.append((
861864
binding.type, binding.name, deferred_binding_info))

azure_functions_worker/logging.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
SDK_LOG_PREFIX = "azure.functions"
1414
SYSTEM_ERROR_LOG_PREFIX = "azure_functions_worker_errors"
1515

16+
1617
logger: logging.Logger = logging.getLogger(SYSTEM_LOG_PREFIX)
1718
error_logger: logging.Logger = (
1819
logging.getLogger(SYSTEM_ERROR_LOG_PREFIX))

tests/unittests/test_dispatcher.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ class TestDispatcherStein(testutils.AsyncTestCase):
598598
def setUp(self):
599599
self._ctrl = testutils.start_mockhost(
600600
script_root=DISPATCHER_STEIN_FUNCTIONS_DIR)
601+
config_manager.clear_config()
601602

602603
async def test_dispatcher_functions_metadata_request(self):
603604
"""Test if the functions metadata response will be sent correctly

tests/unittests/test_extension.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def setUp(self):
8080

8181
def tearDown(self) -> None:
8282
os.environ.pop(PYTHON_ENABLE_WORKER_EXTENSIONS)
83+
8384
self.mock_sys_path.stop()
8485
self.mock_sys_module.stop()
8586
self.mock_environ.stop()

tests/unittests/test_script_file_name.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33
import os
4+
45
from tests.utils import testutils
56

67
from azure_functions_worker.constants import (

tests/unittests/test_utilities_dependency.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
import unittest
77
from unittest.mock import patch
88

9+
from tests.utils import testutils
10+
911
from azure_functions_worker.utils.dependency import DependencyManager
1012
from azure_functions_worker.utils.config_manager import config_manager
11-
from tests.utils import testutils
1213

1314

1415
class TestDependencyManager(unittest.TestCase):

0 commit comments

Comments
 (0)