Skip to content

liblaf.cherries.plugins.git_ ¤

Classes:

Functions:

Git ¤

Bases: Run

Parameters:

  • plugins (dict[str, str], default: <class 'dict'> ) –

    dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

  • inputs (list[Path], default: <dynamic> ) –

    Built-in mutable sequence.

    If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.

  • outputs (list[Path], default: <dynamic> ) –

    Built-in mutable sequence.

    If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.

  • repo (Repo, default: None ) –

Methods:

Attributes:

data_dir cached property ¤

data_dir: Path

entrypoint cached property ¤

entrypoint: Path

exp_dir cached property ¤

exp_dir: Path

inputs class-attribute instance-attribute ¤

inputs: list[Path] = field(factory=list)

name cached property ¤

name: str

outputs class-attribute instance-attribute ¤

outputs: list[Path] = field(factory=list)

params property ¤

params: Mapping[str, Any]

plugin_id property ¤

plugin_id: str

plugin_root property ¤

plugin_root: Self

plugins class-attribute instance-attribute ¤

plugins: dict[str, Plugin] = field(
    factory=dict, kw_only=True
)

project_name cached property ¤

project_name: str | None

repo class-attribute instance-attribute ¤

repo: Repo = field(default=None)

root_dir cached property ¤

root_dir: Path

start_time cached property ¤

start_time: datetime

url cached property ¤

url: str

delegate ¤

delegate(
    method: MethodName,
    args: Sequence[Any] = (),
    kwargs: Mapping[str, Any] = {},
    *,
    first_result: bool = False,
) -> Any
Source code in src/liblaf/cherries/core/_plugin.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def delegate(
    self,
    method: MethodName,
    args: Sequence[Any] = (),
    kwargs: Mapping[str, Any] = {},
    *,
    first_result: bool = False,
) -> Any:
    plugins: Sequence[Plugin] = self._plugins_sort(method)
    if not plugins:
        if first_result:
            return None
        return []
    results: list[Any] = []
    for plugin in plugins:
        result: Any = getattr(plugin, method)(*args, **kwargs)
        if result is None:
            continue
        if first_result:
            return result
        results.append(result)
    return results

end ¤

end(*args, **kwargs) -> None
Source code in src/liblaf/cherries/plugins/git_.py
27
28
29
30
31
32
33
34
35
@override
@core.impl(after=("Dvc",))
def end(self, *args, **kwargs) -> None:
    if not self.repo.is_dirty(untracked_files=True):
        return
    self.repo.git.add(all=True)
    subprocess.run(["git", "status"], check=False)
    message: str = self._make_commit_message()
    self.repo.git.commit(message=message)

get_others ¤

get_others() -> Mapping[str, Any]
Source code in src/liblaf/cherries/core/_run.py
95
96
@spec(first_result=True)
def get_others(self) -> Mapping[str, Any]: ...

get_params ¤

get_params() -> Mapping[str, Any]
Source code in src/liblaf/cherries/core/_run.py
98
99
@spec(first_result=True)
def get_params(self) -> Mapping[str, Any]: ...

get_url ¤

get_url() -> str
Source code in src/liblaf/cherries/core/_run.py
101
102
@spec(first_result=True)
def get_url(self) -> str: ...

log_asset ¤

log_asset(
    path: PathLike,
    name: PathLike | None = None,
    *,
    metadata: Mapping[str, Any] | None = None,
    **kwargs,
) -> None
Source code in src/liblaf/cherries/core/_run.py
104
105
106
107
108
109
110
111
112
113
114
115
116
117
@spec(delegate=False)
def log_asset(
    self,
    path: PathLike,
    name: PathLike | None = None,
    *,
    metadata: Mapping[str, Any] | None = None,
    **kwargs,
) -> None:
    if name is None:
        path = Path(path)
        with contextlib.suppress(ValueError):
            name = path.relative_to(self.data_dir)
    self.delegate("log_asset", (path, name), {"metadata": metadata, **kwargs})

log_input ¤

log_input(path: PathLike, *args, **kwargs) -> None
Source code in src/liblaf/cherries/plugins/git_.py
37
38
39
40
41
@override
@core.impl
def log_input(self, path: PathLike, *args, **kwargs) -> None:
    path: Path = Path(path)
    self.inputs.append(path.relative_to(self.repo.working_dir))

log_metric ¤

log_metric(
    name: str,
    value: Any,
    /,
    step: int | None = None,
    epoch: int | None = None,
    **kwargs,
) -> None
Source code in src/liblaf/cherries/core/_run.py
129
130
131
132
133
134
135
136
137
138
@spec
def log_metric(
    self,
    name: str,
    value: Any,
    /,
    step: int | None = None,
    epoch: int | None = None,
    **kwargs,
) -> None: ...

log_metrics ¤

log_metrics(
    dic: Mapping[str, Any],
    /,
    prefix: str | None = None,
    step: int | None = None,
    epoch: int | None = None,
    **kwargs,
) -> None
Source code in src/liblaf/cherries/core/_run.py
140
141
142
143
144
145
146
147
148
149
@spec
def log_metrics(
    self,
    dic: Mapping[str, Any],
    /,
    prefix: str | None = None,
    step: int | None = None,
    epoch: int | None = None,
    **kwargs,
) -> None: ...

log_other ¤

log_other(key: Any, value: Any, /, **kwargs) -> None
Source code in src/liblaf/cherries/core/_run.py
151
152
@spec
def log_other(self, key: Any, value: Any, /, **kwargs) -> None: ...

log_others ¤

log_others(
    dictionary: Mapping[Any, Any], /, **kwargs
) -> None
Source code in src/liblaf/cherries/core/_run.py
154
155
@spec
def log_others(self, dictionary: Mapping[Any, Any], /, **kwargs) -> None: ...

log_output ¤

log_output(
    path: PathLike, name: PathLike | None = None, **kwargs
) -> None
Source code in src/liblaf/cherries/plugins/git_.py
43
44
45
46
47
48
49
50
51
52
@override
@core.impl
def log_output(
    self,
    path: PathLike,
    name: PathLike | None = None,
    **kwargs,
) -> None:
    path: Path = Path(path)
    self.outputs.append(path.relative_to(self.repo.working_dir))

log_parameter ¤

log_parameter(
    name: Any,
    value: Any,
    /,
    step: int | None = None,
    **kwargs,
) -> None
Source code in src/liblaf/cherries/core/_run.py
167
168
169
170
@spec
def log_parameter(
    self, name: Any, value: Any, /, step: int | None = None, **kwargs
) -> None: ...

log_parameters ¤

log_parameters(
    parameters: Mapping[Any, Any],
    /,
    prefix: str | None = None,
    step: int | None = None,
    **kwargs,
) -> None
Source code in src/liblaf/cherries/core/_run.py
172
173
174
175
176
177
178
179
180
@spec
def log_parameters(
    self,
    parameters: Mapping[Any, Any],
    /,
    prefix: str | None = None,
    step: int | None = None,
    **kwargs,
) -> None: ...

plugin_id_cls classmethod ¤

plugin_id_cls() -> str
Source code in src/liblaf/cherries/core/_plugin.py
21
22
23
@classmethod
def plugin_id_cls(cls) -> str:
    return cls.__name__

register ¤

register(plugin: Plugin) -> None
Source code in src/liblaf/cherries/core/_plugin.py
58
59
60
def register(self, plugin: "Plugin") -> None:
    plugin._plugin_parent = self  # noqa: SLF001
    self.plugins[plugin.plugin_id] = plugin

start ¤

start(*args, **kwargs) -> None
Source code in src/liblaf/cherries/plugins/git_.py
54
55
56
57
@override
@core.impl
def start(self, *args, **kwargs) -> None:
    self.repo = git.Repo(self.plugin_root.exp_dir, search_parent_directories=True)

enc_hook ¤

enc_hook(obj: Any) -> Any
Source code in src/liblaf/cherries/plugins/git_.py
15
16
17
18
def enc_hook(obj: Any) -> Any:
    if isinstance(obj, Path):
        return str(obj)
    raise NotImplementedError