topmark.pipeline.engine¶
Execution helpers for running pipelines over a list of files (engine layer).
This module provides a small, CLI-free function to execute a pipeline for one or more files. It exists so both the public API and the CLI can share the same engine logic without introducing import cycles.
Design goals
- No CLI dependencies: Do not import Click, console helpers, or anything under
topmark.cli.*from here. Presentation (printing, colors, exit) is a responsibility of the CLI layer. - Structured results: Return a
PipelineExecutioncontaining producedProcessingContextobjects plus an optionalExitCodesummarizing any error encountered while iterating files. - Logging only: Error conditions are logged via the package logger. Callers decide how to surface errors (e.g., raise, print, or exit).
Typical usage:
run = run_steps_for_files(
file_list=files,
pipeline=Pipeline.CHECK.steps,
config=cfg,
run_options=run_options,
)
if run.error_code is not None:
# CLI would map this to a process exit; API callers may handle it differently.
...
This module is intentionally minimal to keep the dependency graph acyclic and the execution path easy to test in isolation.
PipelineExecution
dataclass
¶
Result of running pipeline steps over a selected file list.
Attributes:
| Name | Type | Description |
|---|---|---|
results |
list[ProcessingContext]
|
Ordered per-file processing contexts produced by the pipeline, one for each path in the input file list that did not raise a fatal engine-level error. |
exit_code |
ExitCode | None
|
First non-success engine-level exit code encountered while
iterating files, or |
exit_code_from_pipeline_results ¶
Return the highest-priority non-success exit code implied by pipeline results.
This helper summarizes per-file pipeline statuses into a process-level exit signal for CLI/API callers. It is intentionally presentation-free: it does not print, log, or inspect rendered hints. Callers remain responsible for rendering diagnostics and deciding exactly when to exit.
Priority order
- missing inputs (
FILE_NOT_FOUND) - permission failures (
PERMISSION_DENIED) - encoding failures (
ENCODING_ERROR) - write failures (
IO_ERROR) - generic read/I/O failures (
IO_ERROR)
Non-error skips such as binary/unsupported files, empty files, mixed line endings, and policy blocks are intentionally not mapped here. Those remain normal per-file pipeline outcomes unless a command layer gives them a command-specific non-zero meaning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
Sequence[ProcessingContext]
|
Pipeline contexts returned by |
required |
Returns:
| Type | Description |
|---|---|
ExitCode | None
|
The highest-priority |
ExitCode | None
|
the result set does not imply a command-level error. |
Source code in src/topmark/pipeline/engine.py
run_steps_for_files ¶
Run a pipeline for each file and return structured engine results.
Catches common filesystem/encoding errors so command bodies don't duplicate try/except.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_options
|
RunOptions
|
Invocation-wide runtime options shared by all files in the run. |
required |
config
|
FrozenConfig
|
Default layered TopMark configuration for the run. |
required |
path_configs
|
Mapping[Path, FrozenConfig] | None
|
Optional per-path effective layered configs. When provided, a
path-specific config is used for bootstrap; otherwise the shared |
None
|
pipeline
|
Sequence[Step[ProcessingContext]]
|
The pipeline steps to execute for the run. |
required |
file_list
|
list[Path]
|
List of file Path instances to be processed in the run. |
required |
Returns:
| Type | Description |
|---|---|
PipelineExecution
|
Structured engine result containing ordered per-file |
PipelineExecution
|
|
PipelineExecution
|
code, if any. The exit code is suitable for reporting or process exit |
PipelineExecution
|
in the CLI layer. |
Exit code mapping
FILE_NOT_FOUND
Raised when a path is missing or is a directory where a file was expected
(FileNotFoundError, IsADirectoryError).
PERMISSION_DENIED
Raised on insufficient permissions (PermissionError).
ENCODING_ERROR
Raised when the input cannot be decoded as text (UnicodeDecodeError).
PIPELINE_ERROR
Any other unexpected exception not covered by the above categories.
Notes
- This helper never prints; it only logs. Callers are responsible for user-visible messaging and exiting the process if desired.
- When multiple files are processed, only the first error code is preserved (a conventional behavior for batch tools). Subsequent files continue to run.
Source code in src/topmark/pipeline/engine.py
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 | |