コード例 #1
0
ファイル: capture.py プロジェクト: pytask-dev/pytask
def pytask_parse_config(
    config: dict[str, Any],
    config_from_cli: dict[str, Any],
    config_from_file: dict[str, Any],
) -> None:
    """Parse configuration.

    Note that, ``-s`` is a shortcut for ``--capture=no``.

    """
    if config_from_cli.get("s"):
        config["capture"] = _CaptureMethod.NO
    else:
        config["capture"] = get_first_non_none_value(
            config_from_cli,
            config_from_file,
            key="capture",
            default=_CaptureMethod.FD,
            callback=parse_click_choice("capture", _CaptureMethod),
        )

    config["show_capture"] = get_first_non_none_value(
        config_from_cli,
        config_from_file,
        key="show_capture",
        default=ShowCapture.ALL,
        callback=parse_click_choice("show_capture", ShowCapture),
    )
コード例 #2
0
def pytask_parse_config(
    config: dict[str, Any],
    config_from_file: dict[str, Any],
    config_from_cli: dict[str, Any],
) -> None:
    """Parse configuration."""
    config["show_locals"] = get_first_non_none_value(
        config_from_cli,
        config_from_file,
        key="show_locals",
        default=False,
        callback=convert_truthy_or_falsy_to_bool,
    )
    config["editor_url_scheme"] = get_first_non_none_value(
        config_from_cli,
        config_from_file,
        key="editor_url_scheme",
        default="file",
        callback=lambda x: None if x in [None, "none", "None"] else str(x),
    )
    if config["editor_url_scheme"] not in ["no_link", "file"
                                           ] and IS_WINDOWS_TERMINAL:
        config["editor_url_scheme"] = "file"
        warnings.warn(
            "Windows Terminal does not support url schemes to applications, yet."
            "See https://github.com/pytask-dev/pytask/issues/171 for more information. "
            "Resort to `editor_url_scheme='file'`.")
    config["show_traceback"] = get_first_non_none_value(
        config_from_cli,
        config_from_file,
        key="show_traceback",
        default=True,
        callback=convert_truthy_or_falsy_to_bool,
    )
コード例 #3
0
def pytask_parse_config(
    config: dict[str, Any],
    config_from_cli: dict[str, Any],
    config_from_file: dict[str, Any],
) -> None:
    """Parse the configuration."""
    config["pdb"] = get_first_non_none_value(
        config_from_cli,
        key="pdb",
        default=False,
        callback=convert_truthy_or_falsy_to_bool,
    )
    config["trace"] = get_first_non_none_value(
        config_from_cli,
        key="trace",
        default=False,
        callback=convert_truthy_or_falsy_to_bool,
    )
    config["pdbcls"] = get_first_non_none_value(
        config_from_cli,
        config_from_file,
        key="pdbcls",
        default=None,
        callback=_pdbcls_callback,
    )
    config["show_locals"] = get_first_non_none_value(
        config_from_cli,
        config_from_file,
        key="show_locals",
        default=False,
        callback=convert_truthy_or_falsy_to_bool,
    )
コード例 #4
0
def pytask_parse_config(
    config: dict[str, Any],
    config_from_cli: dict[str, Any],
    config_from_file: dict[str, Any],
) -> None:
    """Parse configuration."""
    config["output_path"] = get_first_non_none_value(
        config_from_cli,
        config_from_file,
        key="output_path",
        default=Path.cwd() / "dag.pdf",
        callback=lambda x: None if x is None else Path(x),
    )
    config["layout"] = get_first_non_none_value(
        config_from_cli,
        config_from_file,
        key="layout",
        default="dot",
    )
    config["rank_direction"] = get_first_non_none_value(
        config_from_cli,
        config_from_file,
        key="rank_direction",
        default=_RankDirection.TB,
        callback=parse_click_choice("rank_direction", _RankDirection),
    )
コード例 #5
0
def pytask_parse_config(config, config_from_cli, config_from_file):
    """Register the r marker."""
    config["markers"]["stata"] = "Tasks which are executed with Stata."
    config["platform"] = sys.platform

    if config_from_file.get("stata"):
        config["stata"] = config_from_file["stata"]
    else:
        config["stata"] = next(
            (executable
             for executable in STATA_COMMANDS if shutil.which(executable)),
            None,
        )

    config["stata_keep_log"] = get_first_non_none_value(
        config_from_cli,
        config_from_file,
        key="stata_keep_log",
        callback=convert_truthy_or_falsy_to_bool,
        default=False,
    )

    config["stata_check_log_lines"] = get_first_non_none_value(
        config_from_cli,
        config_from_file,
        key="stata_check_log_lines",
        callback=_nonnegative_nonzero_integer,
        default=10,
    )

    config["stata_source_key"] = config_from_file.get("stata_source_key",
                                                      "source")
コード例 #6
0
ファイル: config.py プロジェクト: pytask-dev/pytask-parallel
def pytask_parse_config(config, config_from_cli, config_from_file):
    """Parse the configuration."""
    config["n_workers"] = get_first_non_none_value(
        config_from_cli,
        config_from_file,
        key="n_workers",
        default=1,
        callback=n_workers_callback,
    )
    if config["n_workers"] == "auto":
        config["n_workers"] = max(os.cpu_count() - 1, 1)

    config["delay"] = get_first_non_none_value(
        config_from_cli,
        config_from_file,
        key="delay",
        default=0.1,
        callback=delay_callback,
    )

    config["parallel_backend"] = get_first_non_none_value(
        config_from_cli,
        config_from_file,
        key="parallel_backend",
        default=PARALLEL_BACKENDS_DEFAULT,
        callback=parallel_backend_callback,
    )
コード例 #7
0
ファイル: profile.py プロジェクト: pytask-dev/pytask
def pytask_parse_config(
    config: dict[str, Any], config_from_cli: dict[str, Any]
) -> None:
    """Parse the configuration."""
    config["export"] = get_first_non_none_value(
        config_from_cli,
        key="export",
        default=_ExportFormats.NO,
        callback=parse_click_choice("export", _ExportFormats),
    )
コード例 #8
0
ファイル: live.py プロジェクト: pytask-dev/pytask
def pytask_parse_config(
    config: dict[str, Any],
    config_from_cli: dict[str, Any],
    config_from_file: dict[str, Any],
) -> None:
    """Parse the configuration."""
    config["n_entries_in_table"] = get_first_non_none_value(
        config_from_cli,
        config_from_file,
        key="n_entries_in_table",
        default=15,
        callback=_parse_n_entries_in_table,
    )
コード例 #9
0
ファイル: execute.py プロジェクト: pytask-dev/pytask
def pytask_parse_config(
    config: dict[str, Any],
    config_from_cli: dict[str, Any],
    config_from_file: dict[str, Any],
) -> None:
    """Parse the configuration."""
    config["show_errors_immediately"] = get_first_non_none_value(
        config_from_cli,
        config_from_file,
        key="show_errors_immediately",
        default=False,
        callback=lambda x: x if x is None else bool(x),
    )
コード例 #10
0
ファイル: clean.py プロジェクト: pytask-dev/pytask
def pytask_parse_config(
    config: dict[str, Any],
    config_from_cli: dict[str, Any],
    config_from_file: dict[str, Any],
) -> None:
    """Parse the configuration."""
    config["directories"] = config_from_cli.get("directories", False)
    cli_excludes = parse_value_or_multiline_option(
        config_from_cli.get("exclude"))
    file_excludes = parse_value_or_multiline_option(
        config_from_file.get("exclude"))
    config["exclude"] = (to_list(cli_excludes or []) +
                         to_list(file_excludes or []) + _DEFAULT_EXCLUDE)
    config["mode"] = config_from_cli.get("mode", "dry-run")
    config["quiet"] = get_first_non_none_value(config_from_cli,
                                               key="quiet",
                                               default=False)
コード例 #11
0
def pytask_parse_config(
    config: dict[str, Any],
    config_from_cli: dict[str, Any],
    config_from_file: dict[str, Any],
) -> None:
    """Parse marker related options."""
    markers = _read_marker_mapping(config_from_file.get("markers", {}))
    config["markers"] = {**markers, **config["markers"]}
    config["strict_markers"] = get_first_non_none_value(
        config,
        config_from_file,
        config_from_cli,
        key="strict_markers",
        default=False,
        callback=convert_truthy_or_falsy_to_bool,
    )

    config["expression"] = config_from_cli.get("expression")
    config["marker_expression"] = config_from_cli.get("marker_expression")

    MARK_GEN.config = config
コード例 #12
0
ファイル: config.py プロジェクト: pytask-dev/pytask
def pytask_configure(pm: pluggy.PluginManager,
                     config_from_cli: dict[str, Any]) -> dict[str, Any]:
    """Configure pytask."""
    config = {"pm": pm}

    # Either the path to the configuration is passed via the CLI or it needs to be
    # detected from the paths passed to pytask.
    if config_from_cli.get("config"):
        config["config"] = Path(config_from_cli["config"])
        config["root"] = config["config"].parent
    else:
        paths = (parse_paths(config_from_cli.get("paths"))
                 if config_from_cli.get("paths") is not None else [Path.cwd()])
        config["root"], config["config"] = _find_project_root_and_config(paths)

    if config["config"] is None:
        config_from_file = {}
    else:
        read_config = get_config_reader(config["config"])
        config_from_file = read_config(config["config"])

        if read_config.__name__ == "_read_ini_config":
            toml_string = "# Content of pyproject.toml\n\n" + tomli_w.dumps(
                {"tool": {
                    "pytask": {
                        "ini_options": config_from_file
                    }
                }})
            console.print(
                Text(
                    _DEPRECATION_MESSAGE.format(
                        config["config"].with_name("pyproject.toml")),
                    style="warning",
                ))
            console.print(Syntax(toml_string, "toml"))

    # If paths are set in the configuration, process them.
    if config_from_file.get("paths"):
        paths_from_file = to_list(
            parse_value_or_multiline_option(config_from_file.get("paths")))
        config_from_file["paths"] = [
            config["config"].parent.joinpath(p).resolve()
            for p in paths_from_file
        ]

    config["paths"] = get_first_non_none_value(
        config_from_cli,
        config_from_file,
        key="paths",
        default=[Path.cwd()],
        callback=parse_paths,
    )

    config["markers"] = {
        "depends_on":
        ("Add dependencies to a task. See this tutorial for more information: "
         "[link https://bit.ly/3JlxylS]https://bit.ly/3JlxylS[/]."),
        "produces":
        ("Add products to a task. See this tutorial for more information: "
         "[link https://bit.ly/3JlxylS]https://bit.ly/3JlxylS[/]."),
        "try_first":
        "Try to execute a task a early as possible.",
        "try_last":
        "Try to execute a task a late as possible.",
    }

    pm.hook.pytask_parse_config(
        config=config,
        config_from_cli=config_from_cli,
        config_from_file=config_from_file,
    )

    pm.hook.pytask_post_parse(config=config)

    return config
コード例 #13
0
ファイル: config.py プロジェクト: pytask-dev/pytask
def pytask_parse_config(
    config: dict[str, Any],
    config_from_cli: dict[str, Any],
    config_from_file: dict[str, Any],
) -> None:
    """Parse the configuration."""
    config["command"] = config_from_cli.get("command", "build")

    config_from_file["ignore"] = parse_value_or_multiline_option(
        config_from_file.get("ignore"))
    config["ignore"] = (to_list(
        get_first_non_none_value(
            config_from_cli,
            config_from_file,
            key="ignore",
            default=[],
        )) + _IGNORED_FILES_AND_FOLDERS + IGNORED_TEMPORARY_FILES_AND_FOLDERS)

    config["debug_pytask"] = get_first_non_none_value(
        config_from_cli,
        config_from_file,
        key="debug_pytask",
        default=False,
        callback=convert_truthy_or_falsy_to_bool,
    )
    if config["debug_pytask"]:
        config["pm"].trace.root.setwriter(print)  # noqa: T202
        config["pm"].enable_tracing()

    config_from_file["task_files"] = parse_value_or_multiline_option(
        config_from_file.get("task_files"))
    config["task_files"] = to_list(
        get_first_non_none_value(config_from_file,
                                 key="task_files",
                                 default="task_*.py"))

    config["stop_after_first_failure"] = get_first_non_none_value(
        config_from_cli,
        config_from_file,
        key="stop_after_first_failure",
        default=False,
        callback=convert_truthy_or_falsy_to_bool,
    )
    if config["stop_after_first_failure"]:
        config["max_failures"] = 1
    else:
        config["max_failures"] = get_first_non_none_value(
            config_from_cli,
            config_from_file,
            key="max_failures",
            default=float("inf"),
            callback=lambda x: x if x is None else int(x),
        )

    config["check_casing_of_paths"] = get_first_non_none_value(
        config_from_cli,
        config_from_file,
        key="check_casing_of_paths",
        default=True,
        callback=convert_truthy_or_falsy_to_bool,
    )

    config["verbose"] = get_first_non_none_value(
        config_from_cli,
        config_from_file,
        key="verbose",
        default=1,
        callback=lambda x: x if x is None else int(x),
    )

    config["sort_table"] = convert_truthy_or_falsy_to_bool(
        config_from_file.get("sort_table", True))