topmark.resolution.filetypes¶
topmark / resolution / filetypes
Path-based file type and processor resolution helpers.
This module contains the shared scoring-based resolution engine used to map a
concrete filesystem path onto the most specific matching
FileType, and optionally onto the bound
HeaderProcessor registered for that
resolved file type.
Unlike identifier-based lookup in topmark.registry.filetypes,
these helpers operate on real paths and evaluate extension, filename, pattern,
and optional content-based signals.
Resolution may produce multiple matching FileType candidates. This is not a
registry error. Instead, the resolver applies a deterministic precedence model
and selects at most one effective winner. Candidate overlap is therefore
allowed, but the final selection must remain stable for the same path, content,
and effective registry state.
The module also constructs probe results for topmark probe. Probe result value
objects live in topmark.resolution.probe, while the
probe implementation remains here so it can share the exact same scoring and
tie-break helpers used by effective resolution.
FileTypeCandidate
dataclass
¶
Describe a scored file type resolution candidate.
Attributes:
| Name | Type | Description |
|---|---|---|
score |
int
|
Candidate precedence score; higher is better. |
namespace |
str
|
Candidate file type namespace. |
local_key |
str
|
Candidate file type local key. |
file_type |
FileType
|
Candidate |
FileTypeCandidateOrderKey
dataclass
¶
Deterministic ordering key for scored file type candidates.
The fields are ordered in comparison priority order so instances can be used
directly as min() or sorted() keys.
Attributes:
| Name | Type | Description |
|---|---|---|
score_rank |
int
|
Negated candidate score. Lower values sort first, so higher
scores win when this key is used with |
namespace |
str
|
Candidate file type namespace used as a deterministic tie-breaker. |
local_key |
str
|
Candidate file type local key used as a deterministic tie-breaker. |
MatchSignals
dataclass
¶
Name-based match signals for a FileType (extension, filename/tail, pattern).
candidate_order_key ¶
Return the deterministic ordering key for a file type candidate.
Candidates are ordered by
1) score (descending) 2) namespace (ascending) 3) local key (ascending)
The returned ordered value object is intended to be used with min() or
sorted() so that the highest-scoring candidate wins and exact score ties
are resolved deterministically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
candidate
|
FileTypeCandidate
|
Candidate being ranked. |
required |
Returns:
| Type | Description |
|---|---|
FileTypeCandidateOrderKey
|
Ordered candidate ranking key. |
Source code in src/topmark/resolution/filetypes.py
get_file_type_candidates_for_path ¶
Return candidate file types using name-based and optional content-based matching.
This helper centralizes the resolution logic used by ResolverStep.
For each registered FileType, it computes name-based match signals,
determines whether content probing is allowed via the file type's
ContentGate, optionally calls the file type's content_matcher, and
evaluates inclusion rules and scoring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Filesystem path of the file being resolved. |
required |
include_file_types
|
Collection[str] | None
|
Optional set of file type identifiers to include. Frozen config passes canonical qualified keys. Direct callers may pass public local identifiers when unambiguous. Empty collection means no whitelist filter. |
None
|
exclude_file_types
|
Collection[str] | None
|
Optional set of file type identifiers to exclude. Frozen config passes canonical qualified keys. Direct callers may pass public local identifiers when unambiguous. Empty collection means no blacklist filter. |
None
|
Returns:
| Type | Description |
|---|---|
list[FileTypeCandidate]
|
Unsorted scored candidates. The caller is responsible for selecting the |
list[FileTypeCandidate]
|
best candidate. |
Source code in src/topmark/resolution/filetypes.py
probe_resolution_for_path ¶
Resolve a path and return probe-visible explanation details.
This helper uses the shared scoring and deterministic tie-break model and
returns all diagnostic details needed by the topmark probe command and
probe-backed pipeline resolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Filesystem path of the file being resolved. |
required |
include_file_types
|
Collection[str] | None
|
Optional set of file type identifiers to include. Frozen config passes canonical qualified keys. Direct callers may pass public local identifiers when unambiguous. |
None
|
exclude_file_types
|
Collection[str] | None
|
Optional set of file type identifiers to exclude. Frozen config passes canonical qualified keys. Direct callers may pass public local identifiers when unambiguous. |
None
|
Returns:
| Type | Description |
|---|---|
ResolutionProbeResult
|
Probe result containing candidates, selected file type, selected processor, |
ResolutionProbeResult
|
status, and reason. |
Source code in src/topmark/resolution/filetypes.py
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 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 | |