hbutils.testing.requires.git
Git availability and version query utilities for testing environments.
This module provides lightweight helpers built on top of
hbutils.system.git.info.git_info() to query Git and Git LFS installation
status as well as retrieve their versions. The functions are intentionally
minimal and designed for use in test requirements checks where a concise
boolean or version object is more convenient than the full metadata dictionary.
The module contains the following main components:
is_git_installed()- Determine whether Git is availablegit_version()- Retrieve the Git version as aVersionInfois_git_lfs_installed()- Determine whether Git LFS is availablegit_lfs_version()- Retrieve the Git LFS version as aVersionInfo
Note
These helpers depend on hbutils.system.git.info.git_info() and therefore
inherit its path resolution and caching behavior.
Example:
>>> from hbutils.testing.requires.git import is_git_installed, git_version
>>> if is_git_installed():
... print(git_version())
2.34.1
__all__
- hbutils.testing.requires.git.__all__ = ['is_git_installed', 'git_version', 'is_git_lfs_installed', 'git_lfs_version']
Built-in mutable sequence.
If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.
is_git_installed
- hbutils.testing.requires.git.is_git_installed(git_path: str | None = None) bool[source]
Check if Git is installed.
The function delegates to
hbutils.system.git.info.git_info()and reports whether Git is available. Whengit_pathis provided, it is used as the candidate Git executable path; otherwise, the systemPATHis searched.- Parameters:
git_path (Optional[str]) – Optional path to the Git executable. If not provided, the function will attempt to find Git in the system
PATH.- Returns:
Trueif Git is installed,Falseotherwise.- Return type:
bool
Example:
>>> is_git_installed() True >>> is_git_installed('/custom/path/to/git') True
git_version
- hbutils.testing.requires.git.git_version(git_path: str | None = None) VersionInfo | None[source]
Get the Git version.
This function returns a
VersionInfoinstance for the parsed Git version when Git is installed and its version information can be parsed. If Git is not installed or the version string cannot be recognized, it returnsNone.- Parameters:
git_path (Optional[str]) – Optional path to the Git executable. If not provided, the function will attempt to find Git in the system
PATH.- Returns:
Git version wrapped as
VersionInfo, orNoneif Git is not installed or the version cannot be determined.- Return type:
Optional[VersionInfo]
Note
This function may return
Noneeven if Git is installed, in cases where thegit --versionoutput is unrecognizable.Example:
>>> version = git_version() >>> if version: ... print(f"Git version: {version}") ... else: ... print("Git version could not be determined") Git version: 2.34.1
is_git_lfs_installed
- hbutils.testing.requires.git.is_git_lfs_installed(git_path: str | None = None) bool[source]
Check if Git LFS is installed.
The function reports
Trueonly when both Git and Git LFS are installed. It useshbutils.system.git.info.git_info()to obtain this information.- Parameters:
git_path (Optional[str]) – Optional path to the Git executable. If not provided, the function will attempt to find Git in the system
PATH.- Returns:
Trueif Git and Git LFS are installed,Falseotherwise.- Return type:
bool
Example:
>>> is_git_lfs_installed() True >>> is_git_lfs_installed('/custom/path/to/git') False
git_lfs_version
- hbutils.testing.requires.git.git_lfs_version(git_path: str | None = None) VersionInfo | None[source]
Get the Git LFS version.
This function returns a
VersionInfoinstance for the parsed Git LFS version when Git LFS is installed and its version information can be parsed. If Git LFS is not installed or the version string cannot be recognized, it returnsNone.- Parameters:
git_path (Optional[str]) – Optional path to the Git executable. If not provided, the function will attempt to find Git in the system
PATH.- Returns:
Git LFS version wrapped as
VersionInfo, orNoneif Git LFS is not installed or the version cannot be determined.- Return type:
Optional[VersionInfo]
Note
This function may return
Noneeven if Git LFS is installed, in cases where thegit lfs versionoutput is unrecognizable.Example:
>>> version = git_lfs_version() >>> if version: ... print(f"Git LFS version: {version}") ... else: ... print("Git LFS version could not be determined") Git LFS version: 3.2.0