diff --git a/coco/state.py b/coco/state.py index 007369c..ba56a4e 100644 --- a/coco/state.py +++ b/coco/state.py @@ -5,6 +5,7 @@ from pathlib import Path from typing import List, Dict import yaml +from kotekan.config import load_config_file from .result import Result from .util import Host, PersistentState, hash_dict @@ -184,32 +185,8 @@ def read_from_file(self, path, file): element, name = self._find_new(path) file_ext = os.path.splitext(file)[1] - if not file_ext == ".j2": - with open(file, "r") as stream: - try: - new_state = yaml.safe_load(stream) - except yaml.YAMLError as exc: - logger.error(f"Failure reading YAML file {file}: {exc}") - else: - # Is a jinja file - try: - from jinja2 import FileSystemLoader, Environment, select_autoescape - from jinja2 import TemplateNotFound - except ImportError as err: - logger.error("Jinja2 required for '.j2' files.") - - directory, file_name = os.path.split(file) - directory = '.' if directory == '' else directory - # Load the template - env = Environment( - loader=FileSystemLoader(directory), autoescape=select_autoescape() - ) - try: - template = env.get_template(file_name) - except TemplateNotFound as err: - logger.error(f"Could not open file {file}") - yaml_raw = template.render() - new_state = yaml.safe_load(yaml_raw) + + new_state = load_config_file(file, return_dict=True, dump=False, jinja_options=None) # Don't load state parts that are excluded from reset self._exclude_paths(path, new_state) diff --git a/requirements.txt b/requirements.txt index 81f1e37..9348b55 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ comet @ git+https://github.com/chime-experiment/comet.git@ael/fixjson#egg=comet +kotekan @ git+https://github.com/kotekan/kotekan.git@develop#egg=kotekan&subdirectory=python/ aiohttp pyyaml requests