def merge_imports(self, base_path, parsed_templates): parsed = parsed_templates.copy() for import_def in self.data.get("imports", []): import_def.file.resolve_path(base_path) import_path = import_def.file.data if import_path in parsed: continue with (base_path / import_path).open() as fd: yaml_data = yaml.load(fd, str(import_path)) ast, parsed = ServiceTemplate.parse( yaml_data, base_path, import_path, parsed, ) self.merge(ast) # We do not need imports anymore, since they are preprocessor # construct and would only clutter the AST. self.data.pop("imports", None) return parsed
def load(base_path, template_name): with (base_path / template_name).open() as input_fd: input_yaml = yaml.load(input_fd, str(template_name)) if not isinstance(input_yaml.value, dict): raise ParseError( "Top level structure should be a map.", yaml_node.loc, ) tosca_version = _get_tosca_version(input_yaml) parser = _get_parser(tosca_version) stdlib_yaml = stdlib.load(tosca_version) service = parser.parse( stdlib_yaml, base_path, PurePath("STDLIB"), set(), )[0] service.merge( parser.parse( input_yaml, base_path, template_name, set(), )[0]) service.visit("resolve_path", base_path) service.visit("resolve_reference", service) return service
def merge_imports(self, base_path): for import_def in self.data.get("imports", []): csar_path = import_def.file.resolve_path(base_path).data with (base_path / csar_path).open() as fd: yaml_data = yaml.load(fd, str(csar_path)) self.merge( ServiceTemplate.parse( yaml_data, base_path, csar_path.parent, )) # We do not need imports anymore, since they are preprocessor # construct and would only clutter the AST. self.data.pop("imports", None)
def test_load_valid_yaml(self, input, output): assert yaml.load(input, "test").bare == output
def load(version): return yaml.load( pkg_resources.resource_stream(__name__, version + ".yaml"), "STD[{}]".format(version), )