spacr.qt.settings_pack

Read a downloaded settings pack into settings this spaCR can run.

The demo dataset on HuggingFace ships a settings CSV per stage beside the images. They were written by an older spaCR, so some of what they name no longer exists – keys renamed, keys removed with the feature they configured, keys that were never settings at all.

Merging every row of the CSV over the defaults would pass keys the current build does not have into the pipeline, where they are ignored or cause an error naming a setting the user cannot find in the form.

This module therefore migrates the pack and reports what it did with each key:

  • a key the app still has is applied;

  • a key that has been renamed is applied under its new name and counted;

  • a key that no longer exists anywhere is dropped and named;

  • a key that is a setting in this build but not on THIS app’s form is named separately, because this version does have it.

The report states the outcome, for example “Loaded 34 settings, renamed 2, dropped 3 this version no longer has”.

The published pack needs three further rules:

  • File names. einarolafsson/spacr_settings ships gen_masks_settings.csv and crop_measure_settings.csv, not <app>_settings.csv, so the published names in PACK_FILES are tried after <app>_settings.csv.

  • Header row. The shipped files start with Key,Value; that row is skipped rather than read as a setting named Key.

  • List values. channels,"[0, 1, 2, 3]" is parsed into a list with ast.literal_eval rather than applied as a string over a list default.

On the published mask pack, with the current defaults: 32 applied, 9 renamed, 17 dropped, of which 10 are live settings this form does not carry. 32 + 9 + 17 = 58, every row of the file except the header (59 non-blank lines).

Classes

PackReport

What became of a settings pack, in terms a user can be told.

Functions

read_pack(→ Tuple[Dict[str, Any], int])

({key: value}, malformed row count) from this app's pack file.

settings_from_pack(→ Tuple[Dict[str, Any], PackReport])

The app's defaults, with the pack migrated over them.

Module Contents

class spacr.qt.settings_pack.PackReport[source]

What became of a settings pack, in terms a user can be told.

summary() → str[source]

One sentence for a status bar, naming what was lost.

Names the dropped keys rather than counting them: “dropped 3” alone does not say which settings were lost.

Two different losses get two different sentences. Keys such as timelapse are live settings that this form does not show, and are reported separately from keys this version does not have.

spacr.qt.settings_pack.read_pack(app_key: str, pack_dir: str) → Tuple[Dict[str, Any], int][source]

({key: value}, malformed row count) from this app’s pack file.

Missing file is not an error: a pack legitimately carries settings for some apps and not others, and the caller gets an empty dict. Use _pack_path() to tell that case apart from a file that was read.

Parameters:
  • app_key – app key whose pack file is looked for, first as <app_key>_settings.csv and then under the published names in PACK_FILES.

  • pack_dir – folder holding the unpacked settings pack.

spacr.qt.settings_pack.settings_from_pack(app_key: str, pack_dir: str, *, src: str | None = None, defaults: Dict[str, Any] | None = None) → Tuple[Dict[str, Any], PackReport][source]

The app’s defaults, with the pack migrated over them.

Parameters:
  • app_key – the module the pack is for.

  • pack_dir – folder holding this app’s settings CSV, under any of the names _pack_candidates() lists.

  • src – dataset folder; overrides whatever src the pack names, because a pack written on somebody else’s machine names a path that does not exist on this one.

  • defaults – the app’s defaults; resolved from the registry when omitted.

Returns:

the settings to apply, and what became of the pack.