summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/generate_python_boilerplate.py111
1 files changed, 3 insertions, 108 deletions
diff --git a/scripts/generate_python_boilerplate.py b/scripts/generate_python_boilerplate.py
index dc51dae..a03aa2b 100644
--- a/scripts/generate_python_boilerplate.py
+++ b/scripts/generate_python_boilerplate.py
@@ -56,38 +56,6 @@ def generate_typed_dict() -> str:
return "\n".join(lines)
-def generate_function_signature() -> str:
- """Generate function signature for update_config and create_config_from_args"""
- params = []
-
- for field_name, field_def in CONFIG_SCHEMA_DEF.items():
- python_type = get_python_type(ConfigFieldType(field_def["fieldType"]))
- default = field_def["default"]
-
- # Format default value
- if isinstance(default, str):
- default_str = f'"{default}"'
- elif isinstance(default, bool):
- default_str = str(default)
- else:
- default_str = str(default)
-
- params.append(f"{field_name}: {python_type} = {default_str}")
-
- return ",\n ".join(params)
-
-
-def generate_config_dict_creation() -> str:
- """Generate dictionary creation for create_config_from_args"""
- lines = [" return cast(ConfigurationData, {"]
-
- for field_name in CONFIG_SCHEMA_DEF.keys():
- lines.append(f' "{field_name}": kwargs.get("{field_name}"),')
-
- lines.append(" })")
- return "\n".join(lines)
-
-
def generate_script_parsing() -> str:
"""Generate script content parsing logic"""
lines = []
@@ -195,17 +163,6 @@ def generate_script_generation() -> str:
return "\n".join(lines)
-def generate_log_statement() -> str:
- """Generate logging statement with all field values"""
- field_parts = []
-
- for field_name in CONFIG_SCHEMA_DEF.keys():
- field_parts.append(f"{field_name}={{{field_name}}}")
-
- log_format = ", ".join(field_parts)
- return f' self.log.info(f"Updated lsfg TOML configuration: {log_format}")'
-
-
def generate_complete_schema_file() -> str:
"""Generate complete config_schema_generated.py file"""
@@ -221,7 +178,7 @@ def generate_complete_schema_file() -> str:
'DO NOT EDIT THIS FILE MANUALLY - it will be overwritten on build',
'"""',
'',
- 'from typing import TypedDict, Dict, Any, Union, cast',
+ 'from typing import TypedDict, Dict, Any, Union',
'from enum import Enum',
'import sys',
'from pathlib import Path',
@@ -267,19 +224,6 @@ def generate_complete_schema_file() -> str:
' return generate_script_lines',
'',
'',
- 'def get_function_parameters() -> str:',
- ' """Return function signature parameters"""',
- f' return """{generate_function_signature()}"""',
- '',
- '',
- 'def create_config_dict(**kwargs) -> ConfigurationData:',
- ' """Create configuration dictionary from keyword arguments"""',
- f'{generate_config_dict_creation().replace(" return cast(ConfigurationData, {", " return cast(ConfigurationData, {").replace(" })", " })")}',
- '',
- '',
- '# Field lists for dynamic operations',
- f'TOML_FIELDS = {[name for name, field in CONFIG_SCHEMA_DEF.items() if field.get("location") == "toml"]}',
- f'SCRIPT_FIELDS = {[name for name, field in CONFIG_SCHEMA_DEF.items() if field.get("location") == "script"]}',
f'ALL_FIELDS = {list(CONFIG_SCHEMA_DEF.keys())}',
''
]
@@ -287,66 +231,17 @@ def generate_complete_schema_file() -> str:
return '\n'.join(lines)
-def generate_complete_configuration_helpers() -> str:
- """Generate configuration_helpers_generated.py file"""
-
- # Generate the log format string using config parameter
- log_parts = []
- for field_name in CONFIG_SCHEMA_DEF.keys():
- log_parts.append(f"{field_name}={{config['{field_name}']}}")
- log_format = ", ".join(log_parts)
-
- lines = [
- '"""',
- 'Auto-generated configuration helper functions from shared_config.py',
- 'DO NOT EDIT THIS FILE MANUALLY - it will be overwritten on build',
- '"""',
- '',
- 'from typing import Dict, Any',
- 'from .config_schema_generated import ConfigurationData, ALL_FIELDS',
- '',
- '',
- 'def log_configuration_update(logger, config: ConfigurationData) -> None:',
- ' """Log configuration update with all field values"""',
- f' logger.info(f"Updated lsfg TOML configuration: {log_format}")',
- '',
- '',
- 'def get_config_field_names() -> list[str]:',
- ' """Get all configuration field names"""',
- ' return ALL_FIELDS.copy()',
- '',
- '',
- 'def extract_config_values(config: ConfigurationData) -> Dict[str, Any]:',
- ' """Extract configuration values as a dictionary"""',
- ' return {field: config[field] for field in ALL_FIELDS}',
- ''
- ]
-
- return '\n'.join(lines)
-
-
def main():
"""Generate complete Python configuration files"""
try:
# Create generated files in py_modules/lsfg_vk/
target_dir = project_root / "py_modules" / "lsfg_vk"
-
+
# Generate the complete schema file
schema_content = generate_complete_schema_file()
schema_file = target_dir / "config_schema_generated.py"
schema_file.write_text(schema_content)
- print(f"āœ… Generated {schema_file.relative_to(project_root)}")
-
- # Generate configuration helpers
- helpers_content = generate_complete_configuration_helpers()
- helpers_file = target_dir / "configuration_helpers_generated.py"
- helpers_file.write_text(helpers_content)
- print(f"āœ… Generated {helpers_file.relative_to(project_root)}")
-
- print(f"\nšŸŽÆ Ready-to-use files generated!")
- print(" Import these in your main files:")
- print(" - from .config_schema_generated import ConfigurationData, get_script_parsing_logic, etc.")
- print(" - from .configuration_helpers_generated import log_configuration_update, etc.")
+ print(f"Generated {schema_file.relative_to(project_root)}")
except Exception as e:
print(f"āŒ Error generating Python files: {e}")