climate_ref.executor.fragment
#
Helpers for allocating non-colliding output fragment paths.
PLACEHOLDER_FRAGMENT = '_pending'
module-attribute
#
Output-fragment placeholder used until Execution.id is known.
allocate_output_fragment(base_fragment, results_dir)
#
Return a unique output fragment by appending a UTC timestamp.
The returned fragment is {base_fragment}_{YYYYMMDDTHHMMSSffffff}, which is
practically unique without needing any database or filesystem lookups.
Microsecond resolution avoids collisions from rapid successive calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_fragment
|
str
|
The natural fragment, e.g. |
required |
results_dir
|
Path
|
The results root directory. Used to verify the allocated fragment does not already exist on disk. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A new fragment with a timestamp suffix |
Raises:
| Type | Description |
|---|---|
FileExistsError
|
If the computed output directory already exists under results_dir |
Source code in packages/climate-ref/src/climate_ref/executor/fragment.py
assign_execution_fragment(session, execution, *, provider_slug, diagnostic_slug, selectors, group_id, diagnostic_version=_DEFAULT_DIAGNOSTIC_VERSION)
#
Flush execution to materialise its id, then assign the canonical output fragment.
Returns the assigned fragment string.
Source code in packages/climate-ref/src/climate_ref/executor/fragment.py
compute_group_short(selectors, group_id, diagnostic_version, *, token_limit=_DEFAULT_TOKEN_LIMIT)
#
Compute a short, deterministic, human-readable path segment for an execution group.
Human-readable hint for operators browsing the filesystem.
Not unique -- execution_id is the uniqueness guarantee.
Selector values across all source types are sorted (first by source-type key,
then by facet key),
sanitized to [A-Za-z0-9_-],
joined by _,
and truncated to token_limit characters at an underscore boundary.
A suffix _g{group_id}_v{diagnostic_version}_{digest} is appended,
where digest is an 8-character BLAKE2s hash of the canonical
group_id|diagnostic_version|sorted_selectors representation.
The returned string is ASCII, capped at roughly 96 characters, and deterministic for fixed inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
selectors
|
Mapping[str, Iterable[tuple[str, str]]]
|
Mapping from source-type key (e.g. |
required |
group_id
|
int
|
The |
required |
diagnostic_version
|
int
|
The integer |
required |
token_limit
|
int
|
Maximum length of the sanitized selector portion before the suffix. |
_DEFAULT_TOKEN_LIMIT
|
Returns:
| Type | Description |
|---|---|
str
|
A short, sanitized, deterministic identifier suitable for use as a filesystem path segment. |
Source code in packages/climate-ref/src/climate_ref/executor/fragment.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |