Skip to content

Commit af36a6e

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

8 files changed

+251
-359
lines changed

azure_functions_worker/dispatcher.py

Lines changed: 226 additions & 308 deletions
Large diffs are not rendered by default.

azure_functions_worker/utils/app_setting_manager.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@
2020

2121
def get_python_appsetting_state():
2222
current_vars = config_manager.get_config()
23-
python_specific_settings = [
24-
PYTHON_ROLLBACK_CWD_PATH,
25-
PYTHON_THREADPOOL_THREAD_COUNT,
26-
PYTHON_ISOLATE_WORKER_DEPENDENCIES,
27-
PYTHON_ENABLE_DEBUG_LOGGING,
28-
PYTHON_ENABLE_WORKER_EXTENSIONS,
29-
FUNCTIONS_WORKER_SHARED_MEMORY_DATA_TRANSFER_ENABLED,
30-
PYTHON_SCRIPT_FILE_NAME,
31-
PYTHON_ENABLE_INIT_INDEXING,
32-
PYTHON_ENABLE_OPENTELEMETRY,
33-
]
23+
python_specific_settings = \
24+
[PYTHON_ROLLBACK_CWD_PATH,
25+
PYTHON_THREADPOOL_THREAD_COUNT,
26+
PYTHON_ISOLATE_WORKER_DEPENDENCIES,
27+
PYTHON_ENABLE_DEBUG_LOGGING,
28+
PYTHON_ENABLE_WORKER_EXTENSIONS,
29+
FUNCTIONS_WORKER_SHARED_MEMORY_DATA_TRANSFER_ENABLED,
30+
PYTHON_SCRIPT_FILE_NAME,
31+
PYTHON_ENABLE_INIT_INDEXING,
32+
PYTHON_ENABLE_OPENTELEMETRY]
3433

3534
app_setting_states = "".join(
3635
f"{app_setting}: {current_vars[app_setting]} | "
@@ -39,16 +38,14 @@ def get_python_appsetting_state():
3938
)
4039

4140
# Special case for extensions
42-
if "PYTHON_ENABLE_WORKER_EXTENSIONS" not in current_vars:
41+
if 'PYTHON_ENABLE_WORKER_EXTENSIONS' not in current_vars:
4342
if sys.version_info.minor == 9:
44-
app_setting_states += (
45-
f"{PYTHON_ENABLE_WORKER_EXTENSIONS}: "
46-
f"{str(PYTHON_ENABLE_WORKER_EXTENSIONS_DEFAULT_39)}"
47-
)
43+
app_setting_states += \
44+
(f"{PYTHON_ENABLE_WORKER_EXTENSIONS}: "
45+
f"{str(PYTHON_ENABLE_WORKER_EXTENSIONS_DEFAULT_39)}")
4846
else:
49-
app_setting_states += (
50-
f"{PYTHON_ENABLE_WORKER_EXTENSIONS}: "
51-
f"{str(PYTHON_ENABLE_WORKER_EXTENSIONS_DEFAULT)}"
52-
)
47+
app_setting_states += \
48+
(f"{PYTHON_ENABLE_WORKER_EXTENSIONS}: "
49+
f"{str(PYTHON_ENABLE_WORKER_EXTENSIONS_DEFAULT)}")
5350

5451
return app_setting_states

azure_functions_worker/utils/config_manager.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,10 @@ def read_config(self, function_path: str):
3434
except FileNotFoundError:
3535
pass
3636

37-
# updates the config dictionary with the environment variables
38-
# this prioritizes set env variables over the config file
39-
# env_copy = os.environ
40-
# for k, v in env_copy.items():
41-
# self.config_data.update({k.upper(): v})
42-
4337
def set_config(self, function_path: str):
4438
self.read_config(function_path)
4539
self.read_environment_variables()
4640

47-
def config_exists(self) -> bool:
48-
if self.config_data is None:
49-
self.set_config("")
50-
return self.config_data is not None
51-
52-
def get_config(self) -> dict:
53-
return self.config_data
54-
5541
def is_true_like(self, setting: str) -> bool:
5642
if setting is None:
5743
return False
@@ -66,11 +52,6 @@ def is_false_like(self, setting: str) -> bool:
6652

6753
def is_envvar_true(self, key: str) -> bool:
6854
key_upper = key.upper()
69-
# special case for PYTHON_ENABLE_DEBUG_LOGGING
70-
# This is read by the host and must be set in os.environ
71-
if key_upper == "PYTHON_ENABLE_DEBUG_LOGGING":
72-
val = os.getenv(key_upper)
73-
return self.is_true_like(val)
7455
if self.config_exists() and not self.config_data.get(key_upper):
7556
return False
7657
return self.is_true_like(self.config_data.get(key_upper))
@@ -137,5 +118,13 @@ def clear_config(self):
137118
self.config_data.clear()
138119
self.config_data = None
139120

121+
def config_exists(self) -> bool:
122+
if self.config_data is None:
123+
self.set_config("")
124+
return self.config_data is not None
125+
126+
def get_config(self) -> dict:
127+
return self.config_data
128+
140129

141130
config_manager = ConfigManager()

tests/unittests/test_app_setting_manager.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ def setUpClass(cls):
7272
cls._patch_environ = patch.dict('os.environ', os_environ)
7373
cls._patch_environ.start()
7474
super().setUpClass()
75-
config_manager.clear_config()
7675
config_manager.read_environment_variables()
7776

7877
@classmethod

tests/unittests/test_dispatcher.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ async def test_dispatcher_sync_threadpool_set_worker(self):
176176
await self._check_if_function_is_ok(host)
177177
await self._assert_workers_threadpool(self._ctrl, host,
178178
self._allowed_max_workers)
179-
os.environ.pop(PYTHON_THREADPOOL_THREAD_COUNT)
180179

181180
async def test_dispatcher_sync_threadpool_invalid_worker_count(self):
182181
"""Test when sync threadpool maximum worker is set to an invalid value,
@@ -197,7 +196,6 @@ async def test_dispatcher_sync_threadpool_invalid_worker_count(self):
197196
self._default_workers)
198197
mock_logger.warning.assert_any_call(
199198
'%s must be an integer', PYTHON_THREADPOOL_THREAD_COUNT)
200-
os.environ.pop(PYTHON_THREADPOOL_THREAD_COUNT)
201199

202200
async def test_dispatcher_sync_threadpool_below_min_setting(self):
203201
"""Test if the sync threadpool will pick up default value when the
@@ -216,7 +214,6 @@ async def test_dispatcher_sync_threadpool_below_min_setting(self):
216214
'Reverting to default value for max_workers',
217215
PYTHON_THREADPOOL_THREAD_COUNT,
218216
PYTHON_THREADPOOL_THREAD_COUNT_MIN)
219-
os.environ.pop(PYTHON_THREADPOOL_THREAD_COUNT)
220217

221218
async def test_dispatcher_sync_threadpool_exceed_max_setting(self):
222219
"""Test if the sync threadpool will pick up default max value when the
@@ -233,7 +230,6 @@ async def test_dispatcher_sync_threadpool_exceed_max_setting(self):
233230
# Ensure the dispatcher sync threadpool should fallback to max
234231
await self._assert_workers_threadpool(self._ctrl, host,
235232
self._allowed_max_workers)
236-
os.environ.pop(PYTHON_THREADPOOL_THREAD_COUNT)
237233

238234
async def test_dispatcher_sync_threadpool_in_placeholder(self):
239235
"""Test if the sync threadpool will pick up app setting in placeholder
@@ -381,7 +377,6 @@ async def test_sync_invocation_request_log_threads(self):
381377
r'\d{2}:\d{2}:\d{2}.\d{6}), '
382378
'sync threadpool max workers: 5'
383379
)
384-
os.environ.pop(PYTHON_THREADPOOL_THREAD_COUNT)
385380

386381
async def test_async_invocation_request_log_threads(self):
387382
with patch('azure_functions_worker.dispatcher.logger') as mock_logger:
@@ -406,7 +401,6 @@ async def test_async_invocation_request_log_threads(self):
406401
r'(\d{4}-\d{2}-\d{2} '
407402
r'\d{2}:\d{2}:\d{2}.\d{6})'
408403
)
409-
os.environ.pop(PYTHON_THREADPOOL_THREAD_COUNT)
410404

411405
async def test_sync_invocation_request_log_in_placeholder_threads(self):
412406
with patch('azure_functions_worker.dispatcher.logger') as mock_logger:
@@ -604,7 +598,6 @@ class TestDispatcherStein(testutils.AsyncTestCase):
604598
def setUp(self):
605599
self._ctrl = testutils.start_mockhost(
606600
script_root=DISPATCHER_STEIN_FUNCTIONS_DIR)
607-
config_manager.clear_config()
608601

609602
async def test_dispatcher_functions_metadata_request(self):
610603
"""Test if the functions metadata response will be sent correctly
@@ -736,7 +729,6 @@ async def test_dispatcher_load_modules_dedicated_app(self):
736729
"working_directory: , Linux Consumption: False,"
737730
" Placeholder: False", logs
738731
)
739-
os.environ.pop("PYTHON_ISOLATE_WORKER_DEPENDENCIES")
740732

741733
async def test_dispatcher_load_modules_con_placeholder_enabled(self):
742734
"""Test modules are loaded in consumption apps with placeholder mode

tests/unittests/test_extension.py

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

8181
def tearDown(self) -> None:
8282
os.environ.pop(PYTHON_ENABLE_WORKER_EXTENSIONS)
83-
8483
self.mock_sys_path.stop()
8584
self.mock_sys_module.stop()
8685
self.mock_environ.stop()

tests/unittests/test_third_party_http_functions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import pathlib
66
import re
77
import typing
8-
98
from unittest.mock import patch
109

1110
from tests.utils import testutils

tests/unittests/test_utilities.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ def setUp(self):
8383
self.mock_environ.start()
8484
self.mock_sys_module.start()
8585
self.mock_sys_path.start()
86-
config_manager.clear_config()
8786

8887
def tearDown(self):
8988
self.mock_sys_path.stop()

0 commit comments

Comments
 (0)