def discover_tasks()

in optimum/exporters/executorch/task_registry.py [0:0]


def discover_tasks():
    """
    Dynamically discovers and imports all task modules within the `optimum.exporters.executorch.tasks` package.

    Ensures tasks under `./tasks` directory are dynamically loaded without requiring manual imports.

    Notes:
        New tasks **must** be added to the `./tasks` directory to be discovered and used by `main_export`.
        Failure to do so will prevent dynamic discovery and registration. Tasks must also use the
        `@register_task` decorator to be properly registered in the `task_registry`.
    """
    package = importlib.import_module(package_name)
    package_path = package.__path__

    for _, module_name, _ in pkgutil.iter_modules(package_path):
        logger.info(f"Importing {package_name}.{module_name}")
        importlib.import_module(f"{package_name}.{module_name}")