From bf23ba3f38a2605d6d12702e00c1ed32a6d4d642 Mon Sep 17 00:00:00 2001 From: brb Date: Thu, 13 Jul 2023 11:36:47 +0200 Subject: [PATCH] added automatic parsing from file --- code/runner_script.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/code/runner_script.py b/code/runner_script.py index 2fd6c55..447a5ee 100644 --- a/code/runner_script.py +++ b/code/runner_script.py @@ -7,10 +7,16 @@ from pathlib import Path class RunnerScript(BaseModel): script: List[str] + @staticmethod + def from_file(path: Path): + assert path.exists() + with open(path, 'r') as fh: + content_dict = yaml.safe_load(fh) + script_list = content_dict['script'].split('\n') + return RunnerScript.model_validate({'script': script_list}) + if __name__ == '__main__': path = Path(__file__).parent.parent / 'runner_script.yml' - with open(path, 'r') as fh: - script = yaml.safe_load(fh) - runner_script = RunnerScript.parse_obj(script) - print(runner_script) \ No newline at end of file + rs = RunnerScript.from_file(path) + print(rs) \ No newline at end of file