Coverage for /Users/rik/github/navdict/src/navdict/directives.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.8.2, created at 2025-10-16 22:28 +0200

1""" 

2Default directive plugins that are used in NavigableDict. 

3 

4This module also serves as a guideline how to implement the directive plugins. The plugins are called with the 

5following interface: 

6 

7 plugin_func(value: str, parent_location: Path | None, *args, **kwargs) 

8 

9where: 

10 

11 - value: this is the directive value, i.e. the part that comes after the double slash '//'. 

12 - parent_location: this is the location of the navdict where this directive was found and 

13 this can be used to determine the location of a resource. 

14 - args: any positional arguments that were given in the YAML file under '<key>_args'. 

15 - kwargs: any keyword arguments that were given in the YAML file under '<key>_kwargs'. 

16 

17""" 

18 

19import logging 

20import os 

21from pathlib import Path 

22 

23from navdict.navdict import load_yaml as _load_yaml 

24from navdict.navdict import load_csv as _load_csv 

25 

26logger = logging.getLogger("navdict.plugin") 

27 

28 

29def load_yaml(value: str, parent_location: Path | None, *args, **kwargs): 

30 # logger.debug(f"Loading YAML file: '{value}'.") 

31 

32 return _load_yaml(value, parent_location) 

33 

34 

35def load_csv(value: str, parent_location: Path | None, *args, **kwargs): 

36 # logger.debug(f"Loading CSV file: '{value}'.") 

37 

38 return _load_csv(value, parent_location, *args, **kwargs) 

39 

40 

41def env_var(value: str, parent_location: Path | None, *args, **kwargs): 

42 # logger.debug(f"Loading environment variable: '{value}'.") 

43 

44 return os.environ.get(value) 

45 

46 

47# TODO: 

48# I can have 'panda' as an optional dependency and provide a pandas directive here.