_bundles_fetch¶
rhiza_hooks._bundles_fetch
¶
Load and fetch template-bundles documents into a typed result.
This module is responsible solely for obtaining a template-bundles document —
from a local file, from already-fetched bytes, or from a remote GitHub
repository — and returning it as a :class:BundlesDoc. Structural validation of
the returned mapping lives in :mod:rhiza_hooks._bundles_validate.
BundlesDoc
dataclass
¶
Outcome of loading/parsing a template-bundles document.
data holds the parsed mapping on success and is None on failure;
errors carries the failure messages (empty on success). The two are
mutually exclusive, so callers branch on data is None — which also lets
the type checker narrow data to dict on the success path without a
cast.
Source code in rhiza_hooks/_bundles_fetch.py
Fetcher
¶
Bases: Protocol
The :func:fetch_remote_bundles-shaped callable a validation run obtains its document from.
The same reasoning as :class:_Opener, one layer up. check_template_bundles
injects this rather than reaching for the module global, so a test supplies a fake
document through the argument every caller uses instead of rebinding
check_template_bundles.fetch_remote_bundles by dotted name — a rebinding that
pins the wiring rather than the behaviour, and breaks on any rename.
Unprefixed, unlike :class:_Opener: this module's convention is that a leading
underscore marks a helper with no caller outside its own file, and this one is
named in another module's signatures.
Source code in rhiza_hooks/_bundles_fetch.py
__call__(repo, branch, *, attempts, timeout)
¶
fetch_remote_bundles(repo, branch, attempts=FETCH_ATTEMPTS, backoff=FETCH_BACKOFF_SECONDS, timeout=FETCH_TIMEOUT_SECONDS, opener=urlopen)
¶
Fetch template-bundles.yml from a remote GitHub repository.
Transient network failures (URLError/TimeoutError) are retried up to
attempts times with a linear backoff, and each failed attempt is logged
so CI failures are diagnosable. HTTP errors (e.g. 404) are permanent and
returned immediately without retrying.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo
|
str
|
GitHub repository in 'owner/repo' format |
required |
branch
|
str
|
Branch name |
required |
attempts
|
int
|
Total number of fetch attempts (initial try + retries) |
FETCH_ATTEMPTS
|
backoff
|
float
|
Base seconds to sleep between attempts (multiplied by attempt number) |
FETCH_BACKOFF_SECONDS
|
timeout
|
float
|
Per-request socket timeout in seconds |
FETCH_TIMEOUT_SECONDS
|
opener
|
_Opener
|
Performs one HTTP GET; defaults to :func: |
urlopen
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
BundlesDoc
|
class: |
Source code in rhiza_hooks/_bundles_fetch.py
load_local_bundles(bundles_path)
¶
Load and parse a local template-bundles file into a :class:BundlesDoc.
This is the local-file counterpart to :func:fetch_remote_bundles and part
of this module's cross-module surface — :mod:rhiza_hooks._bundles_validate
calls it to load a document before validating it.