Coverage for appr/render_jsonnet.py : 71%

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 raise RuntimeError('Got invalid filename (empty string).')
if self.files[rel] is None: with open(rel) as f: self.files[rel] = f.read() return rel, self.files[rel] filepath = os.path.join(self.manifestdir, rel) with open(filepath) as f: return rel, f.read() else:
if rel[0] == '/': full_path = rel else: full_path = path + rel if full_path[-1] == '/': raise RuntimeError('Attempted to import a directory') 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')
"snippet", manifeststr, import_callback=self.import_callback, native_callbacks=filters.jsonnet_callbacks(), tla_codes=tla_codes)
"%s %s" % (i, line) for i, line in enumerate( [l for l in manifeststr.split("\n") if re.match(r"^ *#", l) is None]) ])) return json.loads(json_str) |