httk.core.git_sources¶
Fetch, cache and install members of git repositories named by git URIs.
A git URI has the form git+SCHEME://AUTHORITY/PATH[@REF][#SUBDIR] with
SCHEME one of https, http or file. The repository is cloned at
REF (a branch, tag, abbreviated or full commit hash, or the remote default
branch when omitted), and the member is the directory SUBDIR (or the
repository root), which must hold the consumer’s marker file. The canonical URI
always carries the full commit hash, a lowercased scheme and host, and no
trailing slashes; the repository path is kept verbatim, so …/repo and
…/repo.git are distinct URIs.
Checkout trees are cached per repository and commit under
data_home() / "git"; they carry no .git directory and are safe to
delete. Referencing a URI with install_git_member() records one installed
entry under data_home() / KIND / "installed", where KIND names the
consumer (for example "templates"). Git runs with the global and system
configuration, hooks, credential helpers and terminal prompts disabled, so only
repositories reachable without credentials are supported. The cache-only
lookups (cached_git_checkout(), installed_git_members(),
installed_git_member(), resolve_installed_name() and
uninstall_git_members()) never run git and never fetch.
Classes¶
One parsed git URI. |
|
One installed git member entry. |
Functions¶
|
Parse and canonicalize a |
|
Return the canonical pinned URI and cached checkout tree, cloning only on a cache miss. |
|
Return the cached checkout tree of a pinned URI without running git. |
|
Return the member directory uri names inside a checkout tree. |
|
Fetch the member a git URI names and record it as installed. |
|
Return the installed entries of kind, sorted by URI, without running git. |
|
Return the installed entry for exactly this pinned URI, without running git. |
|
Return the installed entry a short name means: the latest referenced one. |
|
Remove installed entries without running git; cached checkout trees stay. |
Module Contents¶
- class httk.core.git_sources.GitUri¶
One parsed git URI.
- Parameters:
repository – Give the canonical
git+scheme://authority/pathrepository.ref – Give the branch, tag or commit, or
Nonefor the default branch.subdir – Give the member directory, or
Nonefor the repository root.
- class httk.core.git_sources.InstalledGitMember¶
One installed git member entry.
- Parameters:
kind – Give the consumer kind, such as
"templates".uri – Give the canonical pinned URI.
repository – Give the canonical repository part of the URI.
commit – Give the full commit hash.
subdir – Give the member directory, or
Nonefor the repository root.names – Give the short names the member claims.
referenced_at – Give the ISO timestamp of the latest explicit reference.
path – Give the member directory inside the cached checkout tree.
- path: pathlib.Path¶
- httk.core.git_sources.parse_git_uri(text)¶
Parse and canonicalize a
git+scheme://authority/path[@ref][#subdir]URI.The ref is split off at the last
@of the path, so repository paths that themselves contain@are not supported.- Parameters:
text (str) – Supply the URI text.
- Returns:
The parsed URI with a lowercased scheme, host and hash and no trailing slashes.
- Raises:
ValueError – If the text is not a supported git URI.
- Return type:
- httk.core.git_sources.fetch_git_checkout(uri)¶
Return the canonical pinned URI and cached checkout tree, cloning only on a cache miss.
A pinned URI whose commit is already cached runs no git at all.
- Parameters:
- Returns:
The URI pinned to the full commit hash, and the checkout tree root.
- Raises:
ValueError – If the URI is invalid or git fails.
- Return type:
- httk.core.git_sources.cached_git_checkout(uri)¶
Return the cached checkout tree of a pinned URI without running git.
- Parameters:
- Returns:
The tree root, or
Noneif the URI is not pinned or not cached.- Raises:
ValueError – If the URI text is invalid.
- Return type:
pathlib.Path | None
- httk.core.git_sources.git_member(tree, uri, marker)¶
Return the member directory uri names inside a checkout tree.
- Parameters:
tree (pathlib.Path) – Give the checkout tree root.
uri (GitUri) – Give the URI whose subdirectory names the member.
marker (str) – Give the file name the member directory must hold.
- Returns:
The member directory.
- Raises:
ValueError – If the subdirectory is missing, leaves the tree, or lacks the marker.
- Return type:
- httk.core.git_sources.install_git_member(kind, uri, marker, names)¶
Fetch the member a git URI names and record it as installed.
The entry is written only after names accepts the member. Every call refreshes
referenced_at, which decides which commit a short name means.- Parameters:
kind (str) – Name the consumer kind, such as
"templates".uri (str) – Supply a
git+…URI.marker (str) – Give the file name the member directory must hold.
names (collections.abc.Callable[[pathlib.Path], collections.abc.Sequence[str]]) – Validate the member directory and return the short names it claims.
- Returns:
The installed entry.
- Raises:
ValueError – If the URI or kind is invalid, git fails, or the member is missing or invalid.
- Return type:
- httk.core.git_sources.installed_git_members(kind)¶
Return the installed entries of kind, sorted by URI, without running git.
Malformed or inconsistent entries and entries whose checkout is missing are skipped with a warning.
- Parameters:
kind (str) – Name the consumer kind, such as
"templates".- Returns:
The installed entries.
- Raises:
ValueError – If the kind is invalid.
- Return type:
- httk.core.git_sources.installed_git_member(kind, uri)¶
Return the installed entry for exactly this pinned URI, without running git.
- Parameters:
- Returns:
The entry, or
Noneif the URI is not pinned or not installed.- Raises:
ValueError – If the kind or URI is invalid.
- Return type:
InstalledGitMember | None
- httk.core.git_sources.resolve_installed_name(kind, name)¶
Return the installed entry a short name means: the latest referenced one.
- Parameters:
- Returns:
The latest-referenced entry claiming name, or
Noneif none does.- Raises:
ValueError – If entries from several lineages (repository and subdirectory) claim name.
- Return type:
InstalledGitMember | None
- httk.core.git_sources.uninstall_git_members(kind, selector)¶
Remove installed entries without running git; cached checkout trees stay.
A pinned URI removes that entry; an unpinned URI (no ref, a branch, tag or abbreviated hash) removes every entry of its repository and subdirectory; a short name removes every entry of the lineage
resolve_installed_name()selects.- Parameters:
- Returns:
The removed entries.
- Raises:
ValueError – If the selector is invalid, ambiguous, or matches nothing.
- Return type: