azure_functions_worker/utils/dependency.py [25:91]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class DependencyManager:
    """The dependency manager controls the Python packages source, preventing
    worker packages interfer customer's code.

    It has two mode, in worker mode, the Python packages are loaded from worker
    path, (e.g. workers/python/<python_version>/<os>/<arch>). In customer mode,
    the packages are loaded from customer's .python_packages/ folder or from
    their virtual environment.

    Azure Functions has three different set of sys.path ordering,

    Linux Consumption sys.path: [
        "/tmp/functions\\standby\\wwwroot", # Placeholder folder
        "/home/site/wwwroot/.python_packages/lib/site-packages", # CX's deps
        "/azure-functions-host/workers/python/3.11/LINUX/X64", # Worker's deps
        "/home/site/wwwroot" # CX's Working Directory
    ]

    Linux Dedicated/Premium sys.path: [
        "/home/site/wwwroot", # CX's Working Directory
        "/home/site/wwwroot/.python_packages/lib/site-packages", # CX's deps
        "/azure-functions-host/workers/python/3.11/LINUX/X64", # Worker's deps
    ]

    Core Tools sys.path: [
        "%appdata%\\azure-functions-core-tools\\bin\\workers\\"
            "python\\3.11\\WINDOWS\\X64", # Worker's deps
        "C:\\Users\\user\\Project\\.venv311\\lib\\site-packages", # CX's deps
        "C:\\Users\\user\\Project", # CX's Working Directory
    ]

    When we first start up the Python worker, we should only loaded from
    worker's deps and create module namespace (e.g. google.protobuf variable).

    Once the worker receives worker init request, we clear out the sys.path,
    worker sys.modules cache and sys.path_import_cache so the libraries
    will only get loaded from CX's deps path.
    """

    cx_deps_path: str = ''
    cx_working_dir: str = ''
    worker_deps_path: str = ''

    @classmethod
    def initialize(cls):
        cls.cx_deps_path = cls._get_cx_deps_path()
        cls.cx_working_dir = cls._get_cx_working_dir()
        cls.worker_deps_path = cls._get_worker_deps_path()

    @classmethod
    def is_in_linux_consumption(cls):
        return CONTAINER_NAME in os.environ

    @classmethod
    def should_load_cx_dependencies(cls):
        """
        Customer dependencies should be loaded when dependency
         isolation is enabled and
         1) App is a dedicated app
         2) App is linux consumption but not in placeholder mode.
         This can happen when the worker restarts for any reason
         (OOM, timeouts etc) and env reload request is not called.
        """
        return not (DependencyManager.is_in_linux_consumption()
                    and is_envvar_true("WEBSITE_PLACEHOLDER_MODE"))

    @classmethod
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



proxy_worker/utils/dependency.py [14:79]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class DependencyManager:
    """The dependency manager controls the Python packages source, preventing
    worker packages interfer customer's code.

    It has two mode, in worker mode, the Python packages are loaded from worker
    path, (e.g. workers/python/<python_version>/<os>/<arch>). In customer mode,
    the packages are loaded from customer's .python_packages/ folder or from
    their virtual environment.

    Azure Functions has three different set of sys.path ordering,

    Linux Consumption sys.path: [
        "/tmp/functions\\standby\\wwwroot", # Placeholder folder
        "/home/site/wwwroot/.python_packages/lib/site-packages", # CX's deps
        "/azure-functions-host/workers/python/3.13/LINUX/X64", # Worker's deps
        "/home/site/wwwroot" # CX's Working Directory
    ]

    Linux Dedicated/Premium sys.path: [
        "/home/site/wwwroot", # CX's Working Directory
        "/home/site/wwwroot/.python_packages/lib/site-packages", # CX's deps
        "/azure-functions-host/workers/python/3.13/LINUX/X64", # Worker's deps
    ]

    Core Tools sys.path: [
        "%appdata%\\azure-functions-core-tools\\bin\\workers\\"
            "python\\3.13\\WINDOWS\\X64", # Worker's deps
        "C:\\Users\\user\\Project\\.venv311\\lib\\site-packages", # CX's deps
        "C:\\Users\\user\\Project", # CX's Working Directory
    ]

    When we first start up the Python worker, we should only loaded from
    worker's deps and create module namespace (e.g. google.protobuf variable).

    Once the worker receives worker init request, we clear out the sys.path,
    worker sys.modules cache and sys.path_import_cache so the libraries
    will only get loaded from CX's deps path.
    """

    cx_deps_path: str = ''
    cx_working_dir: str = ''
    worker_deps_path: str = ''

    @classmethod
    def initialize(cls):
        cls.cx_deps_path = cls._get_cx_deps_path()
        cls.cx_working_dir = cls._get_cx_working_dir()
        cls.worker_deps_path = cls._get_worker_deps_path()

    @classmethod
    def is_in_linux_consumption(cls):
        return CONTAINER_NAME in os.environ

    @classmethod
    def should_load_cx_dependencies(cls):
        """
         Customer dependencies should be loaded when
         1) App is a dedicated app
         2) App is linux consumption but not in placeholder mode.
         This can happen when the worker restarts for any reason
         (OOM, timeouts etc) and env reload request is not called.
        """
        return not (DependencyManager.is_in_linux_consumption()
                    and is_envvar_true("WEBSITE_PLACEHOLDER_MODE"))

    @classmethod
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



