topmark.toml.defaults¶
Helpers for TopMark's bundled/default TOML documents.
This module is intentionally separate from
topmark.toml.loaders. It does not load TOML from
arbitrary on-disk user config files. Instead, it owns the bundled template and
the code-defined default TopMark TOML document used when the annotated template
is unavailable.
Today, build_default_topmark_toml_table() assembles one complete TOML-serializable
default TopMark document in a single place. Over time, this should evolve toward
merging smaller domain-scoped default fragments such as:
- layered config defaults
- persisted writer-option defaults
- config-resolution/discovery defaults (for example strict mode)
The current helper remains the single centralized assembly point for those partial defaults until that split is implemented.
DefaultTomlTemplateText
dataclass
¶
Loaded default TOML template text and fallback metadata.
Attributes:
| Name | Type | Description |
|---|---|---|
toml_text |
str
|
The TOML document text to emit. |
error |
Exception | None
|
The exception raised while reading the bundled template, if any. Callers may surface this as a user-facing warning. |
load_default_topmark_template_toml_text ¶
Load the bundled default TOML config template as text.
This reads the annotated template bundled with TopMark
(topmark-example.toml) and returns it as UTF-8 text.
Unlike build_default_topmark_toml_table(), this helper preserves the template's
comments and formatting (when the packaged resource is available).
If the packaged template cannot be read, the function falls back to a
generated TOML document built from TopMark's default TOML document
(build_default_topmark_toml_table). The returned result includes the
exception raised while reading the packaged template.
Returns:
| Type | Description |
|---|---|
DefaultTomlTemplateText
|
Loaded default TOML template text and fallback metadata. |
Notes
- This function performs I/O and logs a warning on fallback, but it does not print to stdout/stderr.
- User-facing warnings should be emitted by CLI emitters.
Source code in src/topmark/toml/defaults.py
build_default_topmark_toml_table ¶
Return TopMark's default TOML document as a plain-Python table.
This helper intentionally performs no I/O.
The bundled file topmark-example.toml is an annotated template intended
for human-facing output (for example topmark config init). The actual
default TopMark TOML document is assembled in code so TopMark can still
operate when the packaged template is missing or unreadable.
Today, this helper assembles one centralized TOML-serializable default document that includes both layered config defaults and persisted writer defaults. In the future, the implementation may delegate to smaller domain-scoped helpers and then merge those partial TOML tables here.
If you need the annotated template with comments and formatting preserved,
use load_default_topmark_template_toml_text() and read the returned
DefaultTomlTemplateText.toml_text field.
Returns:
| Type | Description |
|---|---|
TomlTable
|
A new TOML-table-compatible dictionary containing the default TopMark |
TomlTable
|
TOML document. |
Source code in src/topmark/toml/defaults.py
render_default_topmark_toml_text ¶
Render the centralized default TopMark TOML document as text.
This helper is I/O-free: it serializes the TOML table returned by
build_default_topmark_toml_table(). It does not preserve the annotated template's
comments or formatting.
Note
The rendered content is the default TopMark TOML document,
not execution-only RunOptions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
for_pyproject
|
bool
|
If |
required |
Returns:
| Type | Description |
|---|---|
str
|
TOML document text. |