Coverage for src/configuraptor/loaders/__init__.py: 100%

1"""

2 Loads loaders based on Python version.

3"""

4

5 import typing

6

7 from ._types import T_config

8

9# tomli used for every Python version now.

10 from .loaders_shared import json, toml, yaml

11

12 __all__ = ["get", "toml", "json", "yaml"]

13

14 T_loader = typing.Callable[[typing.BinaryIO], T_config]

15

16 LOADERS: dict[str, T_loader] = {

17 "toml": toml,

18 "json": json,

19 "yml": yaml,

20 "yaml": yaml,

21}

22

23

24 def get(extension: str) -> T_loader:

25 """

26 Get the right loader for a specific extension.

27 """

28 extension = extension.removeprefix(".")

29 if loader := LOADERS.get(extension):

30 return loader

31 else:

32 raise ValueError(f"Invalid extension {extension}")