We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider having YAML schema as release asset and decouple it from the CLI commands.
Either that, or put them in a directory in this repo, and refer to the GitHub "raw" URLs.
Run with uv run hello.py:
uv run hello.py
# /// script # dependencies = [ # "pyyaml==6.0.1", # ] # /// import yaml from typing import Dict, Any, List import json def variable_to_schema_property(variable: Dict[str, Any]) -> Dict[str, Any]: property_schema = { 'title': variable['name'] } var_type = variable.get('type', 'string') if var_type == 'bool': property_schema['type'] = 'boolean' elif var_type == 'int': property_schema['type'] = 'integer' elif var_type == 'float': property_schema['type'] = 'number' else: property_schema['type'] = 'string' if 'description' in variable: property_schema['description'] = variable['description'] if 'options' in variable: property_schema['enum'] = variable['options'] if 'default' in variable: property_schema['default'] = variable['default'] return property_schema def generate_config_schema(boilerplate_path: str) -> Dict[str, Any]: with open(boilerplate_path, 'r') as f: boilerplate = yaml.safe_load(f) schema = { '$schema': 'http://json-schema.org/draft-07/schema#', 'type': 'object', 'properties': {}, 'required': [] } if 'variables' in boilerplate: for variable in boilerplate['variables']: var_name = variable['name'] schema['properties'][var_name] = variable_to_schema_property(variable) if 'default' not in variable: schema['required'].append(var_name) if 'dependencies' in boilerplate: for dep in boilerplate['dependencies']: if not dep.get('dont-inherit-variables', False) and 'variables' in dep: for variable in dep['variables']: var_name = variable['name'] schema['properties'][var_name] = variable_to_schema_property(variable) if 'default' not in variable: schema['required'].append(var_name) return schema def write_schema(schema: Dict[str, Any], output_path: str): with open(output_path, 'w') as f: json.dump(schema, f, indent=2) if __name__ == '__main__': import sys if len(sys.argv) != 3: print("Usage: python config_schema_generator.py <boilerplate.yml> <output.json>") sys.exit(1) schema = generate_config_schema(sys.argv[1]) write_schema(schema, sys.argv[2]) print(f"Schema generated successfully at {sys.argv[2]}")
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Consider having YAML schema as release asset and decouple it from the CLI commands.
Either that, or put them in a directory in this repo, and refer to the GitHub "raw" URLs.
Quick script
Run with
uv run hello.py
:The text was updated successfully, but these errors were encountered: