示例#1
0
def handle_for_repo_cli_args(kwargs):
    '''Builds an ExecutionTargetHandle for CLI arguments, which can be any of the combinations
    for repo loading above.
    '''
    check.dict_param(kwargs, 'kwargs')

    _cli_load_invariant(kwargs.get('pipeline_name') is None)

    if kwargs.get('repository_yaml') or all_none(kwargs):
        _cli_load_invariant(kwargs.get('module_name') is None)
        _cli_load_invariant(kwargs.get('python_file') is None)
        _cli_load_invariant(kwargs.get('fn_name') is None)
        return ExecutionTargetHandle.for_repo_yaml(
            repository_yaml=kwargs.get('repository_yaml')
            or DEFAULT_REPOSITORY_YAML_FILENAME)
    elif kwargs.get('module_name') and kwargs.get('fn_name'):
        _cli_load_invariant(kwargs.get('repository_yaml') is None)
        _cli_load_invariant(kwargs.get('python_file') is None)
        return ExecutionTargetHandle.for_repo_module(
            module_name=kwargs['module_name'], fn_name=kwargs['fn_name'])
    elif kwargs.get('python_file') and kwargs.get('fn_name'):
        _cli_load_invariant(kwargs.get('repository_yaml') is None)
        _cli_load_invariant(kwargs.get('module_name') is None)
        return ExecutionTargetHandle.for_repo_python_file(
            python_file=kwargs['python_file'], fn_name=kwargs['fn_name'])
    else:
        raise CliUsageError()
示例#2
0
def recon_repo_for_cli_args(kwargs):
    '''Builds a ReconstructableRepository for CLI arguments, which can be any of the combinations
    for repo loading above.
    '''
    check.dict_param(kwargs, 'kwargs')
    _cli_load_invariant(kwargs.get('pipeline_name') is None)

    if kwargs.get('repository_yaml') or all_none(kwargs):
        _cli_load_invariant(kwargs.get('module_name') is None)
        _cli_load_invariant(kwargs.get('python_file') is None)
        _cli_load_invariant(kwargs.get('fn_name') is None)
        repo_yaml = (
            os.path.abspath(kwargs.get('repository_yaml'))
            if kwargs.get('repository_yaml')
            else DEFAULT_REPOSITORY_YAML_FILENAME
        )
        _cli_load_invariant(
            os.path.exists(repo_yaml),
            'Expected to use file "{}" to load repository but it does not exist. '
            'Verify your current working directory or CLI arguments.'.format(repo_yaml),
        )
        return ReconstructableRepository.from_yaml(repo_yaml)
    elif kwargs.get('module_name') and kwargs.get('fn_name'):
        _cli_load_invariant(kwargs.get('repository_yaml') is None)
        _cli_load_invariant(kwargs.get('python_file') is None)
        return ReconstructableRepository.for_module(kwargs['module_name'], kwargs['fn_name'])

    elif kwargs.get('python_file') and kwargs.get('fn_name'):
        _cli_load_invariant(kwargs.get('repository_yaml') is None)
        _cli_load_invariant(kwargs.get('module_name') is None)
        return ReconstructableRepository.for_file(
            os.path.abspath(kwargs['python_file']), kwargs['fn_name']
        )
    else:
        _cli_load_invariant(False)
示例#3
0
def get_register_repo_info(cli_args, allow_none=True):
    scaffolding_with_repo = True
    if all_none(cli_args):
        if os.path.exists(
                os.path.join(os.getcwd(), DEFAULT_REPOSITORY_YAML_FILENAME)):
            cli_args['repository_yaml'] = DEFAULT_REPOSITORY_YAML_FILENAME
        elif allow_none:  # register_repo_info can remain None
            scaffolding_with_repo = False

    if (cli_args['python_file'] and cli_args['fn_name']
            and not cli_args['module_name']
            and not cli_args['repository_yaml']):
        raise click.UsageError(
            "Cannot instantiate notebook with repository definition given by a "
            "function from a file")

    register_repo_info = None
    if scaffolding_with_repo:
        handle = handle_for_repo_cli_args(cli_args)
        module = handle.entrypoint.module_name
        fn_name = handle.entrypoint.fn_name
        RegisterRepoInfo = namedtuple(
            'RegisterRepoInfo', 'import_statement declaration_statement')
        register_repo_info = RegisterRepoInfo(
            "from {module} import {fn_name}".format(module=module,
                                                    fn_name=fn_name),
            "dm.register_repository({fn_name}())".format(fn_name=fn_name),
        )
    return register_repo_info
示例#4
0
def handle_for_repo_cli_args(kwargs):
    '''Builds an ExecutionTargetHandle for CLI arguments, which can be any of the combinations
    for repo loading above.
    '''
    check.dict_param(kwargs, 'kwargs')

    _cli_load_invariant(kwargs.get('pipeline_name') is None)

    if kwargs.get('repository_yaml') or all_none(kwargs):
        _cli_load_invariant(kwargs.get('module_name') is None)
        _cli_load_invariant(kwargs.get('python_file') is None)
        _cli_load_invariant(kwargs.get('fn_name') is None)
        repo_yaml = kwargs.get(
            'repository_yaml') or DEFAULT_REPOSITORY_YAML_FILENAME
        _cli_load_invariant(
            os.path.exists(repo_yaml),
            'Expected to use file "{}" to load repository but it does not exist. '
            'Verify your current working directory or CLI arguments.'.format(
                repo_yaml),
        )
        return ExecutionTargetHandle.for_repo_yaml(repository_yaml=repo_yaml)
    elif kwargs.get('module_name') and kwargs.get('fn_name'):
        _cli_load_invariant(kwargs.get('repository_yaml') is None)
        _cli_load_invariant(kwargs.get('python_file') is None)
        return ExecutionTargetHandle.for_repo_module(
            module_name=kwargs['module_name'], fn_name=kwargs['fn_name'])
    elif kwargs.get('python_file') and kwargs.get('fn_name'):
        _cli_load_invariant(kwargs.get('repository_yaml') is None)
        _cli_load_invariant(kwargs.get('module_name') is None)
        return ExecutionTargetHandle.for_repo_python_file(
            python_file=kwargs['python_file'], fn_name=kwargs['fn_name'])
    else:
        _cli_load_invariant(False)
示例#5
0
def recon_repo_for_cli_args(kwargs):
    """Builds a ReconstructableRepository for CLI arguments, which can be any of the combinations
    for repo loading above.
    """
    check.dict_param(kwargs, "kwargs")
    _cli_load_invariant(kwargs.get("pipeline_name") is None)

    if kwargs.get("workspace"):
        check.not_implemented(
            "Workspace not supported yet in this cli command")

    if kwargs.get("repository_yaml") or all_none(kwargs):
        _cli_load_invariant(kwargs.get("module_name") is None)
        _cli_load_invariant(kwargs.get("python_file") is None)
        _cli_load_invariant(kwargs.get("fn_name") is None)
        repo_yaml = (os.path.abspath(kwargs.get("repository_yaml"))
                     if kwargs.get("repository_yaml") else
                     DEFAULT_REPOSITORY_YAML_FILENAME)
        _cli_load_invariant(
            os.path.exists(repo_yaml),
            'Expected to use file "{}" to load repository but it does not exist. '
            "Verify your current working directory or CLI arguments.".format(
                repo_yaml),
        )
        return ReconstructableRepository.from_legacy_repository_yaml(repo_yaml)
    elif kwargs.get("module_name") and kwargs.get("fn_name"):
        _cli_load_invariant(kwargs.get("repository_yaml") is None)
        _cli_load_invariant(kwargs.get("python_file") is None)
        return ReconstructableRepository.for_module(kwargs["module_name"],
                                                    kwargs["fn_name"])

    elif kwargs.get("python_file") and kwargs.get("fn_name"):
        _cli_load_invariant(kwargs.get("repository_yaml") is None)
        _cli_load_invariant(kwargs.get("module_name") is None)
        return ReconstructableRepository.for_file(
            os.path.abspath(kwargs["python_file"]),
            kwargs["fn_name"],
            kwargs.get("working_directory")
            if kwargs.get("working_directory") else os.getcwd(),
        )
    else:
        _cli_load_invariant(False)