Skip to content

Git

liblaf.cherries.plugins.git

Classes:

  • Git –

    Record Git metadata and optionally commit dirty experiment outputs.

Attributes:

logger module-attribute

logger: Logger = logging.getLogger(__name__)

Git

Bases: Plugin


              flowchart TD
              liblaf.cherries.plugins.git.Git[Git]
              liblaf.cherries.core.plugin._plugin.Plugin[Plugin]

                              liblaf.cherries.core.plugin._plugin.Plugin --> liblaf.cherries.plugins.git.Git
                


              click liblaf.cherries.plugins.git.Git href "" "liblaf.cherries.plugins.git.Git"
              click liblaf.cherries.core.plugin._plugin.Plugin href "" "liblaf.cherries.core.plugin._plugin.Plugin"
            

Record Git metadata and optionally commit dirty experiment outputs.

Attributes:

Parameters:

  • name (PluginName, default: <dynamic> ) –
  • run (Run) –
  • commit (bool, default: False ) –
  • verify (bool, default: False ) –

Methods:

  • end –

    Commit dirty changes if configured and log the final Git SHA.

commit class-attribute instance-attribute

commit: bool = attrs.field(default=False, kw_only=True)

name class-attribute instance-attribute

name: PluginName = attrs.field(
    default=attrs.Factory(_default_name, takes_self=True),
    kw_only=True,
)

repo cached property

repo: Repo | None

Repository associated with the owning run.

run class-attribute instance-attribute

run: Run = attrs.field(repr=False)

verify class-attribute instance-attribute

verify: bool = attrs.field(default=False, kw_only=True)

end

end(exc: BaseException | None = None) -> None

Commit dirty changes if configured and log the final Git SHA.

Source code in src/liblaf/cherries/plugins/git.py
@core.impl(before=("Comet",))
def end(self, exc: BaseException | None = None) -> None:
    """Commit dirty changes if configured and log the final Git SHA."""
    del exc
    if self.repo is None:
        return
    if self.commit and self.repo.is_dirty(untracked_files=True):
        message: str = self._make_commit_message()
        try:
            self.repo.git.add(all=True)
            subprocess.run(["git", "status"], check=False)
            self.repo.git.commit(message=message, no_verify=not self.verify)
        except git.GitCommandError:
            logger.exception("")
    self.run.log_other("cherries/git/sha", self.repo.head.commit.hexsha)