예제 #1
0
def test_local_directory_module():
    # this is testing that modules that *can* be resolved using the current working directory
    # for local python modules instead of installed packages will succeed.

    # pytest will insert the current directory onto the path when the current directory does is not
    # a module
    assert not os.path.exists(file_relative_path(__file__, "__init__.py"))
    assert os.path.dirname(__file__) in sys.path

    if "autodiscover_in_module" in sys.modules:
        del sys.modules["autodiscover_in_module"]

    with pytest.raises(DagsterImportError):
        loadable_targets_from_python_module(
            "complete_bogus_module",
            working_directory=os.path.dirname(__file__),
            remove_from_path_fn=_current_test_directory_paths,
        )

    with pytest.raises(DagsterImportError):
        loadable_targets_from_python_module(
            "autodiscover_in_module",
            working_directory=None,
            remove_from_path_fn=_current_test_directory_paths,
        )

    loadable_targets = loadable_targets_from_python_module(
        "autodiscover_in_module",
        working_directory=os.path.dirname(__file__),
        remove_from_path_fn=_current_test_directory_paths,
    )
    assert len(loadable_targets) == 1
예제 #2
0
def test_local_directory_module():
    # this is testing that modules that *can* be resolved using the current working directory
    # for local python modules instead of installed packages will succeed.

    # pytest will insert the current directory onto the path when the current directory does is not
    # a module
    assert not os.path.exists(file_relative_path(__file__, "__init__.py"))
    assert os.path.dirname(__file__) in sys.path

    if "autodiscover_in_module" in sys.modules:
        del sys.modules["autodiscover_in_module"]

    with pytest.raises(ImportError):
        loadable_targets_from_python_module(
            "complete_bogus_module", remove_from_path_fn=_current_test_directory_paths
        )

    with pytest.warns(
        UserWarning,
        match=re.escape(
            "Module autodiscover_in_module was resolved using the working directory. The ability "
            "to load uninstalled modules from the working directory is deprecated and will be "
            "removed in a future release.  Please use the python-file based load arguments or "
            "install autodiscover_in_module to your python environment."
        ),
    ):
        loadable_targets = loadable_targets_from_python_module(
            "autodiscover_in_module", remove_from_path_fn=_current_test_directory_paths
        )
    assert len(loadable_targets) == 1
예제 #3
0
파일: utils.py 프로젝트: trevenrawr/dagster
def get_loadable_targets(python_file, module_name, package_name,
                         working_directory,
                         attribute) -> Sequence["LoadableTarget"]:
    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")
예제 #4
0
def test_single_repository_in_module():
    loadable_targets = loadable_targets_from_python_module(
        "dagster.utils.test.toys.single_repository"
    )
    assert len(loadable_targets) == 1
    symbol = loadable_targets[0].attribute
    assert symbol == "single_repository"

    repo_def = CodePointer.from_module(
        "dagster.utils.test.toys.single_repository", symbol
    ).load_target()
    isinstance(repo_def, RepositoryDefinition)
    assert repo_def.name == "single_repository"