Пример #1
0
def load_class(project, config_key):
    path = project.config.get(config_key)
    modname, clsname = path.rsplit('.', maxsplit=1)
    mod = import_module_from_modname(modname)
    cls = getattr(mod, clsname)
    logger.debug('Loaded class {} from {}'
                 .format(cls.__name__, mod.__path__))
    return cls
Пример #2
0
def _get_project(package_slug, project_path):
    if package_slug is not None:
        package = import_module_from_modname(package_slug)
        return Project(package)
    elif project_path is not None:
        return Project.from_path(project_path)
    else:
        return Project.from_cwd()
Пример #3
0
def _load_class(project, config_key):
    path = project.config.get(config_key)
    modname, clsname = path.rsplit('.', maxsplit=1)
    mod = import_module_from_modname(modname)
    cls = getattr(mod, clsname)

    clsname = getattr(cls, '__name__', '<unknown>')
    modfile = getattr(mod, '__file__', '<unknown>')
    logger.debug('Loaded class {} from {}'.format(clsname, modfile))

    return cls
Пример #4
0
def load_spec(spec: Union[str, dict]) -> Tuple[type, dict]:
    if isinstance(spec, str):
        path = spec
        params = {}
    else:
        path = spec['name']
        params = spec.get('params', {})
    modname, clsname = path.rsplit('.', maxsplit=1)
    mod = import_module_from_modname(modname)
    cls = getattr(mod, clsname)
    modfile = getattr(mod, '__file__', '<unknown>')
    logger.debug(f'Loaded class {clsname} from module at {modfile} '
                 f'with params {params}')
    return cls, params
Пример #5
0
 def from_import():
     module_name, scorer_name = self.name.rsplit('.', maxsplit=1)
     mod = import_module_from_modname(module_name)
     return getattr(mod, scorer_name)