From 69471164e636fab5c1d1150cd5db1e0904292ae9 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sun, 22 Mar 2026 15:13:55 +0000 Subject: [PATCH] Initial upload: EnvSchema v0.1.0 with CI/CD workflow --- envschema/generator.py | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 envschema/generator.py diff --git a/envschema/generator.py b/envschema/generator.py new file mode 100644 index 0000000..9df8980 --- /dev/null +++ b/envschema/generator.py @@ -0,0 +1,57 @@ +"""Generator for .env.example files from schema definitions.""" + +from envschema.schema import Schema + + +def generate_env_example(schema: Schema, include_descriptions: bool = True) -> str: + """Generate an .env.example file content from a schema. + + Args: + schema: The schema to generate from. + include_descriptions: Whether to include description comments. + + Returns: + Formatted .env.example content. + """ + lines = [] + + lines.append("# Environment Variables Schema") + if schema.version: + lines.append(f"# Version: {schema.version}") + lines.append("") + + for var in schema.envvars: + if include_descriptions and var.description: + lines.append(f"# {var.description}") + + if var.required: + lines.append(f"# REQUIRED") + elif var.default is not None: + lines.append(f"# Default: {var.default}") + + default_part = f"# {var.default}" if var.default else "" + type_part = f"[{var.type.value}]" + + if var.required: + lines.append(f"{var.name}=") + elif var.default is not None: + lines.append(f"{var.name}={var.default}") + else: + lines.append(f"{var.name}=") + + lines.append("") + + return "\n".join(lines) + + +def generate_env_example_to_file(schema: Schema, output_path: str, include_descriptions: bool = True) -> None: + """Generate and write an .env.example file. + + Args: + schema: The schema to generate from. + output_path: Path to write the .env.example file. + include_descriptions: Whether to include description comments. + """ + content = generate_env_example(schema, include_descriptions) + with open(output_path, "w") as f: + f.write(content) \ No newline at end of file