from pathlib import Path
import importlib
import inspect


def create_init_line_library(module_path: str, lib_name: str) -> str:
    """Creates an __init__ entry of the library dir for the corresponding metadatablocks file"""

    # Get the module name from file
    module_name = Path(module_path).stem

    # Import package to inspect it
    module = importlib.import_module(module_name)

    # Get the class that will be part of the init
    for class_name, _ in inspect.getmembers(module, inspect.isclass):

        if class_name.lower() == module_name.lower():
            return (
                f"from {lib_name}.metadatablocks import {class_name}"
            )

    raise ModuleNotFoundError(
        f"Could not find module '{module_name}' in generated modules."
    )