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
« 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.
4This module also serves as a guideline how to implement the directive plugins. The plugins are called with the
5following interface:
7 plugin_func(value: str, parent_location: Path | None, *args, **kwargs)
9where:
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'.
17"""
19import logging
20import os
21from pathlib import Path
23from navdict.navdict import load_yaml as _load_yaml
24from navdict.navdict import load_csv as _load_csv
26logger = logging.getLogger("navdict.plugin")
29def load_yaml(value: str, parent_location: Path | None, *args, **kwargs):
30 # logger.debug(f"Loading YAML file: '{value}'.")
32 return _load_yaml(value, parent_location)
35def load_csv(value: str, parent_location: Path | None, *args, **kwargs):
36 # logger.debug(f"Loading CSV file: '{value}'.")
38 return _load_csv(value, parent_location, *args, **kwargs)
41def env_var(value: str, parent_location: Path | None, *args, **kwargs):
42 # logger.debug(f"Loading environment variable: '{value}'.")
44 return os.environ.get(value)
47# TODO:
48# I can have 'panda' as an optional dependency and provide a pandas directive here.