Skip to content

liblaf.cherries.plugins.git_ ¤

Classes:

Git ¤

Bases: Run

Parameters:

  • plugins (dict[PluginId, 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 ) –
  • verify (bool, default: False ) –

Methods:

Attributes:

inputs class-attribute instance-attribute ¤

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

outputs class-attribute instance-attribute ¤

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

plugin_id property ¤

plugin_id: str

plugin_root property ¤

plugin_root: Self

plugins class-attribute instance-attribute ¤

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

repo class-attribute instance-attribute ¤

repo: Repo = field(default=None)

verify class-attribute instance-attribute ¤

verify: bool = False

data_dir ¤

data_dir() -> Path
Source code in src/liblaf/cherries/core/_run.py
27
28
29
@plugin_cached_property
def data_dir(self) -> Path:
    return path_utils.data()

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
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
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:
        try:
            result: Any = getattr(plugin, method)(*args, **kwargs)
        except BaseException as e:
            if isinstance(e, (KeyboardInterrupt, SystemExit)):
                raise
            logger.exception("Plugin {}", plugin.plugin_id)
        else:
            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
22
23
24
25
26
27
28
29
30
@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, no_verify=not self.verify)

entrypoint ¤

entrypoint() -> Path
Source code in src/liblaf/cherries/core/_run.py
31
32
33
@plugin_cached_property
def entrypoint(self) -> Path:
    return path_utils.entrypoint()

exp_dir ¤

exp_dir() -> Path
Source code in src/liblaf/cherries/core/_run.py
35
36
37
@plugin_cached_property
def exp_dir(self) -> Path:
    return path_utils.exp_dir()

get_others ¤

get_others() -> Mapping[str, Any]
Source code in src/liblaf/cherries/core/_run.py
66
67
@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
69
70
@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
72
73
@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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
@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
32
33
34
35
36
@override
@core.impl
def log_input(self, path: PathLike, *args, **kwargs) -> None:
    path: Path = Path(path)
    self.inputs.append(path.relative_to(self.project_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
100
101
102
103
104
105
106
107
108
109
@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
111
112
113
114
115
116
117
118
119
120
@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
122
123
@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
125
126
@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
38
39
40
41
42
43
44
45
46
47
@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.project_dir))

log_parameter ¤

log_parameter(
    name: Any,
    value: Any,
    /,
    step: int | None = None,
    **kwargs,
) -> None
Source code in src/liblaf/cherries/core/_run.py
138
139
140
141
@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
143
144
145
146
147
148
149
150
151
@spec
def log_parameters(
    self,
    parameters: Mapping[Any, Any],
    /,
    prefix: str | None = None,
    step: int | None = None,
    **kwargs,
) -> None: ...

name ¤

name() -> str
Source code in src/liblaf/cherries/core/_run.py
39
40
41
@plugin_cached_property
def name(self) -> str:
    return self.start_time.strftime("%Y-%m-%dT%H%M%S")

params ¤

params() -> Mapping[str, Any]
Source code in src/liblaf/cherries/core/_run.py
43
44
45
@plugin_property
def params(self) -> Mapping[str, Any]:
    return self.plugin_root.get_params()

project_dir ¤

project_dir() -> Path
Source code in src/liblaf/cherries/core/_run.py
51
52
53
@plugin_cached_property
def project_dir(self) -> Path:
    return path_utils.project_dir()

project_name ¤

project_name() -> str | None
Source code in src/liblaf/cherries/core/_run.py
47
48
49
@plugin_cached_property
def project_name(self) -> str | None:
    return self.project_dir.name

register ¤

register(plugin: Plugin) -> None
Source code in src/liblaf/cherries/core/_plugin.py
63
64
65
66
67
68
def register(self, plugin: "Plugin") -> None:
    impls: dict[MethodName, ImplInfo] = collect_impls(plugin)
    for name in impls:
        self._cache_sort_plugins.pop(name, 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
49
50
51
52
@override
@core.impl
def start(self, *args, **kwargs) -> None:
    self.repo = git.Repo(self.project_dir, search_parent_directories=True)

start_time ¤

start_time() -> datetime
Source code in src/liblaf/cherries/core/_run.py
55
56
57
@plugin_cached_property
def start_time(self) -> datetime.datetime:
    return datetime.datetime.now().astimezone()

url ¤

url() -> str
Source code in src/liblaf/cherries/core/_run.py
59
60
61
@plugin_property
def url(self) -> str:
    return self.plugin_root.get_url()