topmark.pipeline.steps.comparer¶
topmark / pipeline / steps / comparer
Header comparer step for the TopMark pipeline (view-based).
This step assigns a ComparisonStatus by comparing the existing header (from HeaderView)
with the expected header produced by the renderer (from RenderView). The comparer prefers a
semantic (dict-wise) comparison of header fields and falls back to a
formatting comparison when content is equal but layout differs. In strip
pipelines (or when an update has already produced a full image), it can perform a
full-file comparison.
Summary of behavior
• If ctx.views.updated carries an updated image, compare full file images.
• If generation is PENDING (pipelines that don't render), set UNCHANGED.
• Else, compare dicts: ctx.views.header.mapping vs ctx.views.build.selected:
- If dicts differ → CHANGED.
- If dicts equal but rendered block differs from existing block
(ordering/spacing/affixes/newlines), treat this as a formatting
change → CHANGED.
• Otherwise → UNCHANGED.
This contract keeps CLI summaries consistent: content changes and pure formatting drifts both show up as "would update header", whereas true matches land in "up-to-date".
ComparerStep ¶
Bases: BaseStep
Compare existing vs expected header content/format.
Prefers semantic (field-mapping) comparison and falls back to formatting comparison when dictionaries match but layout differs. In strip-mode or when an updated image exists, can compare full file images.
Axes written
- comparison
Sets
- ComparisonStatus: {PENDING, CHANGED, UNCHANGED, SKIPPED, CANNOT_COMPARE}
Source code in src/topmark/pipeline/steps/comparer.py
may_proceed ¶
Return True if comparison can run.
Conditions
- Resolve succeeded, file type and header processor exist; and
- One of:
- Generation is
GENERATEDorNO_FIELDS; or - Policy allows empty-file processing; or
- An updated image is already present (strip/update fast path).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
ProcessingContext
|
The processing context for the current file. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if processing can proceed to the build step, False otherwise. |
Source code in src/topmark/pipeline/steps/comparer.py
run ¶
Compare existing vs expected header and set ctx.status.comparison.
The step runs only when header generation has completed or when there are no header fields to generate. In other cases it returns the context unchanged.
Decision tree:
1. Precomputed image: If ctx.updated_file_lines exists (e.g., strip), set
UNCHANGED iff file_lines == updated_file_lines; else CHANGED.
2. No generation: If generation == PENDING, set UNCHANGED.
3. Dict-wise content: Compare existing_header_dict vs expected_header_dict.
- Different → CHANGED.
- Equal → proceed to (4).
4. Formatting fallback: If we have both existing_header_block and
expected_header_lines, compare exact block text. If blocks differ (order,
alignment, spacing, affixes, newline style), set CHANGED; otherwise UNCHANGED.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
ProcessingContext
|
The processing context carrying file state, statuses, and dictionaries. |
required |
Mutations
ProcessingContext: The same context, with status.comparison updated to CHANGED
or UNCHANGED when applicable.
Source code in src/topmark/pipeline/steps/comparer.py
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 | |
hint ¶
Attach comparison hints (non-binding).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
ProcessingContext
|
The processing context. |
required |