Esempio n. 1
0
def test_local_directory_package():
    # this is testing that modules in a local directory that are NOT installed packages will raise
    # an error, when using the loadable_targets_from_python_package function

    # 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_package(
            "complete_bogus_module",
            remove_from_path_fn=_current_test_directory_paths)

    with pytest.raises(DagsterInvariantViolationError) as exc_info:
        loadable_targets_from_python_package(
            "autodiscover_in_module",
            remove_from_path_fn=_current_test_directory_paths)

    assert str(exc_info.value) == (
        "Module autodiscover_in_module not found. Packages must be installed rather than relying "
        "on the working directory to resolve module loading.")
Esempio n. 2
0
def get_loadable_targets(python_file, module_name, package_name, working_directory, attribute):
    from dagster.cli.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))]
            if attribute
            else loadable_targets_from_python_module(module_name)
        )
    elif package_name:
        return (
            [LoadableTarget(attribute, load_def_in_package(package_name, attribute))]
            if attribute
            else loadable_targets_from_python_package(package_name)
        )
    else:
        check.failed("invalid")
Esempio n. 3
0
def test_single_repository_in_package():
    loadable_targets = loadable_targets_from_python_package(
        "dagster.utils.test.toys.single_repository")
    assert len(loadable_targets) == 1
    symbol = loadable_targets[0].attribute
    assert symbol == "single_repository"

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