File size: 2,667 Bytes
0185029
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""Locate OraRL configuration, documentation, and launcher resources."""

from __future__ import annotations

from importlib.metadata import PackageNotFoundError, distribution
from pathlib import Path, PurePosixPath

_RESOURCE_KINDS = frozenset({"configs", "docs", "scripts"})


def _safe_name(name: str) -> str:
    candidate = str(name).strip()
    if not candidate or candidate in {".", ".."} or Path(candidate).name != candidate:
        raise ValueError(f"resource name must be a file name, got {name!r}")
    return candidate


def _source_resource(kind: str, name: str) -> Path | None:
    candidate = Path(__file__).resolve().parent.parent / kind / name
    return candidate if candidate.is_file() else None


def _installed_resource(kind: str, name: str) -> Path | None:
    try:
        package_distribution = distribution("orarl")
    except PackageNotFoundError:
        return None

    suffix = ("share", "orarl", kind, name)
    for entry in package_distribution.files or ():
        parts = PurePosixPath(str(entry)).parts
        if len(parts) >= len(suffix) and tuple(parts[-len(suffix) :]) == suffix:
            candidate = Path(package_distribution.locate_file(entry)).resolve()
            if candidate.is_file():
                return candidate
    return None


def resource_path(kind: str, name: str) -> Path:
    """Return one packaged resource from a source or wheel installation."""

    normalized_kind = str(kind).strip().casefold()
    if normalized_kind not in _RESOURCE_KINDS:
        choices = ", ".join(sorted(_RESOURCE_KINDS))
        raise ValueError(f"resource kind must be one of {{{choices}}}, got {kind!r}")
    normalized_name = _safe_name(name)
    candidate = _source_resource(normalized_kind, normalized_name)
    if candidate is None:
        candidate = _installed_resource(normalized_kind, normalized_name)
    if candidate is None:
        raise FileNotFoundError(
            f"OraRL {normalized_kind} resource was not found: {normalized_name}"
        )
    return candidate


def config_path(name: str) -> Path:
    """Return an included public YAML configuration."""

    return resource_path("configs", name)


def documentation_path(name: str) -> Path:
    """Return an included release document."""

    return resource_path("docs", name)


def script_path(name: str) -> Path:
    """Return an included shell or Python launcher."""

    return resource_path("scripts", name)


def available_configs() -> tuple[str, ...]:
    """Return the stable names of the four public training recipes."""

    return (
        "grpo_4b.yaml",
        "grpo_9b.yaml",
        "orarl_4b.yaml",
        "orarl_9b.yaml",
    )