예제 #1
0
def get_loadable_targets(python_file, module_name, package_name,
                         working_directory, attribute):
    from dagster.core.workspace.autodiscovery import (
        LoadableTarget,
        loadable_targets_from_python_file,
        loadable_targets_from_python_module,
        loadable_targets_from_python_package,
    )

    if python_file:
        return ([
            LoadableTarget(
                attribute,
                load_def_in_python_file(python_file, attribute,
                                        working_directory))
        ] if attribute else loadable_targets_from_python_file(
            python_file, working_directory))
    elif module_name:
        return ([
            LoadableTarget(
                attribute,
                load_def_in_module(module_name, attribute, working_directory))
        ] if attribute else loadable_targets_from_python_module(
            module_name, working_directory))
    elif package_name:
        return ([
            LoadableTarget(
                attribute,
                load_def_in_package(package_name, attribute,
                                    working_directory))
        ] if attribute else loadable_targets_from_python_package(
            package_name, working_directory))
    else:
        check.failed("invalid")
예제 #2
0
파일: server.py 프로젝트: zuodh/dagster
    def __init__(self, shutdown_server_event, loadable_target_origin=None):
        super(DagsterApiServer, self).__init__()

        self._shutdown_server_event = check.inst_param(
            shutdown_server_event, 'shutdown_server_event',
            seven.ThreadingEventType)
        self._loadable_target_origin = check.opt_inst_param(
            loadable_target_origin, 'loadable_target_origin',
            LoadableTargetOrigin)

        if loadable_target_origin:
            from dagster.cli.workspace.autodiscovery import LoadableTarget

            if not loadable_target_origin.attribute:
                loadable_targets = get_loadable_targets(
                    loadable_target_origin.python_file,
                    loadable_target_origin.module_name,
                    loadable_target_origin.working_directory,
                )
            elif loadable_target_origin.python_file:
                loadable_targets = [
                    LoadableTarget(
                        loadable_target_origin.attribute,
                        load_def_in_python_file(
                            loadable_target_origin.python_file,
                            loadable_target_origin.attribute,
                            loadable_target_origin.working_directory,
                        ),
                    )
                ]
            else:
                check.invariant(
                    loadable_target_origin.module_name,
                    'if attribute is set, either a file or module must also be set',
                )
                loadable_targets = [
                    LoadableTarget(
                        loadable_target_origin.attribute,
                        load_def_in_module(
                            loadable_target_origin.module_name,
                            loadable_target_origin.attribute,
                        ),
                    )
                ]

            self._loadable_repository_symbols = [
                LoadableRepositorySymbol(
                    attribute=loadable_target.attribute,
                    repository_name=loadable_target.target_definition.name,
                ) for loadable_target in loadable_targets
            ]
        else:
            self._loadable_repository_symbols = []
예제 #3
0
파일: load.py 프로젝트: zuodh/dagster
def location_handle_from_module_name(module_name,
                                     attribute,
                                     user_process_api,
                                     location_name=None):
    check.str_param(module_name, 'module_name')
    check.opt_str_param(attribute, 'attribute')
    check.inst_param(user_process_api, 'user_process_api', UserProcessApi)
    check.opt_str_param(location_name, 'location_name')

    if user_process_api == UserProcessApi.GRPC:
        return RepositoryLocationHandle.create_process_bound_grpc_server_location(
            LoadableTargetOrigin(
                executable_path=sys.executable,
                python_file=None,
                module_name=module_name,
                working_directory=None,
                attribute=attribute,
            ),
            location_name,
        )

    loadable_targets = ([
        LoadableTarget(attribute, load_def_in_module(module_name, attribute))
    ] if attribute else loadable_targets_from_python_module(module_name))

    repository_code_pointer_dict = {}
    for loadable_target in loadable_targets:
        repository_code_pointer_dict[
            loadable_target.target_definition.name] = CodePointer.from_module(
                module_name, loadable_target.attribute)

    return RepositoryLocationHandle.create_out_of_process_location(
        repository_code_pointer_dict=repository_code_pointer_dict,
        # default to the name of the repository symbol for now
        location_name=assign_location_name(location_name,
                                           repository_code_pointer_dict),
    )