Exemplo n.º 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(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
Exemplo n.º 2
0
def _get_loadable_targets(python_file, module_name):
    if python_file:
        return loadable_targets_from_python_file(python_file)
    elif module_name:
        return loadable_targets_from_python_module(module_name)
    else:
        check.failed('invalid')
Exemplo n.º 3
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")
Exemplo n.º 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"