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

Code before:

            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)

    # Build metadata store

Review comment (suggestion):
We need similar logging for all the connection methods (within `if`).

Also the "connecting" message should go before the connection code (not after)

Code after:

            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)

    # Build databackend
    databackend = build_databackend(cfg, databackend)