Coverage for src \ truenex_memory \ ingestion \ parsers \ __init__.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.14.0, created at 2026-05-19 10:21 +0200

1"""Parser registry for ingestion source types.""" 

2 

3from __future__ import annotations 

4 

5from collections.abc import Callable 

6from pathlib import Path 

7 

8from truenex_memory.ingestion.manifest import IngestionRecord 

9 

10ParserFunc = Callable[[Path, str, str, str], list[IngestionRecord]] 

11"""Parser signature: (resolved_source_dir, project, source_tool, privacy_scope) -> records""" 

12 

13_parsers: dict[str, ParserFunc] = {} 

14 

15 

16def register(source_type: str): 

17 """Decorator that registers a parser function for a source_type.""" 

18 

19 def decorator(parser: ParserFunc) -> ParserFunc: 

20 _parsers[source_type] = parser 

21 return parser 

22 

23 return decorator 

24 

25 

26def get_parser(source_type: str) -> ParserFunc | None: 

27 return _parsers.get(source_type) 

28 

29 

30def parsers() -> dict[str, ParserFunc]: 

31 return dict(_parsers) 

32 

33 

34# Import parsers so they self-register 

35from truenex_memory.ingestion.parsers import text_docs # noqa: E402, F401 

36from truenex_memory.ingestion.parsers import jsonl_sessions # noqa: E402, F401