def METHOD_NAME():
    """Determine the current host platform and import the platform factory.
    If the ``TOGA_BACKEND`` environment variable is set, the factory will be loaded
    from that module.
    Raises :any:`RuntimeError` if an appropriate host platform cannot be identified.
    :returns: The factory for the host platform.
    """
    toga_backends = entry_points(group="toga.backends")
    if not toga_backends:
        raise RuntimeError("No Toga backend could be loaded.")
    backend_value = os.environ.get("TOGA_BACKEND")
    if backend_value:
        try:
            factory = importlib.import_module(f"{backend_value}.factory")
        except ModuleNotFoundError as e:
            toga_backends_values = ", ".join(
                [f"{backend.value!r}" for backend in toga_backends]
            )
            # Android doesn't report Python exception chains in crashes
            # (https://github.com/chaquo/chaquopy/issues/890), so include the original
            # exception message in case the backend does exist but throws a
            # ModuleNotFoundError from one of its internal imports.
            raise RuntimeError(
                f"The backend specified by TOGA_BACKEND ({backend_value!r}) could "
                f"not be loaded ({e}). It should be one of: {toga_backends_values}."
            )
    else:
        # As of Setuptools 65.5, entry points are returned duplicated if the
        # package is installed editable. Use a set to ensure that each entry point
        # is only returned once.
        # See https://github.com/pypa/setuptools/issues/3649
        toga_backends = sorted(set(toga_backends))
        if len(toga_backends) == 1:
            backend = toga_backends[0]
        else:
            # multiple backends are installed: choose the one that matches the host platform
            matching_backends = [
                backend for backend in toga_backends if backend.name == current_platform
            ]
            if len(matching_backends) == 0:
                toga_backends_string = ", ".join(
                    [f"{backend.value!r} ({backend.name})" for backend in toga_backends]
                )
                raise RuntimeError(
                    f"Multiple Toga backends are installed ({toga_backends_string}), "
                    f"but none of them match your current platform ({current_platform!r}). "
                    "Install a backend for your current platform, or use "
                    "TOGA_BACKEND to specify a backend."
                )
            if len(matching_backends) > 1:
                toga_backends_string = ", ".join(
                    [
                        f"{backend.value!r} ({backend.name})"
                        for backend in matching_backends
                    ]
                )
                raise RuntimeError(
                    f"Multiple candidate toga backends found: ({toga_backends_string}). "
                    "Uninstall the backends you don't require, or use "
                    "TOGA_BACKEND to specify a backend."
                )
            backend = matching_backends[0]
        factory = importlib.import_module(f"{backend.value}.factory")
    return factory