Exemplo n.º 1
0
def get_datacopy_lookup(
    copiers: Iterable[DataCopier] = None,
    available_storage_engines: Set[Type[StorageEngine]] = None,
    available_data_formats: Iterable[DataFormat] = None,
    expected_record_count: int = 10000,
) -> CopyLookup:
    return CopyLookup(
        copiers=copiers or all_data_copiers,
        available_storage_engines=available_storage_engines
        or set(global_registry.all(StorageEngine)),
        available_data_formats=available_data_formats
        or list(global_registry.all(DataFormatBase)),
        expected_record_count=expected_record_count,
    )
Exemplo n.º 2
0
def get_engine_for_scheme(scheme: str) -> Type[RuntimeEngine]:
    # Take first match IN REVERSE ORDER they were added
    # (so an Engine added later - by user perhaps - takes precedence)
    for eng in list(global_registry.all(RuntimeEngine))[::-1]:
        if scheme in eng.schemes:
            return eng
    raise Exception(f"No matching engine for scheme {scheme}")  # TODO
def get_data_format_of_object(obj: Any) -> Optional[DataFormat]:
    maybes = []
    for m in global_registry.all(DataFormatBase):
        if not m.is_python_format():
            continue
        assert issubclass(m, MemoryDataFormatBase)
        try:
            if m.definitely_instance(obj):
                return m
        except NotImplementedError:
            pass
        if m.maybe_instance(obj):
            maybes.append(m)
    if len(maybes) == 1:
        return maybes[0]
    elif len(maybes) > 1:
        return [f for f in core_data_formats_precedence if f in maybes][0]
    return None
Exemplo n.º 4
0
 def from_storage(cls, storage: Storage) -> Runtime:
     for eng in global_registry.all(RuntimeEngine):
         if eng.natural_storage_engine == storage.storage_engine:
             return Runtime(storage.url, eng)
     raise NotImplementedError(f"No matching runtime {storage}")