Coverage for appr/render_jsonnet.py : 72%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# 1. Resolve old manifest variables # Load 'old' manifest.yaml # Get variable from the 'old' manfiest and update them tla = json.loads(tla_codes['params']).get("variables", {}) variables.update(tla) # Resolve the templated variables inside the 'old' manifest
# 2. Convert 'old' manifest.yaml to manifest.jsonnet # Load the yaml -> jsonnet template # @TODO keep yaml format and escape 'jsonnet' commands: key: "<% $.variables.key %>" # jsonnet_str = re.sub(r'[\'"]<%(.*)%>["\']', r"\1", templatedjsonnet)
self.manifestdir = os.path.dirname(manifestpath)
# Returns content if worked, None if file not found, or throws an exception full_path = rel else:
raise RuntimeError('Attempted to import a directory')
raise RuntimeError('Got invalid filename (empty string).') if self.files[full_path] is None: with open(full_path) as f: self.files[full_path] = f.read() return rel, self.files[full_path]
# @TODO(ant31) fail if full_path is absolute filepath = os.path.join(self.manifestdir, full_path) with open(filepath) as f: return rel, f.read() else:
if not os.path.isfile(full_path): return full_path, None
with open(full_path) as f: return full_path, f.read()
raise RuntimeError('File not found')
# @TODO(ant31): workaround until jsonnet compile on windows "snippet", manifeststr, import_callback=self.import_callback, native_callbacks=filters.jsonnet_callbacks(), tla_codes=tla_codes)
print("tla_codes: %s" % (str(tla_codes))) print("\n".join([ "%s %s" % (i, line) for i, line in enumerate([ l for l in manifeststr.split("\n") if re.match(r"^ *#", l) is None])])) raise e |