"""Import util functions.""" import importlib from dim_refresh_etl import flows class FlowImportError(Exception): """Flow class import error.""" pass def import_workflow_class(workflow_name): """Import workflow class by name. Args: workflow_name (str): Name of the imported flow. Namely one of the `flows` package. Returns: type: Imported flow class. Raises: FlowImportError: If flow module wasn't found or the module doesn't contain Flow class. """ try: module = importlib.import_module( '.{}.flow'.format(workflow_name), flows.__name__) flow_class = module.Flow return flow_class except ImportError as e: raise FlowImportError( "{} flow wasn't imported. Error: {}".format(workflow_name, str(e))) except AttributeError: raise FlowImportError( "Implementation of {} flow wasn't found.".format(workflow_name))