Skip to content

FetchConfig

FetchConfig

Bases: BaseModel

Configuration for a Benchmarkoor fetch run.

Load from a YAML file with from_yaml; apply CLI overrides with with_cli_overrides. Auth (bearer token) is never part of the config — pass it via BENCHMARKOOR_TOKEN env var, --token CLI flag, or BenchmarkoorClient(token=...).

from_yaml classmethod

from_yaml(path: Path, *, allow_partial: bool = False) -> FetchConfig

Load a FetchConfig from a YAML file.

Parameters:

Name Type Description Default
path Path

Filesystem path to the YAML config file.

required
allow_partial bool

When True, required query fields (network, fork, test_type) may be absent; validation is deferred until with_cli_overrides is called with the missing values.

False

Returns:

Type Description
FetchConfig

A validated FetchConfig instance.

Raises:

Type Description
ValidationError

If the YAML content violates any constraint (unknown keys, type errors, inverted date window, token present in YAML, etc.).

Source code in src/benchmarkoor_fetch/config.py
@classmethod
def from_yaml(cls, path: Path, *, allow_partial: bool = False) -> FetchConfig:
    """Load a `FetchConfig` from a YAML file.

    Args:
        path: Filesystem path to the YAML config file.
        allow_partial: When True, required query fields (network, fork,
            test_type) may be absent; validation is deferred until
            `with_cli_overrides` is called with the missing values.

    Returns:
        A validated `FetchConfig` instance.

    Raises:
        pydantic.ValidationError: If the YAML content violates any
            constraint (unknown keys, type errors, inverted date window,
            token present in YAML, etc.).
    """
    raw: dict = yaml.load(Path(path).read_text(), Loader=_ConfigLoader) or {}

    _raise_token_error(raw)

    if allow_partial:
        return cls._load_partial(raw)
    return cls.model_validate(raw)

with_cli_overrides

with_cli_overrides(**kwargs: object) -> FetchConfig

Return a new FetchConfig with CLI-supplied overrides applied.

Only non-None kwargs are applied; omitting a kwarg leaves the existing value intact. Accepted kwargs: network, fork, test_type, start_date, end_date, run_id_pattern, cache_dir.

Returns:

Type Description
FetchConfig

A new validated FetchConfig; the original is not modified.

Raises:

Type Description
ValidationError

If the merged result is invalid.

Source code in src/benchmarkoor_fetch/config.py
def with_cli_overrides(self, **kwargs: object) -> FetchConfig:
    """Return a new `FetchConfig` with CLI-supplied overrides applied.

    Only non-None kwargs are applied; omitting a kwarg leaves the existing
    value intact. Accepted kwargs: `network`, `fork`, `test_type`,
    `start_date`, `end_date`, `run_id_pattern`, `cache_dir`.

    Returns:
        A new validated `FetchConfig`; the original is not modified.

    Raises:
        pydantic.ValidationError: If the merged result is invalid.
    """
    current_query = self.query
    query_dict: dict[str, object] = {}
    for field in (
        "network",
        "fork",
        "test_type",
        "start_date",
        "end_date",
        "run_id_pattern",
        "suites",
    ):
        val = getattr(current_query, field, None)
        if val is not None:
            query_dict[field] = val

    for key in (
        "network",
        "fork",
        "test_type",
        "start_date",
        "end_date",
        "run_id_pattern",
    ):
        if key in kwargs and kwargs[key] is not None:
            query_dict[key] = kwargs[key]

    cache_dict = self.cache.model_dump()
    if "cache_dir" in kwargs and kwargs["cache_dir"] is not None:
        cache_dict["dir"] = kwargs["cache_dir"]

    merged = {
        "query": query_dict,
        "http": self.http.model_dump(),
        "output": self.output.model_dump(),
        "cache": cache_dict,
    }
    return FetchConfig.model_validate(merged)