Skip to content

feu.local_git

The tags of the local git repository. It needs the git extra. See the usage guide.

feu.local_git

Contain git utility functions to inspect the tags of the current repository.

These functions require the gitpython package, which can be installed with pip install 'feu[git]'. The repository is searched from the current working directory and its parent directories.

feu.local_git.get_last_tag_name

get_last_tag_name(
    *, raise_error: bool = True
) -> str | None

Get the name of the most recent tag in the current repository.

The most recent tag is the tag pointing to the most recent commit, see get_tags.

Parameters:

Name Type Description Default
raise_error bool

If True, a RuntimeError is raised when no tag is found. If False, None is returned instead.

True

Returns:

Type Description
str | None

The tag name, or None if no tag was found and raise_error=False.

Raises:

Type Description
RuntimeError

if no tag was found and raise_error=True.

MissingPackageError

if the gitpython package is not installed.

InvalidGitRepositoryError

if the current directory is not in a git repository.

Example
>>> from feu.local_git import get_last_tag_name
>>> tag = get_last_tag_name(raise_error=False)
>>> tag is None or isinstance(tag, str)
True

feu.local_git.get_last_version_tag_name

get_last_version_tag_name(
    *, raise_error: bool = True
) -> str | None

Get the name of the most recent version tag in the current repository.

A version tag is a tag made of the prefix v followed by a valid PEP 440 version, e.g. v1.2.3. The other tags are ignored.

Parameters:

Name Type Description Default
raise_error bool

If True, a RuntimeError is raised when no version tag is found. If False, None is returned instead.

True

Returns:

Type Description
str | None

The tag name, or None if no version tag was found and raise_error=False.

Raises:

Type Description
RuntimeError

if no version tag was found and raise_error=True.

MissingPackageError

if the gitpython package is not installed.

InvalidGitRepositoryError

if the current directory is not in a git repository.

Example
>>> from feu.local_git import get_last_version_tag_name
>>> tag = get_last_version_tag_name(raise_error=False)
>>> tag is None or tag.startswith("v")
True

feu.local_git.get_tags

get_tags() -> list[TagReference]

Get the list of git tags sorted by date/time for the current repository.

The repository is searched from the current working directory and its parent directories. The tags are sorted by the commit date of the commit they point to. The repository is closed before returning, so that no git helper process is left running.

Returns:

Type Description
list[TagReference]

The list of git tags sorted by commit date/time, from the oldest to the most recent.

Raises:

Type Description
MissingPackageError

if the gitpython package is not installed.

InvalidGitRepositoryError

if the current directory is not in a git repository.

Example
>>> from feu.local_git import get_tags
>>> tags = get_tags()
>>> isinstance(tags, list)
True