Return a mapping of conda metadata loaded from a meta.yaml files. The format support Jinja-based templating and we try a crude resolution of variables before loading the data as YAML.
(location)
| 606 | |
| 607 | |
| 608 | def get_meta_yaml_data(location): |
| 609 | """ |
| 610 | Return a mapping of conda metadata loaded from a meta.yaml files. The format |
| 611 | support Jinja-based templating and we try a crude resolution of variables |
| 612 | before loading the data as YAML. |
| 613 | """ |
| 614 | # FIXME: use Jinja to process these |
| 615 | variables = get_variables(location) |
| 616 | yaml_lines = [] |
| 617 | with io.open(location, encoding='utf-8') as metayaml: |
| 618 | for line in metayaml: |
| 619 | if not line: |
| 620 | continue |
| 621 | pure_line = line.strip() |
| 622 | if ( |
| 623 | pure_line.startswith('{%') |
| 624 | and pure_line.endswith('%}') |
| 625 | and '=' in pure_line |
| 626 | ): |
| 627 | continue |
| 628 | |
| 629 | # Replace the variable with the value |
| 630 | if '{{' in line and '}}' in line: |
| 631 | for variable, value in variables.items(): |
| 632 | if "|lower" in line: |
| 633 | line = line.replace('{{ ' + variable + '|lower' + ' }}', value.lower()) |
| 634 | else: |
| 635 | line = line.replace('{{ ' + variable + ' }}', value) |
| 636 | yaml_lines.append(line) |
| 637 | |
| 638 | # Cleanup any remaining complex jinja template lines |
| 639 | # as the yaml load fails otherwise for unresolved jinja |
| 640 | cleaned_yaml_lines = [ |
| 641 | line |
| 642 | for line in yaml_lines |
| 643 | if not "{{" in line |
| 644 | ] |
| 645 | |
| 646 | return saneyaml.load(''.join(cleaned_yaml_lines)) |
| 647 | |
| 648 | |
| 649 | def get_variables(location): |