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
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 | |