in proxy_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 = 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, '
'sys.path: %s',
cls.worker_deps_path, cx_deps_path, working_directory,
DependencyManager.is_in_linux_consumption(),
is_envvar_true("WEBSITE_PLACEHOLDER_MODE"), sys.path)
cls._remove_from_sys_path(cls.worker_deps_path)
cls._add_to_sys_path(cls.worker_deps_path, True)
cls._add_to_sys_path(cls.cx_deps_path, True)
cls._add_to_sys_path(working_directory, False)
logger.info(f'Finished prioritize_customer_dependencies: {sys.path}')