Exemple #1
0
    def from_dict(cls, d: Dict[str, Any]) -> "DbtCliOutput":
        """Constructs an instance of :class:`DbtCliOutput <dagster_dbt.DbtCliOutput>` from a
        dictionary.

        Args:
            d (Dict[str, Any]): A dictionary with key-values to construct a :class:`DbtCliOutput
                <dagster_dbt.DbtCliOutput>`.

        Returns:
            DbtCliOutput: An instance of :class:`DbtCliOutput <dagster_dbt.DbtCliOutput>`.
        """
        return_code = check.int_elem(d, "return_code")
        raw_output = check.str_elem(d, "raw_output")
        num_pass = check.opt_int_elem(d, "num_pass")
        num_warn = check.opt_int_elem(d, "num_warn")
        num_error = check.opt_int_elem(d, "num_error")
        num_skip = check.opt_int_elem(d, "num_skip")
        num_total = check.opt_int_elem(d, "num_total")
        command = check.str_elem(d, "command")

        return cls(
            result=DbtResult.from_dict(d),
            return_code=return_code,
            raw_output=raw_output,
            num_pass=num_pass,
            num_warn=num_warn,
            num_error=num_error,
            num_skip=num_skip,
            num_total=num_total,
            command=command,
        )
Exemple #2
0
    def from_dict(cls, d: Dict[str, Any]) -> "DbtCliOutput":
        """Constructs an instance of :class:`DbtCliOutput <dagster_dbt.DbtCliOutput>` from a
        dictionary.

        Args:
            d (Dict[str, Any]): A dictionary with key-values to construct a :class:`DbtCliOutput
                <dagster_dbt.DbtCliOutput>`.

        Returns:
            DbtCliOutput: An instance of :class:`DbtCliOutput <dagster_dbt.DbtCliOutput>`.
        """
        check.int_elem(d, "return_code")
        check.str_elem(d, "raw_output")
        check.opt_int_elem(d, "num_pass")
        check.opt_int_elem(d, "num_warn")
        check.opt_int_elem(d, "num_error")
        check.opt_int_elem(d, "num_skip")
        check.opt_int_elem(d, "num_total")

        d["result"] = DbtResult.from_dict(d)

        return cls(**d)
Exemple #3
0
def test_int_elem():
    ddict = {"a_bool": True, "a_float": 1.0, "a_int": 1, "a_none": None, "a_str": "a"}

    assert check.int_elem(ddict, "a_int") == 1

    assert check.int_elem(ddict, "a_bool") == True

    with pytest.raises(ElementCheckError):
        check.int_elem(ddict, "a_float")

    with pytest.raises(ElementCheckError):
        check.int_elem(ddict, "a_none")

    with pytest.raises(ElementCheckError):
        check.int_elem(ddict, "a_str")
Exemple #4
0
def get_workspace_load_target(kwargs: Dict[str, str]):
    check.dict_param(kwargs, "kwargs")
    if are_all_keys_empty(kwargs, WORKSPACE_CLI_ARGS):
        if kwargs.get("empty_workspace"):
            return EmptyWorkspaceTarget()
        if os.path.exists("workspace.yaml"):
            return WorkspaceFileTarget(paths=["workspace.yaml"])
        raise click.UsageError(
            "No arguments given and workspace.yaml not found.")

    if kwargs.get("workspace"):
        _check_cli_arguments_none(
            kwargs,
            "python_file",
            "working_directory",
            "module_name",
            "package_name",
            "attribute",
            "grpc_host",
            "grpc_port",
            "grpc_socket",
        )
        return WorkspaceFileTarget(
            paths=list(cast(Union[List, Tuple], kwargs.get("workspace"))))
    if kwargs.get("python_file"):
        _check_cli_arguments_none(
            kwargs,
            "module_name",
            "package_name",
            "grpc_host",
            "grpc_port",
            "grpc_socket",
        )
        working_directory = get_working_directory_from_kwargs(kwargs)
        return PythonFileTarget(
            python_file=check.str_elem(kwargs, "python_file"),
            attribute=check.opt_str_elem(kwargs, "attribute"),
            working_directory=working_directory,
            location_name=None,
        )
    if kwargs.get("module_name"):
        _check_cli_arguments_none(
            kwargs,
            "package_name",
            "grpc_host",
            "grpc_port",
            "grpc_socket",
        )
        working_directory = get_working_directory_from_kwargs(kwargs)
        return ModuleTarget(
            module_name=check.str_elem(kwargs, "module_name"),
            attribute=check.opt_str_elem(kwargs, "attribute"),
            working_directory=working_directory,
            location_name=None,
        )
    if kwargs.get("package_name"):
        _check_cli_arguments_none(
            kwargs,
            "grpc_host",
            "grpc_port",
            "grpc_socket",
        )
        working_directory = get_working_directory_from_kwargs(kwargs)
        return PackageTarget(
            package_name=check.str_elem(kwargs, "package_name"),
            attribute=check.opt_str_elem(kwargs, "attribute"),
            working_directory=working_directory,
            location_name=None,
        )
    if kwargs.get("grpc_port"):
        _check_cli_arguments_none(
            kwargs,
            "attribute",
            "working_directory",
            "grpc_socket",
        )
        return GrpcServerTarget(
            port=check.int_elem(kwargs, "grpc_port"),
            socket=None,
            host=check.opt_str_elem(kwargs, "grpc_host") or "localhost",
            location_name=None,
        )
    elif kwargs.get("grpc_socket"):
        _check_cli_arguments_none(
            kwargs,
            "attribute",
            "working_directory",
        )
        return GrpcServerTarget(
            port=None,
            socket=check.str_elem(kwargs, "grpc_socket"),
            host=check.opt_str_elem(kwargs, "grpc_host") or "localhost",
            location_name=None,
        )
    else:
        _cli_load_invariant(False)
        # necessary for pyright, does not understand _cli_load_invariant(False) never returns
        assert False