Skip to content

comicbox.config.settings ¶

Typed runtime config for comicbox.

Built once by get_config() from the validated confuse AttrDict; every downstream module takes ComicboxSettings instead of AttrDict.

The dataclass tree mirrors the YAML config tree and the CLI argument groups one-for-one:

comicbox:
  general / read / write / print / convert / compute
  online:
    lookup / auth / cache / tuning
  readinglists

This taxonomy is the source of truth for the config tree. New options must land under the group that owns their concern.

The online subtree is big enough to live in its own package — comicbox.config.online.settings. readinglists holds what reading lists alone need: the DieselTech catalog’s repository, ref and lifetime, and the download size cap. Their credentials and cache are online’s.

ComicboxSettings dataclass ¶

Typed runtime config for comicbox, organized by verb taxonomy.

Source code in comicbox/config/settings.py
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
@dataclass(frozen=True, slots=True)
class ComicboxSettings:
    """Typed runtime config for comicbox, organized by verb taxonomy."""

    general: GeneralSettings
    read: ReadSettings
    write: WriteSettings
    print: PrintSettings
    convert: ConvertSettings
    compute: ComputeSettings
    online: "OnlineSettings"
    readinglists: ReadingListsSettings = field(default_factory=ReadingListsSettings)

    # CLI positional args.
    paths: tuple[str | Path | None, ...] = ()

    # Computed (derived in compute_config(); kept flat for ergonomics —
    # they're read by many call sites and the flat names are clearer).
    all_write_formats: "frozenset[MetadataFormats]" = field(default_factory=frozenset)
    # Whether the formats given said keep, as the config was built.
    is_write_keep: bool = False
    read_filename_formats: "frozenset[MetadataFormats]" = field(
        default_factory=frozenset
    )
    read_file_formats: "frozenset[MetadataFormats]" = field(default_factory=frozenset)
    read_metadata_lower_filenames: frozenset[str] = field(default_factory=frozenset)
    is_read_comments: bool = False
    is_skip_computed_from_tags: bool = False

ComputeSettings dataclass ¶

Derived-metadata switches. YAML-only — set-once preferences.

Source code in comicbox/config/settings.py
160
161
162
163
164
165
@dataclass(frozen=True, slots=True)
class ComputeSettings:
    """Derived-metadata switches. YAML-only — set-once preferences."""

    pages: bool = False
    page_count: bool = True

ConvertSettings dataclass ¶

Archive conversion actions: cbz, rename, page/cover extraction, import/export.

Source code in comicbox/config/settings.py
146
147
148
149
150
151
152
153
154
155
156
157
@dataclass(frozen=True, slots=True)
class ConvertSettings:
    """Archive conversion actions: cbz, rename, page/cover extraction, import/export."""

    cbz: bool | None = None
    rename: bool | None = None
    extract_pages_from: int | None = None
    extract_pages_to: int | None = None
    extract_covers: bool | None = None
    import_paths: tuple[Path, ...] = ()
    export_formats: "frozenset[MetadataFormats]" = field(default_factory=frozenset)
    pdf_pages: str = ""

GeneralSettings dataclass ¶

Cross-cutting options that don’t fit a verb-specific group.

Source code in comicbox/config/settings.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
@dataclass(frozen=True, slots=True)
class GeneralSettings:
    """Cross-cutting options that don't fit a verb-specific group."""

    config: str | Path | None = None
    recurse: bool = False
    dry_run: bool = False
    loglevel: str | int = "INFO"
    dest_path: str | Path = "."
    delete_keys: frozenset[str] = field(default_factory=frozenset)
    delete_orig: bool = False
    metadata: Mapping | None = None
    metadata_cli: tuple[str, ...] | None = None
    metadata_format: str | None = None
    jobs: int = 1
    tagger: str | None = None
    theme: str | None = "gruvbox-dark"

MergeMode ¶

Bases: StrEnum

How caller-supplied metadata merges into a comic’s existing tags.

Applies to metadata the caller handed to this run — the write API’s patch, -m, --import files and the config’s metadata block. Metadata comicbox discovered on its own is always accumulated additively.

  • additive: deep-merge via mergedeep ADDITIVE. Dicts recurse; lists / tuples / sets at conflicting paths concatenate; scalars and other leaves replace. Default.
  • replace: deep-merge via mergedeep REPLACE. Dicts recurse; everything else (scalars, lists, tuples, sets) replaces. Use it when a list-typed patch value is meant to be the new complete value rather than an append.
  • update: dict.update() at ROOT_TAG. Replaces top-level keys wholesale; siblings of a replaced key are dropped. A patch of {"credits": {"Jane": {...}}} removes every other credit.

additive and replace differ only on the five list-typed schema fields: remainders, reprints, series_groups, urls and series.alternative_names. Everywhere else the schema is dict-of-dict or scalar, where the two are indistinguishable.

Source code in comicbox/config/settings.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
class MergeMode(StrEnum):
    """
    How caller-supplied metadata merges into a comic's existing tags.

    Applies to metadata the caller handed to this run — the write API's
    patch, ``-m``, ``--import`` files and the config's metadata block.
    Metadata comicbox discovered on its own is always accumulated
    additively.

    - ``additive``: deep-merge via mergedeep ADDITIVE. Dicts recurse;
      lists / tuples / sets at conflicting paths *concatenate*; scalars
      and other leaves *replace*. Default.
    - ``replace``: deep-merge via mergedeep REPLACE. Dicts recurse;
      everything else (scalars, lists, tuples, sets) *replaces*. Use it
      when a list-typed patch value is meant to be the new complete
      value rather than an append.
    - ``update``: ``dict.update()`` at ROOT_TAG. Replaces top-level keys
      wholesale; siblings of a replaced key are dropped. A patch of
      ``{"credits": {"Jane": {...}}}`` removes every other credit.

    ``additive`` and ``replace`` differ only on the five list-typed
    schema fields: ``remainders``, ``reprints``, ``series_groups``,
    ``urls`` and ``series.alternative_names``. Everywhere else the
    schema is dict-of-dict or scalar, where the two are
    indistinguishable.
    """

    ADDITIVE = "additive"
    UPDATE = "update"
    REPLACE = "replace"

PrintSettings dataclass ¶

Phases to print and whether to validate.

Source code in comicbox/config/settings.py
138
139
140
141
142
143
@dataclass(frozen=True, slots=True)
class PrintSettings:
    """Phases to print and whether to validate."""

    phases: "frozenset[PrintPhases]" = field(default_factory=frozenset)
    validate: bool = False

ReadSettings dataclass ¶

Which metadata sources to load and in what merge order.

Source code in comicbox/config/settings.py
76
77
78
79
80
81
82
83
84
85
86
@dataclass(frozen=True, slots=True)
class ReadSettings:
    """Which metadata sources to load and in what merge order."""

    formats: "frozenset[MetadataFormats]" = field(default_factory=frozenset)
    except_formats: frozenset[str] | None = None  # YAML key: "except"
    # Merge precedence, later wins. None = ``MetadataSources`` enum order
    # with the online sources ranked by ``online.lookup.sources``, the
    # first listed winning. Set, it is the whole order and the source
    # selection does not change it. Expert knob; YAML-only.
    merge_order: "tuple[MetadataSources, ...] | None" = None

ReadingListsSettings dataclass ¶

Where reading lists come from online, beyond the online sources.

Source code in comicbox/config/settings.py
168
169
170
171
172
173
174
175
176
177
178
@dataclass(frozen=True, slots=True)
class ReadingListsSettings:
    """Where reading lists come from online, beyond the online sources."""

    # The GitHub repository and ref holding DieselTech's CBL lists.
    catalog_repo: str = "DieselTech/CBL-ReadingLists"
    catalog_ref: str = "main"
    # How long the catalog's index is reused before it is revalidated.
    catalog_ttl: timedelta = timedelta(hours=4)
    # The largest list a fetch will download, in bytes.
    max_download_bytes: int = 16 * 1024 * 1024

WriteSettings dataclass ¶

Which metadata formats to write back, and how.

Source code in comicbox/config/settings.py
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
@dataclass(frozen=True, slots=True)
class WriteSettings:
    """Which metadata formats to write back, and how."""

    formats: "frozenset[MetadataFormats]" = field(default_factory=frozenset)
    # How supplied metadata overlays existing tags. Settable with the
    # ``write.merge_mode`` config key and ``--merge-mode``.
    merge_mode: MergeMode = MergeMode.ADDITIVE
    stamp: bool = False
    stamp_notes: bool = True
    delete_all_tags: bool = False
    # Set by ``keep`` among the formats: a write removes no tag format the
    # comic already carries, and writes the ones it read back beside those
    # named.
    keep_formats: bool = False

parse_enum(enum_cls, flag, raw, *, noun='name') ¶

Parse a lowercased string into an enum member, raising a flag-tagged error.

Source code in comicbox/config/settings.py
45
46
47
48
49
50
51
52
53
54
def parse_enum(
    enum_cls: type[_EnumT], flag: str, raw: str, *, noun: str = "name"
) -> _EnumT:
    """Parse a lowercased string into an enum member, raising a flag-tagged error."""
    try:
        return enum_cls(raw.strip().lower())
    except ValueError as exc:
        valid = ", ".join(member.value for member in enum_cls)
        reason = f"{flag}: unknown {noun} {raw!r}; valid: {valid}"
        raise ConfigurationError(reason) from exc