topmark.config.overrides¶
Apply internal config-like override intent to a resolved MutableConfig draft.
This module sits after layered config discovery/resolution. Its job is to apply the highest-precedence config-like override layer produced by CLI or API orchestration without reimplementing config-file discovery.
PolicyOverrides and
ConfigOverrides are internal typed
value objects. They are not part of TopMark's stable public Python API. Public callers
should pass plain mapping-based configuration and policy inputs to topmark.api
entry points such as topmark.api.check(),
topmark.api.strip(), and
topmark.api.probe().
Execution-only runtime intent such as apply mode, stdin routing, output target,
file write strategy, pruning, and timestamps is intentionally out of scope and
must be handled separately via RunOptions.
Override-application diagnostics belong to the merged-config validation stage. Flattening is performed only at reporting and output boundaries.
PolicyOverrides
dataclass
¶
PolicyOverrides(
*,
header_mutation_mode=None,
allow_header_in_empty_files=None,
empty_insert_mode=None,
render_empty_header_when_no_fields=None,
allow_reflow=None,
allow_content_probe=None,
)
Internal typed overrides for global or per-file-type policy values.
None means "no override provided" for the corresponding policy field.
These values are produced by CLI/API orchestration after public mapping
inputs have been normalized. They are intentionally not exported from
topmark.api and should not be treated as a stable integration surface.
ConfigOverrides
dataclass
¶
ConfigOverrides(
*,
config_origin=SyntheticConfigSource(
label=CLI_OVERRIDE_STR
),
config_base=(lambda: Path.cwd().resolve())(),
strict=None,
policy=PolicyOverrides(),
policy_by_type=(lambda: {})(),
files=None,
files_from=None,
include_from=None,
exclude_from=None,
include_patterns=None,
exclude_patterns=None,
include_file_types=None,
exclude_file_types=None,
header_fields=None,
field_values=None,
align_fields=None,
relative_to=None,
)
Internal highest-precedence config overrides from CLI or API orchestration.
None means "no override provided". Empty collections are meaningful and
should therefore be preserved.
This dataclass is an internal bridge between user-facing inputs and mutable
config drafts. Public API callers should provide plain mappings to
topmark.api functions instead of constructing
ConfigOverrides directly.
Attributes:
| Name | Type | Description |
|---|---|---|
config_origin |
Path | SyntheticConfigSource
|
Real config path or synthetic config source marker used for provenance. |
config_base |
Path
|
real filesystem base for relative patterns and sources |
strict |
bool | None
|
Config-loading strictness override. This remains config-like override intent and is separate from execution-only runtime options. It currently governs strict evaluation of staged config-loading validation. |
policy |
PolicyOverrides
|
Internal global policy override values applied after discovery. |
policy_by_type |
dict[str, PolicyOverrides]
|
Internal per-file-type policy override values applied after discovery. |
files |
list[str] | None
|
List of files to process. |
files_from |
list[str] | None
|
Paths to files that list newline-delimited candidate file paths to add before filtering. |
include_from |
list[str] | None
|
Files containing include patterns. |
exclude_from |
list[str] | None
|
Files containing exclude patterns. |
include_patterns |
list[str] | None
|
Glob patterns to include. |
exclude_patterns |
list[str] | None
|
Glob patterns to exclude. |
include_file_types |
list[str] | None
|
Whitelist of file type identifiers to restrict file discovery. |
exclude_file_types |
list[str] | None
|
Blacklist of file type identifiers to exclude from file discovery. |
header_fields |
list[str] | None
|
List of header fields from the [header] section. |
field_values |
dict[str, str] | None
|
Mapping of field names to their string values from [fields]. |
align_fields |
bool | None
|
Whether to align fields, from [formatting]. |
relative_to |
str | None
|
Base path used only for header metadata (e.g., file_relpath). Note: Glob expansion and filtering are resolved relative to their declaring source (config file dir or CWD for CLI), not relative_to. |
apply_config_overrides ¶
Apply internal CLI/API override intent to an existing mutable config draft.
This helper updates an already-resolved MutableConfig
with the final highest-precedence override layer. It intentionally does not handle
config discovery concerns such as --no-config or --config; those belong to
topmark.toml.resolution and
topmark.config.resolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
MutableConfig
|
Mutable config draft to mutate in place. |
required |
overrides
|
ConfigOverrides
|
Internal structured override values produced by CLI/API orchestration. |
required |
Returns:
| Type | Description |
|---|---|
MutableConfig
|
The same |
MutableConfig
|
after in-place mutation. |
Notes
- Path-to-file options (
--include-from,--exclude-from,--files-from) are normalized againstoverrides.config_base, which defaults to the invocation working directory but may differ for API callers. relative_toinfluences only header metadata generation. It does not change how config-declared glob sources are interpreted.- Provenance information is appended to
overrides.config_originso downstream views can show that a highest-precedence override layer was applied. ConfigOverridesandPolicyOverridesare internal bridge types, not stable public API inputs. Public callers should use mapping-based arguments accepted bytopmark.api.- Execution-only runtime intent (apply mode, STDIN routing, output target, file write
strategy, pruning, timestamps) is out of scope here and must be handled separately via
RunOptions. - Override-application diagnostics are recorded in the merged-config validation stage. Flattening is now performed only at reporting and output boundaries.
Source code in src/topmark/config/overrides.py
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 | |