in azure_functions_worker/utils/dependency.py [0:0]
def prioritize_customer_dependencies(cls, cx_working_dir=None):
"""Switch the sys.path and ensure the customer's code import are loaded
from CX's deppendencies.
This will not affect already imported namespaces, but will clear out
the module cache and ensure the upcoming modules are loaded from
customer's dependency path.
As for Linux Consumption, this will only remove worker_deps_path,
but the customer's path will be loaded in function_environment_reload.
The search order of a module name in customer's paths is:
1. cx_deps_path
2. worker_deps_path
3. cx_working_dir
"""
# Try to get the latest customer's working directory
# cx_working_dir => cls.cx_working_dir => AzureWebJobsScriptRoot
working_directory: str = ''
if cx_working_dir:
working_directory: str = os.path.abspath(cx_working_dir)
if not working_directory:
working_directory = cls.cx_working_dir
if not working_directory:
working_directory = os.getenv(AZURE_WEBJOBS_SCRIPT_ROOT, '')
# Try to get the latest customer's dependency path
cx_deps_path: str = cls._get_cx_deps_path()
if not cx_deps_path:
cx_deps_path = cls.cx_deps_path
logger.info(
'Applying prioritize_customer_dependencies: '
'worker_dependencies_path: %s, customer_dependencies_path: %s, '
'working_directory: %s, Linux Consumption: %s, Placeholder: %s',
cls.worker_deps_path, cx_deps_path, working_directory,
DependencyManager.is_in_linux_consumption(),
is_envvar_true("WEBSITE_PLACEHOLDER_MODE"))
cls._remove_from_sys_path(cls.worker_deps_path)
cls._add_to_sys_path(cls.cx_deps_path, True)
# Deprioritize worker dependencies but don't completely remove it
# Otherwise, it will break some really old function apps, those
# don't have azure-functions module in .python_packages
# https://github.com/Azure/azure-functions-core-tools/pull/1498
cls._add_to_sys_path(cls.worker_deps_path, False)
# The modules defined in customer's working directory should have the
# least priority since we uses the new folder structure.
# Please check the "Message to customer" section in the following PR:
# https://github.com/Azure/azure-functions-python-worker/pull/726
cls._add_to_sys_path(working_directory, False)
logger.info('Finished prioritize_customer_dependencies')