Include file referenced at node.
(loader: Loader, node: yaml.Node)
| 30 | super().__init__(stream) |
| 31 | |
| 32 | def construct_include(loader: Loader, node: yaml.Node) -> Any: |
| 33 | """Include file referenced at node.""" |
| 34 | |
| 35 | filename = os.path.abspath(os.path.join(loader._root, loader.construct_scalar(node))) |
| 36 | extension = os.path.splitext(filename)[1].lstrip('.') |
| 37 | |
| 38 | with open(filename, 'r') as f: |
| 39 | if extension in ('yaml', 'yml'): |
| 40 | return yaml.load(f, Loader) |
| 41 | elif extension in ('json', ): |
| 42 | return json.load(f) |
| 43 | else: |
| 44 | return ''.join(f.readlines()) |
| 45 | |
| 46 | def get_config(config_path): |
| 47 | yaml.add_constructor('!include', construct_include, Loader) |
nothing calls this directly
no outgoing calls
no test coverage detected