From 4375dba31604a552f74af19240d7add43f2b0cc0 Mon Sep 17 00:00:00 2001 From: Gavin Aguiar Date: Thu, 2 Dec 2021 22:28:54 -0600 Subject: [PATCH 1/2] Enable dependency isolation by default for python 3.10 --- azure_functions_worker/constants.py | 2 +- azure_functions_worker/utils/dependency.py | 14 +++---- tests/unittests/test_utilities_dependency.py | 41 ++++++++++---------- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/azure_functions_worker/constants.py b/azure_functions_worker/constants.py index 7f7c32a5e..e1147492a 100644 --- a/azure_functions_worker/constants.py +++ b/azure_functions_worker/constants.py @@ -43,7 +43,7 @@ PYTHON_THREADPOOL_THREAD_COUNT_MAX_37 = 32 PYTHON_ISOLATE_WORKER_DEPENDENCIES_DEFAULT = False -PYTHON_ISOLATE_WORKER_DEPENDENCIES_DEFAULT_39 = False +PYTHON_ISOLATE_WORKER_DEPENDENCIES_DEFAULT_310 = True PYTHON_ENABLE_WORKER_EXTENSIONS_DEFAULT = False PYTHON_ENABLE_WORKER_EXTENSIONS_DEFAULT_39 = True diff --git a/azure_functions_worker/utils/dependency.py b/azure_functions_worker/utils/dependency.py index afdec0d97..8fee4c4c5 100644 --- a/azure_functions_worker/utils/dependency.py +++ b/azure_functions_worker/utils/dependency.py @@ -13,7 +13,7 @@ CONTAINER_NAME, PYTHON_ISOLATE_WORKER_DEPENDENCIES, PYTHON_ISOLATE_WORKER_DEPENDENCIES_DEFAULT, - PYTHON_ISOLATE_WORKER_DEPENDENCIES_DEFAULT_39 + PYTHON_ISOLATE_WORKER_DEPENDENCIES_DEFAULT_310 ) from ..utils.common import is_python_version from ..utils.wrappers import enable_feature_by @@ -76,8 +76,8 @@ def is_in_linux_consumption(cls): @enable_feature_by( flag=PYTHON_ISOLATE_WORKER_DEPENDENCIES, flag_default=( - PYTHON_ISOLATE_WORKER_DEPENDENCIES_DEFAULT_39 if - is_python_version('3.9') else + PYTHON_ISOLATE_WORKER_DEPENDENCIES_DEFAULT_310 if + is_python_version('3.10') else PYTHON_ISOLATE_WORKER_DEPENDENCIES_DEFAULT ) ) @@ -107,8 +107,8 @@ def use_worker_dependencies(cls): @enable_feature_by( flag=PYTHON_ISOLATE_WORKER_DEPENDENCIES, flag_default=( - PYTHON_ISOLATE_WORKER_DEPENDENCIES_DEFAULT_39 if - is_python_version('3.9') else + PYTHON_ISOLATE_WORKER_DEPENDENCIES_DEFAULT_310 if + is_python_version('3.10') else PYTHON_ISOLATE_WORKER_DEPENDENCIES_DEFAULT ) ) @@ -181,8 +181,8 @@ def reload_customer_libraries(cls, cx_working_dir: str): use_new_env = os.getenv(PYTHON_ISOLATE_WORKER_DEPENDENCIES) if use_new_env is None: use_new = ( - PYTHON_ISOLATE_WORKER_DEPENDENCIES_DEFAULT_39 if - is_python_version('3.9') else + PYTHON_ISOLATE_WORKER_DEPENDENCIES_DEFAULT_310 if + is_python_version('3.10') else PYTHON_ISOLATE_WORKER_DEPENDENCIES_DEFAULT ) else: diff --git a/tests/unittests/test_utilities_dependency.py b/tests/unittests/test_utilities_dependency.py index a571a3998..b16aafcd4 100644 --- a/tests/unittests/test_utilities_dependency.py +++ b/tests/unittests/test_utilities_dependency.py @@ -136,7 +136,7 @@ def test_get_cx_deps_path_in_script_root_with_sys_path_linux_py36(self): os.environ['AzureWebJobsScriptRoot'] = '/home/site/wwwroot' result = DependencyManager._get_cx_deps_path() self.assertEqual(result, '/home/site/wwwroot/.python_packages/sites/' - 'lib/python3.6/site-packages/') + 'lib/python3.6/site-packages/') def test_get_cx_deps_path_in_script_root_with_sys_path_linux(self): # Test for Python 3.7+ Azure Environment @@ -145,7 +145,7 @@ def test_get_cx_deps_path_in_script_root_with_sys_path_linux(self): os.environ['AzureWebJobsScriptRoot'] = '/home/site/wwwroot' result = DependencyManager._get_cx_deps_path() self.assertEqual(result, '/home/site/wwwroot/.python_packages/sites/' - 'lib/site-packages/') + 'lib/site-packages/') def test_get_cx_deps_path_in_script_root_with_sys_path_windows(self): # Test for Windows Core Tools Environment @@ -523,9 +523,6 @@ def test_clear_path_importer_cache_and_modules_retain_namespace(self): os.path.join(self._worker_deps_path, 'common_module') ) - @unittest.skip( - 'This feature is not ready due to azure. namespace not found bugs.' - ) def test_use_worker_dependencies(self): # Setup app settings os.environ['PYTHON_ISOLATE_WORKER_DEPENDENCIES'] = 'true' @@ -558,11 +555,11 @@ def test_use_worker_dependencies_disable(self): import common_module # NoQA @unittest.skipUnless( - sys.version_info.major == 3 and sys.version_info.minor in (6, 7, 8), - 'Test only available for Python 3.6, 3.7, or 3.8' + sys.version_info.major == 3 and sys.version_info.minor in (6, 7, 8, 9), + 'Test only available for Python 3.6, 3.7, 3.8 or 3.9' ) - def test_use_worker_dependencies_default_python_36_37_38(self): - # Feature should be disabled in Python 3.6, 3.7, and 3.8 + def test_use_worker_dependencies_default_python_36_37_38_39(self): + # Feature should be disabled in Python 3.6, 3.7, 3.8 and 3.9 # Setup paths DependencyManager.worker_deps_path = self._worker_deps_path DependencyManager.cx_deps_path = self._customer_deps_path @@ -573,11 +570,12 @@ def test_use_worker_dependencies_default_python_36_37_38(self): with self.assertRaises(ImportError): import common_module # NoQA - @unittest.skip( - 'This feature is not ready due to azure. namespace not found bugs.' + @unittest.skipUnless( + sys.version_info.major == 3 and sys.version_info.minor == 10, + 'Test only available for python 3.10' ) - def test_use_worker_dependencies_default_python_39(self): - # Feature should be enabled in Python 3.9 by default + def test_use_worker_dependencies_default_python_310(self): + # Feature should be enabled in Python 3.10 by default # Setup paths DependencyManager.worker_deps_path = self._worker_deps_path DependencyManager.cx_deps_path = self._customer_deps_path @@ -630,11 +628,11 @@ def test_prioritize_customer_dependencies_disable(self): import common_module # NoQA @unittest.skipIf( - sys.version_info.major == 3 and sys.version_info.minor in (6, 7, 8), - 'Test only available for Python 3.6, 3.7, or 3.8' + sys.version_info.major == 3 and sys.version_info.minor == 10, + 'Test not available for python 3.10' ) - def test_prioritize_customer_dependencies_default_python_36_37_38(self): - # Feature should be disabled in Python 3.6, 3.7, and 3.8 + def test_prioritize_customer_dependencies_default_python_36_37_38_39(self): + # Feature should be disabled in Python 3.6, 3.7, 3.8 and 3.9 # Setup paths DependencyManager.worker_deps_path = self._worker_deps_path DependencyManager.cx_deps_path = self._customer_deps_path @@ -645,11 +643,12 @@ def test_prioritize_customer_dependencies_default_python_36_37_38(self): with self.assertRaises(ImportError): import common_module # NoQA - @unittest.skip( - 'This feature is not ready due to azure. namespace not found bugs.' + @unittest.skipUnless( + sys.version_info.major == 3 and sys.version_info.minor == 10, + 'Test only available for python 3.10' ) - def test_prioritize_customer_dependencies_default_python_39(self): - # Feature should be enabled in Python 3.9 by default + def test_prioritize_customer_dependencies_default_python_310(self): + # Feature should be enabled in Python 3.10 by default # Setup paths DependencyManager.worker_deps_path = self._worker_deps_path DependencyManager.cx_deps_path = self._customer_deps_path From 39d16841adde5b9bb70bfa9eeb4b808abbb98ec0 Mon Sep 17 00:00:00 2001 From: Gavin Aguiar Date: Tue, 7 Dec 2021 17:01:02 -0600 Subject: [PATCH 2/2] Simplified condition to run unit test --- tests/unittests/test_utilities_dependency.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unittests/test_utilities_dependency.py b/tests/unittests/test_utilities_dependency.py index b16aafcd4..59fb7a6b6 100644 --- a/tests/unittests/test_utilities_dependency.py +++ b/tests/unittests/test_utilities_dependency.py @@ -555,7 +555,7 @@ def test_use_worker_dependencies_disable(self): import common_module # NoQA @unittest.skipUnless( - sys.version_info.major == 3 and sys.version_info.minor in (6, 7, 8, 9), + sys.version_info.major == 3 and sys.version_info.minor != 10, 'Test only available for Python 3.6, 3.7, 3.8 or 3.9' ) def test_use_worker_dependencies_default_python_36_37_38_39(self):