(path: os.PathLike, platform: str)
| 97 | |
| 98 | |
| 99 | def render(path: os.PathLike, platform: str) -> str: |
| 100 | try: |
| 101 | with open(path) as fi: |
| 102 | data = fi.read() |
| 103 | except OSError: |
| 104 | sys.exit("Error: could not open '%s' for reading" % path) |
| 105 | directory = dirname(path) |
| 106 | content_filter = partial(select_lines, namespace=ns_platform(platform)) |
| 107 | data = content_filter(data) |
| 108 | try: |
| 109 | yaml.load(data) |
| 110 | return data |
| 111 | except YAMLError as e: |
| 112 | if ("{{" not in data) and ("{%" not in data): |
| 113 | raise UnableToParse(original=e) |
| 114 | try: |
| 115 | from constructor.jinja import render_jinja_for_input_file |
| 116 | except ImportError as ex: |
| 117 | raise UnableToParseMissingJinja2(original=ex) |
| 118 | return render_jinja_for_input_file(data, directory, content_filter) |
| 119 | |
| 120 | |
| 121 | def parse(path: os.PathLike, platform: str): |
no test coverage detected