Coverage for collectra/converters/__init__.py: 100.00%

9 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-16 09:56 +0000

1from pathlib import Path 

2 

3from .yolo import YOLOClassifierCSV, YOLOConverter 

4 

5converters = { 

6 "yolo": YOLOConverter, 

7 "yoloclassifier_csv": YOLOClassifierCSV, 

8} 

9 

10 

11def convert_files( 

12 input: Path, 

13 root_label: str, 

14 ext: str, 

15 converter_name: str, 

16 output: Path, 

17 force: bool = False, 

18) -> None: 

19 """Convert files using the specified converter. 

20 

21 Args: 

22 input (Path): Path to the configuration file or folder for conversion. 

23 root_label (str): Root label for converted data. 

24 ext (str): File extension for converted collectra files. 

25 converter_name (str): Name of the converter to use. 

26 output (Path): Output folder for converted files. 

27 force (bool, optional): Whether to force overwrite existing files. Defaults to False. 

28 

29 Raises: 

30 ValueError: If the specified converter is not found. 

31 """ 

32 converter_cls = converters.get(converter_name) 

33 if converter_cls is None: 

34 raise ValueError( 

35 f"Converter '{converter_name}' not found. Available converters: {list(converters.keys())}" 

36 ) 

37 

38 converter = converter_cls(input, root_label, ext, output, force=force) 

39 converter.convert()