Loading tbc/template_to_component.py +10 −10 Original line number Diff line number Diff line Loading @@ -47,7 +47,7 @@ class GlInput(BaseModel): default: Optional[str] = None def to_json(self) -> dict[str, any]: ret = {"name": self.name} ret = {} if self.description: ret["description"] = self.description if self.type != GlInputType.string: Loading Loading @@ -111,9 +111,6 @@ def _migrate_var(var: TbcVar, var_prefix: str, tpl: dict[str, any]) -> Optional[ def _migrate_tpl(tpl_desc, project_dir: Path, var_prefix: str): tpl_path = tpl_desc['template_path'] print(f"=== Migrate template: {tpl_path}...") print() # load template with open(project_dir / tpl_path, "r") as tpl_file: all_tpl = list(yaml.load_all(tpl_file, Loader=yaml.BaseLoader)) Loading @@ -140,7 +137,7 @@ def _migrate_tpl(tpl_desc, project_dir: Path, var_prefix: str): for var in feat.get("variables", []): gl_inputs.append(_migrate_var(TbcVar.parse_obj(var), var_prefix, tpl)) tpl_specs = {"spec": {"inputs": list(map(lambda input: input.to_json(), filter(lambda input: input != None, gl_inputs)))}} tpl_spec = {"spec": {"inputs": {input.name: input.to_json() for input in gl_inputs if input}}} # rewrite template with inputs section # print(">> Rewrite template") Loading @@ -148,8 +145,8 @@ def _migrate_tpl(tpl_desc, project_dir: Path, var_prefix: str): # with open(project_dir / template_path, "w") as tpl_file: # yaml.dump_all((tpl_specs, tpl), tpl_file) print(">> Template specs:") print(yaml.dump(tpl_specs, default_flow_style=False, sort_keys=False)) print(">> Template spec:") print(yaml.dump(tpl_spec, default_flow_style=False, sort_keys=False)) print() print(">> Variables sections:") Loading Loading @@ -190,10 +187,13 @@ def migrate(): var_prefix = (args.var_prefix or kicker["name"].upper()) + "_" print(f"=== Migrating project {project_dir} with var prefix {var_prefix}...") print(f"=== Migrating main template '{kicker['name']}' with var prefix '{var_prefix}'...") print() _migrate_tpl(kicker, project_dir, var_prefix) for variant in kicker.get("variants"): _migrate_tpl(variant, project_dir, var_prefix) for variant in kicker.get("variants", []): var_prefix_for_variant = var_prefix+(variant["id"].upper())+"_" print(f"=== Migrating variant '{variant['name']}' with var prefix '{var_prefix_for_variant}'...") print() _migrate_tpl(variant, project_dir, var_prefix_for_variant) Loading
tbc/template_to_component.py +10 −10 Original line number Diff line number Diff line Loading @@ -47,7 +47,7 @@ class GlInput(BaseModel): default: Optional[str] = None def to_json(self) -> dict[str, any]: ret = {"name": self.name} ret = {} if self.description: ret["description"] = self.description if self.type != GlInputType.string: Loading Loading @@ -111,9 +111,6 @@ def _migrate_var(var: TbcVar, var_prefix: str, tpl: dict[str, any]) -> Optional[ def _migrate_tpl(tpl_desc, project_dir: Path, var_prefix: str): tpl_path = tpl_desc['template_path'] print(f"=== Migrate template: {tpl_path}...") print() # load template with open(project_dir / tpl_path, "r") as tpl_file: all_tpl = list(yaml.load_all(tpl_file, Loader=yaml.BaseLoader)) Loading @@ -140,7 +137,7 @@ def _migrate_tpl(tpl_desc, project_dir: Path, var_prefix: str): for var in feat.get("variables", []): gl_inputs.append(_migrate_var(TbcVar.parse_obj(var), var_prefix, tpl)) tpl_specs = {"spec": {"inputs": list(map(lambda input: input.to_json(), filter(lambda input: input != None, gl_inputs)))}} tpl_spec = {"spec": {"inputs": {input.name: input.to_json() for input in gl_inputs if input}}} # rewrite template with inputs section # print(">> Rewrite template") Loading @@ -148,8 +145,8 @@ def _migrate_tpl(tpl_desc, project_dir: Path, var_prefix: str): # with open(project_dir / template_path, "w") as tpl_file: # yaml.dump_all((tpl_specs, tpl), tpl_file) print(">> Template specs:") print(yaml.dump(tpl_specs, default_flow_style=False, sort_keys=False)) print(">> Template spec:") print(yaml.dump(tpl_spec, default_flow_style=False, sort_keys=False)) print() print(">> Variables sections:") Loading Loading @@ -190,10 +187,13 @@ def migrate(): var_prefix = (args.var_prefix or kicker["name"].upper()) + "_" print(f"=== Migrating project {project_dir} with var prefix {var_prefix}...") print(f"=== Migrating main template '{kicker['name']}' with var prefix '{var_prefix}'...") print() _migrate_tpl(kicker, project_dir, var_prefix) for variant in kicker.get("variants"): _migrate_tpl(variant, project_dir, var_prefix) for variant in kicker.get("variants", []): var_prefix_for_variant = var_prefix+(variant["id"].upper())+"_" print(f"=== Migrating variant '{variant['name']}' with var prefix '{var_prefix_for_variant}'...") print() _migrate_tpl(variant, project_dir, var_prefix_for_variant)