updated schema generator to format the yaml files better, confirmed cli still works

This commit is contained in:
donny committed 2026-01-05 14:49:28 -07:00
1 parent 4f8ba22cd2
commit 4ed1ddad33
3 files changed
+94 -5

No files matched your search

+41 -2
View File
@@ -36,6 +36,45 @@ def find_workflow_files(workflows_dir: Path) -> List[Path]:
return sorted(workflow_files)
def format_schema_yaml(schema: dict) -> str:
"""Format schema as nicely-formatted YAML string (matches write_yaml output)."""
lines = []
# Metadata section
lines.append(f"name: {schema['name']}")
lines.append(f"description: {schema.get('description', '')}")
lines.append(f"category: {schema.get('category', 'Uncategorized')}")
# Model types
model_types = schema.get('model_types', [])
if model_types:
lines.append("model_types:")
for mt in model_types:
lines.append(f" - {mt}")
else:
lines.append("model_types: []")
# Double newline before parameters
lines.append("")
lines.append("parameters:")
# Format each parameter with a blank line between them
parameters = schema.get('parameters', [])
for i, param in enumerate(parameters):
# Add blank line between parameters (not before first one)
if i > 0:
lines.append("")
# Dump the parameter to YAML and indent it
param_yaml = yaml.dump([param], default_flow_style=False, allow_unicode=True, sort_keys=False)
# Remove the leading "- " and adjust indentation
param_lines = param_yaml.strip().split('\n')
for line in param_lines:
lines.append(f" {line}")
return '\n'.join(lines)
def cmd_generate(args: argparse.Namespace) -> int:
"""Generate YAML schema(s) from workflow files."""
workflows_dir = get_workflows_dir()
@@ -55,7 +94,7 @@ def cmd_generate(args: argparse.Namespace) -> int:
print(f"{action}: {yaml_path.name}")
if args.dry_run:
print(yaml.dump(schema, default_flow_style=False, sort_keys=False))
print(format_schema_yaml(schema))
print("-" * 40)
except Exception as e:
print(f"Error processing {wf_path.name}: {e}")
@@ -75,7 +114,7 @@ def cmd_generate(args: argparse.Namespace) -> int:
if args.dry_run:
print(f"Would generate: {yaml_path.name}")
print(yaml.dump(schema, default_flow_style=False, sort_keys=False))
print(format_schema_yaml(schema))
else:
print(f"Generated: {yaml_path.name}")