def prepare_source()

in src/databao_context_engine/project/datasource_discovery.py [0:0]


def prepare_source(datasource: DatasourceDescriptor) -> PreparedDatasource:
    """
    Convert a discovered datasource into a prepared datasource ready for plugin execution
    """
    if datasource.kind is DatasourceKind.FILE:
        file_subtype = datasource.path.suffix.lower().lstrip(".")
        return PreparedFile(
            datasource_type=DatasourceType.from_main_and_subtypes(main_type=datasource.main_type, subtype=file_subtype),
            path=datasource.path,
        )

    else:
        config = _parse_config_file(datasource.path)

        subtype = config.get("type")
        if not subtype or not isinstance(subtype, str):
            raise ValueError("Config missing 'type' at %s - skipping", datasource.path)

        return PreparedConfig(
            datasource_type=DatasourceType.from_main_and_subtypes(main_type=datasource.main_type, subtype=subtype),
            path=datasource.path,
            config=config,
            datasource_name=datasource.path.stem,
        )