topmark.config.io.deserializers¶
topmark / config / io / deserializers
Deserialize layered TopMark config fragments into MutableConfig drafts.
This module contains the layered-config deserialization layer for TopMark.
Responsibilities
- parse layered TOML fragments into
MutableConfigdrafts - normalize config-local filesystem references against the source TOML file
- deserialize layered config sections such as policy, files, header, and formatting
- deserialize built-in and caller-provided layered TopMark config fragments into mutable draft configs
Design notes
- This module is intentionally separate from
topmark.config.model. The model layer defines configuration data structures and merge behavior, while this module handles layered-config deserialization and normalization. - The result of deserialization is a
MutableConfig, not an immutableFrozenConfig. Callers may still merge, override, sanitize, and finally freeze the draft. - Execution-only runtime intent is intentionally out of scope here and is
handled separately via
topmark.runtime.model.RunOptions. - Parsing is diagnostics-friendly: invalid shapes/types are reported through the draft config's merged-config validation stage instead of failing fast on first issue.
Typical entry points
mutable_config_from_layered_toml_table()mutable_config_from_defaults()
ExtractedLayeredTomlTables
dataclass
¶
ExtractedLayeredTomlTables(
*,
field_tbl,
header_tbl,
formatting_tbl,
files_tbl,
policy_tbl,
policy_by_type_tbl,
)
Structured bundle of well-known layered TOML subtables.
This keeps the extraction/parsing flow self-documenting and avoids fragile
position-based tuple unpacking when deserializing a TopMark TOML table into
a MutableConfig draft.
mutable_config_from_layered_toml_table ¶
Create a draft config from a layered TopMark TOML fragment.
This helper deserializes only the layered-config subset of a TopMark TOML
source, such as [header], [fields], [formatting], [policy],
[policy_by_type], and [files].
Whole-source TOML schema validation belongs to topmark.toml and should
already have happened before this helper is called from the normal TOML
loading pipeline.
When called from that normal pipeline, this helper assumes TOML section/key shape has already been validated and focuses on layered deserialization, normalization, and staged config-validation semantics.
This helper still performs defensive parsing of layered fragments so that malformed inputs (e.g. from API mappings or tests) are handled gracefully and produce merged-config validation diagnostics instead of raising errors.
Path-to-file entries declared in the config are normalized to absolute
paths using the config file's directory when available. Glob strings are
kept as-is and evaluated later against relative_to.
[fields] is a free-form mapping of field_name -> field_value; only
names listed in [header].fields are rendered later by BuilderStep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
TomlTable
|
Parsed layered TopMark TOML fragment. |
required |
config_file
|
Path | SyntheticConfigSource | None
|
Optional real filesystem config path or synthetic config source marker used for provenance. |
None
|
Returns:
| Type | Description |
|---|---|
MutableConfig
|
The resulting |
Source code in src/topmark/config/io/deserializers.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 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 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 | |
mutable_config_from_defaults ¶
Load the built-in default TopMark TOML table into a mutable draft.
Returns:
| Type | Description |
|---|---|
MutableConfig
|
A |
MutableConfig
|
populated with default values. |
Source code in src/topmark/config/io/deserializers.py
mutable_config_from_mapping ¶
Create a mutable config draft from a generic Python mapping.
This helper is intended for API-facing configuration inputs that are already available as Python mappings rather than TOML documents read from disk.
The accepted shape currently mirrors the layered TopMark config fragment,
so the implementation delegates to
mutable_config_from_layered_toml_table() after copying the input into a
plain dictionary. The separate helper keeps the public/API coercion
boundary explicit and avoids treating generic mappings as if they were
inherently TOML documents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Mapping[str, object]
|
Generic mapping containing configuration data. |
required |
Returns:
| Type | Description |
|---|---|
MutableConfig
|
A mutable configuration draft parsed from the supplied mapping. |
Notes
- This helper is conceptually distinct from whole-source TOML deserialization even though the current mapping shape matches the layered TOML-backed config fragment.
- The mapping is copied to a plain
dictbefore delegation so parsing code can work with a mutable concrete mapping type. - If the API-facing config shape later diverges from raw TOML structure, this helper is the right place to absorb that change without affecting TOML loaders.