archivebox.config.collection
Module Contents
Functions
Project an arbitrary config payload to flat |
|
Return |
|
Render a flat config dict to INI text, grouped by inferred section. |
|
Atomic-write |
|
Rewrite |
|
Inverse of |
|
Copy |
|
One-time-per-process reconciliation between the two stores. |
|
Merge |
Data
API
- archivebox.config.collection._coerce_to_str_dict(config: Any) dict[str, str][source]
Project an arbitrary config payload to flat
{UPPER_KEY: str}form.INI files only round-trip strings, so we normalize Machine.config values to strings on the way out and accept the same shape on the way back. Pydantic re-coerces types at read time inside
get_config.Composite values (
dict/list/tuple) are JSON-encoded so they round-trip back through pydantic-settings —str(some_dict)would produce Python’s repr ({'k': 'v'}with single quotes), and pydantic-settings refuses to parse that as adictfield, causing e.g.ABX_INSTALL_CACHEto crash withValidationError: Input should be a valid dictionary.
- archivebox.config.collection._load_file_config_dict() tuple[dict[str, str], float | None][source]
Return
(flat_dict, mtime)forArchiveBox.conf(({}, None)if missing).
- archivebox.config.collection._resolve_section_for_key(key: str, config_sections, plugin_configs) str[source]
- archivebox.config.collection._render_config_file_content(config: dict[str, str]) str[source]
Render a flat config dict to INI text, grouped by inferred section.
- archivebox.config.collection._write_file_if_changed(content: str) bool[source]
Atomic-write
ArchiveBox.confonly when contents actually differ.Skipping unchanged writes is the difference between every Machine.save in a hot autodetection loop costing one disk write vs. zero.
- archivebox.config.collection.mirror_machine_config_to_file(config: Any) None[source]
Rewrite
ArchiveBox.confso it mirrorsMachine.configexactly.Called from
Machine.saveafter the row is committed. Recursion-guarded so the matching write_config_file -> Machine.save bounce doesn’t loop.
- archivebox.config.collection._coerce_from_str_dict(file_config: dict[str, str]) dict[str, Any][source]
Inverse of
_coerce_to_str_dict: decode complex INI values to native.mirror_machine_config_to_fileJSON-encodesdict/listvalues so they round-trip through INI’s string-only storage. When reading the file back intoMachine.config(a JSONField that holds native types) those strings have to be decoded — otherwise downstream consumers like_emit_machine_config→MachineEvent→ abx-dl see a JSON string where they expect a dict and raiseTypeError. Declared fields go through pydantic-settings’ ownfield_is_complex/prepare_field_valueso they’re decoded per annotation. Undeclared keys (e.g.ABX_INSTALL_CACHE, written dynamically by abx-dl) are JSON-decoded when their string starts with{or[— the same shape_coerce_to_str_dictwrites them as.
- archivebox.config.collection._mirror_file_to_machine_config(file_config: dict[str, str]) None[source]
Copy
ArchiveBox.confcontents intoMachine.config.Internal helper used by
write_config_fileand the startup sync — callers must hold the_MIRROR_IN_PROGRESSguard around it.
- archivebox.config.collection.sync_machine_and_file(machine: Any = None) None[source]
One-time-per-process reconciliation between the two stores.
Cheap on the common case where they already agree (single
stat+ dict compare ≈ 1ms). When the two sides diverge we merge them: each side’s unique keys are preserved, and for keys present on both we let the newer side win (file mtime vs.Machine.modified_at). After the merge both stores hold the union, so every subsequent write keeps them in lockstep via the full-replace mirror functions.Pass
machinewhen the caller already has a currentMachineinstance (e.g. fromMachine.current()) to skip the 10–15msget_host_guid()round-trip on the cold path.
- archivebox.config.collection.write_config_file(config: dict[str, str]) archivebox.misc.logging.AttrDict[source]
Merge
configintoArchiveBox.conf, validate, then mirror to Machine.config.Backwards-compatible signature: callers (CLI
archivebox config --setand the init flow) pass a partial dict of keys to upsert.