Skip to content

feat: Add vendor auto-discovery from file contents#1195

Merged
nathan-stender merged 3 commits into
mainfrom
feat/vendor-auto-discovery
Apr 30, 2026
Merged

feat: Add vendor auto-discovery from file contents#1195
nathan-stender merged 3 commits into
mainfrom
feat/vendor-auto-discovery

Conversation

@nathan-stender

@nathan-stender nathan-stender commented Apr 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add vendor_from_file() and vendor_from_io() public API functions that auto-detect the correct Vendor for a file based on its contents
  • Make vendor_type optional (None default) in allotrope_from_file, allotrope_from_io, allotrope_model_from_file, allotrope_model_from_io — when None, auto-discovers the vendor
  • Add AllotropeVendorNotFoundError exception raised when no parser matches
  • Implement sniff() classmethods on all 53 parsers with lightweight file-content checks (sheet names, header patterns, XML root tags, etc.)
  • Add discover_vendor_test.py with 309 parametrized tests verifying discovery against all existing test data files
  • Add vendor auto-discovery guidance to CLAUDE.md for new parser development

Design

discover_vendor() in parser_factory.py runs a multi-pass detection strategy:

  1. Filter by extension — only parsers supporting the file's extension are candidates
  2. Sniff pass — call sniff() on each candidate, collect all matches
  3. Single match — return immediately
  4. Multiple matches — try create_data() on each sniff match to disambiguate (e.g., Gen5 vs Gen5Image both sniff True for .txt, but only one parses successfully)
  5. No sniff matches — try create_data() on all candidates as brute-force fallback
  6. Sniff matched but parse failed — trust the sniff result (parse failure may be unrelated to discovery, e.g., encoding issues)

Each parser's sniff() is a lightweight classmethod: unique extensions return True, shared extensions check distinctive content (header columns, sheet names, XML root tags, etc.). UTF-16 LE/BE encoded files are handled with BOM detection.

Indistinguishable parser pairs (same file format, either parser works): Gen5/Gen5Image, xPONENT/IntelliFlex, VisionLite/GenesysOnBoard, EchoCherryPick/EchoPlateReformat, QuantStudio/QuantStudioD&A, MSDWorkbench/MethodicalMind.

Test plan

  • All 1119 existing parser tests pass
  • 309 new discovery tests pass — one per test data file, verifying correct vendor detection
  • Lint + mypy clean

🤖 Generated with Claude Code

Add the ability to automatically detect the correct vendor/parser for a file
without requiring the caller to specify it. This adds `vendor_from_file()` and
`vendor_from_io()` public API functions, makes `vendor_type` optional in all
existing API functions, and implements `sniff()` classmethods on all 53 parsers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@nathan-stender
nathan-stender requested review from a team and slopez-b as code owners April 23, 2026 17:49
nathan-stender and others added 2 commits April 23, 2026 14:09
…scover_vendor

When multiple parsers sniff True for the same file (e.g. Gen5/Gen5Image),
try parsing with each to disambiguate. If no sniff matches at all, try
parsing with every extension-compatible candidate as a last resort.

Also adds vendor auto-discovery guidance to CLAUDE.md for new parser
development.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@nathan-stender
nathan-stender merged commit fe88e2b into main Apr 30, 2026
9 checks passed
@nathan-stender
nathan-stender deleted the feat/vendor-auto-discovery branch April 30, 2026 14:40
nathan-stender added a commit that referenced this pull request May 1, 2026
### Added

- Add vendor auto-discovery from file contents (#1195)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants