from pathlib import Path from typing import Optional, Dict, Union, Type from .formatting_config import FormattingConfig from .dict_formatter import DictFormatter from .simple_tex_formatter import SimpleTeXFormatter from .dtx_formatter import DTXFormatter from .pytex_formatter import PyTeXFormatter def formatter_from_file_extension( input_file: Path, config: Optional[FormattingConfig] = None, locate_file_config: bool = True, allow_infile_config: bool = True ) -> PyTeXFormatter: switcher: Dict[str, Type[Union[DTXFormatter, SimpleTeXFormatter, DictFormatter]]] = { 'dtx.pytex': DTXFormatter, 'sty.pytex': SimpleTeXFormatter, 'cls.pytex': SimpleTeXFormatter, 'dict.pytex': DictFormatter } # TODO: other formatters try: [name, extension] = input_file.name.split('.', maxsplit=1) except: raise NotImplementedError return switcher[extension]( input_file=input_file, config=config, locate_file_config=locate_file_config, allow_infile_config=allow_infile_config )