MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / get_variables

Function get_variables

src/packagedcode/conda.py:649–668  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

647
648
649def 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

Callers 1

get_meta_yaml_dataFunction · 0.85

Calls 2

openMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected