def __call__(self, *args, **kwargs) -> None:
     pybatch.PythonBatchCommandBase.__call__(self, *args, **kwargs)
     if self.config_files is not None:
         reader = ConfigVarYamlReader(config_vars)
         for config_file in self.config_files:
             reader.read_yaml_file(config_file)
     with utils.utf8_open_for_read(self.unresolved_file, "r") as rfd:
         text_to_resolve = rfd.read()
     resolved_text = config_vars.resolve_str(text_to_resolve)
     with utils.utf8_open_for_write(self.resolved_file, "w") as wfd:
         wfd.write(resolved_text)
Example #2
0
    def test_readFile(self):
        input_file_path = Path(__file__).parent.joinpath("test_input.yaml")
        out_file_path = Path(__file__).parent.joinpath("test_out.yaml")
        expected_file_path = Path(__file__).parent.joinpath(
            "expected_output.yaml")

        reader = ConfigVarYamlReader()
        reader.read_yaml_file(input_file_path)
        variables_as_yaml = config_vars.repr_for_yaml()
        yaml_doc = aYaml.YamlDumpDocWrap(variables_as_yaml,
                                         '!define',
                                         "",
                                         explicit_start=True,
                                         sort_mappings=True)
        with open(out_file_path, "w") as wfd:
            aYaml.writeAsYaml(yaml_doc, wfd)

        out_lines = normalize_yaml_lines(out_file_path)
        expected_lines = normalize_yaml_lines(expected_file_path)

        self.assertEqual(out_lines, expected_lines)
    def __call__(self, *args, **kwargs) -> None:
        pybatch.PythonBatchCommandBase.__call__(self, *args, **kwargs)
        with config_vars.push_scope_context() as scope_context:
            if self.temp_config_vars:
                config_vars.update(self.temp_config_vars)
            if self.config_files is not None:
                reader = ConfigVarYamlReader(config_vars)
                for config_file in self.config_files:
                    reader.read_yaml_file(config_file)
            with utils.utf8_open_for_read(self.unresolved_file, "r") as rfd:
                text_to_resolve = rfd.read()
            resolved_text = config_vars.resolve_str(text_to_resolve)

            if self.raise_if_unresolved:
                unresolved_re = re.compile(r"""\$\(.*?\)""")
                all_unresolved = unresolved_re.findall(resolved_text)
                if all_unresolved:
                    unresolved_references = ", ".join(list(
                        set(all_unresolved)))
                    raise ValueError(
                        f"unresolved config_vars in {self.unresolved_file}: {unresolved_references}"
                    )
            with utils.utf8_open_for_write(self.resolved_file, "w") as wfd:
                wfd.write(resolved_text)
 def __call__(self, *args, **kwargs) -> None:
     pybatch.PythonBatchCommandBase.__call__(self, *args, **kwargs)
     reader = ConfigVarYamlReader(config_vars)
     reader.read_yaml_file(self.file_to_read)