Load template from the path if applicable.
(var_name: str, config: dict)
| 31 | |
| 32 | |
| 33 | def _load_template(var_name: str, config: dict) -> dict: |
| 34 | """Load template from the path if applicable.""" |
| 35 | # Check if template_path exists in config. |
| 36 | if f"{var_name}_path" in config: |
| 37 | # If it does, make sure template variable doesn't also exist. |
| 38 | if var_name in config: |
| 39 | raise ValueError( |
| 40 | f"Both `{var_name}_path` and `{var_name}` cannot be provided." |
| 41 | ) |
| 42 | # Pop the template path from the config. |
| 43 | template_path = Path(config.pop(f"{var_name}_path")) |
| 44 | # Load the template. |
| 45 | if template_path.suffix == ".txt": |
| 46 | with open(template_path) as f: |
| 47 | template = f.read() |
| 48 | else: |
| 49 | raise ValueError |
| 50 | # Set the template variable to the extracted variable. |
| 51 | config[var_name] = template |
| 52 | return config |
| 53 | |
| 54 | |
| 55 | def _load_examples(config: dict) -> dict: |
no test coverage detected