Skip to content

Add exception handler factory class loading and warn of missing dependecies  #4

@sambles

Description

@sambles

Issue Description

Set base package requirements only imports needed for the default reader and storage class (local / pandas).
For the optional imports, dask and object store libs, add a check in the class loading calls and warn if a class load fails due to missing dependency.

def get_df_reader(config, *args, **kwargs):
config = clean_config(config)
cls = load_class(config["engine"]["path"], OasisReader)
storage = config["engine"]["options"].pop("storage", None) or LocalStorage("/")
return cls(
config["filepath"], storage, *args, **kwargs, **config["engine"]["options"]
)

def get_storage_from_config(config: StorageConfig):
cls = load_class(config["storage_class"], BaseStorage)
return cls(**config["options"])
def get_storage_from_config_path(config_path: Optional[str], fallback_path: str):
"""
Loads the config from the supplied path. If no config path is provided or the path
doesn't exist a local file store object will be created with the root set to the
fallback path.
:param config_path: The path to the config file to load
:param fallback_path: The path for the local file store should the config path not exist
"""
if config_path and os.path.exists(config_path):
with open(config_path) as f:
config: StorageConfig = json.load(f)
model_storage = get_storage_from_config(config)
elif fallback_path:
model_storage = LocalStorage(
root_dir=fallback_path,
)
else:
raise ConfigError(
"The given config path does not exist and no fallback path was given to create the local storage from"
)
return model_storage

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions