Inspect
cifflow.inspect._lexer
inspect_lexer — pretty-print the lexer token stream for a CIF source.
inspect_lexer(source, *, version=None, file=sys.stdout, use_colour=True)
Print the full token stream for source to file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
_Source
|
CIF source: a raw string, a |
required |
version
|
Optional[CifVersion]
|
If None (default), auto-detected from the magic line. |
None
|
file
|
TextIO
|
Output stream (default |
stdout
|
use_colour
|
bool
|
If False, suppress all ANSI colour codes regardless of terminal type. Default True. |
True
|
Source code in src/cifflow/inspect/_lexer.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
cifflow.inspect._parser
inspect_parse + ParseHandler — pretty-print parser events for a CIF source.
ParseHandler
A CifParserEvents implementation that prints every event and error.
Pass an optional inner handler to forward all events after printing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inner
|
Optional[CifParserEvents]
|
Optional downstream handler. All events are forwarded to it after being printed. |
None
|
file
|
TextIO
|
Output stream (default |
stdout
|
show_values
|
bool
|
If False, |
True
|
use_colour
|
bool
|
If False, suppress all ANSI colour codes regardless of terminal type. Default True. |
True
|
Source code in src/cifflow/inspect/_parser.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 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 | |
inspect_parse(source, *, inner=None, file=sys.stdout, show_values=True, show_tokens=True, use_colour=True)
Run the full pipeline and print token stream then parser events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
_Source
|
CIF source: a raw string, a |
required |
inner
|
Optional[CifParserEvents]
|
Optional downstream handler to receive all events. |
None
|
file
|
TextIO
|
Output stream (default |
stdout
|
show_values
|
bool
|
Forward to |
True
|
show_tokens
|
bool
|
If True (default), also print the lexer token stream before events. |
True
|
use_colour
|
bool
|
If False, suppress all ANSI colour codes regardless of terminal type. Default True. |
True
|
Source code in src/cifflow/inspect/_parser.py
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 | |
cifflow.inspect._model
inspect_model — pretty-print a CifFile or CIF source string.
inspect_model(source, *, mode='pad', file=sys.stdout, show_values=True, show_tokens=True, use_colour=True)
Run the full pipeline through the CIF model and print a summary.
Prints (in order): token stream, parser events, CifFile summary, errors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
_Source
|
CIF source: a raw string, a |
required |
mode
|
str
|
Loop row-count mismatch mode passed to |
'pad'
|
file
|
TextIO
|
Output stream (default |
stdout
|
show_values
|
bool
|
Forward to |
True
|
show_tokens
|
bool
|
If True (default), also print the lexer token stream before events. |
True
|
use_colour
|
bool
|
If False, suppress all ANSI colour codes regardless of terminal type. Default True. |
True
|
Source code in src/cifflow/inspect/_model.py
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 | |
cifflow.inspect._schema
inspect_schema — pretty-print a SchemaSpec derived from a DDLm dictionary.
inspect_schema(source, *, show_ddl=False, file=sys.stdout, use_colour=True)
Print a structured summary of a SchemaSpec to file.
source may be:
- A :class:
~cifflow.dictionary.schema.SchemaSpec— used directly. - A :class:
~cifflow.dictionary.loader.DdlmDictionary— schema generated from it. - A
pathlib.Pathto a DDLm dictionary file — loaded via :class:~cifflow.dictionary.loader.DictionaryLoaderwithdirectory_resolver(path.parent)so_import.getdirectives resolve from the same directory. - A raw CIF source string — parsed with no resolver (imports that require external files are silently skipped).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Union[str, Path, SchemaSpec, DdlmDictionary]
|
Dictionary source, a pre-built |
required |
show_ddl
|
bool
|
If |
False
|
file
|
TextIO
|
Output stream. Default |
stdout
|
use_colour
|
bool
|
If False, suppress all ANSI colour codes regardless of terminal type. Default True. |
True
|
Source code in src/cifflow/inspect/_schema.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
inspect_fk_path(schema, source, target, *, file=sys.stdout, use_colour=True)
Print all FK and bridge-column chains that connect source to target.
Shows two kinds of paths:
- Direct FK edges (
ForeignKeyDef) stored on each table — the declaredFOREIGN KEYconstraints in the schema. - Bridge column chains (
BridgeColumnDef) computed during schema generation — the transitive multi-hop lookups that ingest uses to propagate FK values through intermediate tables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
SchemaSpec
|
The |
required |
source
|
str
|
Table name to start from. |
required |
target
|
str
|
Table name to reach. |
required |
file
|
TextIO
|
Output stream. Default |
stdout
|
use_colour
|
bool
|
If False, suppress all ANSI colour codes regardless of terminal type. Default True. |
True
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in src/cifflow/inspect/_schema.py
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 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 | |
cifflow.inspect._ingest
inspect_ingest — trace what happens during CIF ingestion.
TraceEvent
dataclass
One event captured during :func:inspect_ingest.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
str
|
Category of event. One of:
|
detail |
str
|
Human-readable description of the event. |
block_id |
Optional[str]
|
CIF data-block name where the event occurred, if known. |
table |
Optional[str]
|
DuckDB table name involved, if applicable. |
tag |
Optional[str]
|
CIF tag involved, if applicable. |
Source code in src/cifflow/inspect/_ingest.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
inspect_ingest(cif, db=None, schema=None, *, propagate_fk=False, dataset_id=None, file=None, use_colour=True)
Run ingestion, capture events, and pretty-print a diagnostic trace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cif
|
CifFile
|
Parsed |
required |
db
|
DuckDBPyConnection | None
|
Open |
None
|
schema
|
SchemaSpec | None
|
|
None
|
propagate_fk
|
bool
|
Forwarded to |
False
|
dataset_id
|
str | None
|
Forwarded to |
None
|
file
|
Optional[TextIO]
|
Where to write the trace. Defaults to |
None
|
use_colour
|
bool
|
If False, suppress all ANSI colour codes regardless of terminal type. Default True. |
True
|
Returns:
| Type | Description |
|---|---|
list[TraceEvent]
|
All captured events in occurrence order. |
Source code in src/cifflow/inspect/_ingest.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |