Conda yaml will have variables defined at the beginning of the file, the idea is to parse it and return a dictionary of the variable and value For example: {% set version = "0.45.0" %} {% set sha256 = "bc7512f2eef785b037d836f4cc6faded457ac277f75c6e34eccd12da7c85258f" %}
(location)
| 647 | |
| 648 | |
| 649 | def get_variables(location): |
| 650 | """ |
| 651 | Conda yaml will have variables defined at the beginning of the file, the |
| 652 | idea is to parse it and return a dictionary of the variable and value |
| 653 | |
| 654 | For example: |
| 655 | {% set version = "0.45.0" %} |
| 656 | {% set sha256 = "bc7512f2eef785b037d836f4cc6faded457ac277f75c6e34eccd12da7c85258f" %} |
| 657 | """ |
| 658 | result = {} |
| 659 | with io.open(location, encoding='utf-8') as loc: |
| 660 | for line in loc.readlines(): |
| 661 | if not line: |
| 662 | continue |
| 663 | line = line.strip() |
| 664 | if line.startswith('{%') and line.endswith('%}') and '=' in line: |
| 665 | line = line.lstrip('{%').rstrip('%}').strip().lstrip('set').lstrip() |
| 666 | parts = line.split('=') |
| 667 | result[parts[0].strip()] = parts[-1].strip().strip('"') |
| 668 | return result |
no test coverage detected