def _get_worker_deps_path()

in azure_functions_worker/utils/dependency.py [0:0]


    def _get_worker_deps_path() -> str:
        """Get the worker dependency sys.path. This will always available
        even in all skus.

        Returns
        -------
        str
            The worker packages path
        """
        # 1. Try to parse the absolute path python/3.8/LINUX/X64 in sys.path
        r = re.compile(r'.*python(\/|\\)\d+\.\d+(\/|\\)(WINDOWS|LINUX|OSX).*')
        worker_deps_paths: List[str] = [p for p in sys.path if r.match(p)]
        if worker_deps_paths:
            return worker_deps_paths[0]

        # 2. Try to find module spec of azure.functions without actually
        #    importing it (e.g. lib/site-packages/azure/functions/__init__.py)
        try:
            azf_spec = importlib.util.find_spec('azure.functions')
            if azf_spec and azf_spec.origin:
                return os.path.abspath(
                    os.path.join(os.path.dirname(azf_spec.origin), '..', '..')
                )
        except ModuleNotFoundError:
            logger.warning('Cannot locate built-in azure.functions module')

        # 3. If it fails to find one, try to find one from the parent path
        #    This is used for handling the CI/localdev environment
        return os.path.abspath(
            os.path.join(os.path.dirname(__file__), '..', '..')
        )