Repository: SuperDuperDB/superduperdb
File: superduperdb/base/build.py (Python)

Code before:
            assert type == 'metadata'
            from sqlalchemy import create_engine

            sql_conn = create_engine(uri)
            return mapping['sqlalchemy'](sql_conn, name)


def build_compute(compute):
    if compute == 'local' or compute is None:
        return LocalComputeBackend()

    if compute == 'dask+thread':
        from superduperdb.backends.dask.compute import DaskComputeBackend

        return DaskComputeBackend('local', local=True)

    if compute.split('://')[0] == 'dask+tcp':
        from superduperdb.backends.dask.compute import DaskComputeBackend

        uri = compute.split('+')[-1]
        return DaskComputeBackend(uri)

    if compute.split('://')[0] == 'ray':
        return RayComputeBackend(compute)

    return LocalComputeBackend()


def build_datalayer(cfg=None, databackend=None, **kwargs) -> Datalayer:
    """
    Build a Datalayer object as per ``db = superduper(db)`` from configuration.

    :param cfg: Configuration to use. If None, use ``superduperdb.CFG``.
    :param databackend: Databacked to use.
                        If None, use ``superduperdb.CFG.data_backend``.
    """

    # Configuration
    # ------------------------------
    # Use the provided configuration or fall back to the default configuration.
    cfg = cfg or s.CFG

    # Update configuration with keyword arguments.
    for k, v in kwargs.items():
        if '__' in k:
            getattr(cfg, k.split('__')[0]).force_set(k.split('__')[1], v)
        else:
            cfg.force_set(k, v)

    # Build databackend
    databackend = build_databackend(cfg, databackend)

Review comment (suggestion):
The only way to reach this state is to give an invalid URL -- something that is not None, and is not one of the valid conditions.

In this case, you should return an exception.

Code after:
            assert type == 'metadata'
            from sqlalchemy import create_engine

            sql_conn = create_engine(uri)
            return mapping['sqlalchemy'](sql_conn, name)


def build_compute(compute):
    logging.info("Connecting to compute client:", compute)

    if compute == 'local' or compute is None:
        return LocalComputeBackend()

    if compute == 'dask+thread':
        from superduperdb.backends.dask.compute import DaskComputeBackend

        return DaskComputeBackend('local', local=True)

    if compute.split('://')[0] == 'dask+tcp':
        from superduperdb.backends.dask.compute import DaskComputeBackend

        uri = compute.split('+')[-1]
        return DaskComputeBackend(uri)

    if compute.split('://')[0] == 'ray':
        return RayComputeBackend(compute)

    raise ValueError('Compute {compute} is not a valid compute configuration.')


def build_datalayer(cfg=None, databackend=None, **kwargs) -> Datalayer:
    """
    Build a Datalayer object as per ``db = superduper(db)`` from configuration.

    :param cfg: Configuration to use. If None, use ``superduperdb.CFG``.
    :param databackend: Databacked to use.
                        If None, use ``superduperdb.CFG.data_backend``.
    """

    # Configuration
    # ------------------------------
    # Use the provided configuration or fall back to the default configuration.
    cfg = cfg or s.CFG

    # Update configuration with keyword arguments.
    for k, v in kwargs.items():
        if '__' in k:
            getattr(cfg, k.split('__')[0]).force_set(k.split('__')[1], v)
        else:
            cfg.force_set(k, v)