topmark.pipeline.steps.reader¶
topmark / pipeline / steps / reader
File reader step for the TopMark pipeline.
This step determines whether the target is a UTF-8 text file, detects the
newline convention (LF, CRLF, or CR), and loads the file image (lines) while preserving
original line endings. It updates the processing context with the detected
newline style, whether the file ends with a newline, and exposes the file image for subsequent
steps via a view (see ctx.views.image).
Implementation details
- Uses an incremental UTF-8 decoder to avoid false negatives when multibyte sequences span chunk boundaries during the binary/text sniff.
- Detects CRLF robustly across read chunk boundaries by carrying a 1-byte tail, preferring CRLF over LF and CR when both appear.
- If no newline is observed during sniffing (e.g., single-line files), defaults to "\n" and proceeds, rather than skipping the file.
ReaderStep ¶
Bases: BaseStep
Load text image, detect newline style, and set ContentStatus.
Loads the file as UTF-8 text (preserving native newlines), captures BOM/shebang facts from the sniffer, computes a newline histogram, and determines the dominant newline style for later rendering/comparison.
Axes written
- content
Sets
- ContentStatus: {PENDING, OK, UNSUPPORTED, SKIPPED_MIXED_LINE_ENDINGS, SKIPPED_POLICY_BOM_BEFORE_SHEBANG, UNREADABLE}
Source code in src/topmark/pipeline/steps/reader.py
may_proceed ¶
Determine if processing can proceed to the read step.
Processing can proceed if: - The file was successfully resolved (ctx.status.resolve is RESOLVED) - A file type is present (ctx.file_type is not None) - A header processor is available (ctx.header_processor is not None)
Notes:
- The file system status (ctx.status.fs) states are set by the SnifferStep:
- OK
- controlled by policy
- errors
- The file system status (ctx.status.fs) is not strictly required here, to allow tests
to skip the sniffer and invoke the reader directly. In such cases, ReaderStep is the
definitive authority for content checks (existence, permissions, binary/text, etc).
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 read step, False otherwise. |
Source code in src/topmark/pipeline/steps/reader.py
run ¶
Loads file lines and detects newline style.
This function preserves native newline conventions and records them
in ctx.newline_style.vIt assumes the sniffer has already performed existence,
permission, binary, BOM/shebang, and mixed-newlines policy checks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
ProcessingContext
|
The processing context for the current file. |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If header processor or file type are not defined. |
Notes
- Assumes
sniffer.sniff()has already handled existence, permissions, binary detection, BOM/shebang ordering policy, and mixed-newlines policy. - Sets
ctx.views.image = ListFileImageView(lines)(preserving original line endings), provides streaming access throughctx.iter_file_lines(), and recordsctx.ends_with_newline, a precise newline histogram inctx.newline_hist, and the dominant newline style inctx.newline_style.
Source code in src/topmark/pipeline/steps/reader.py
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 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | |
hint ¶
Attach content outcome hints (non-binding).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
ProcessingContext
|
The processing context. |
required |