Files
alfred/scripts/bootstrap.py

44 lines
1.1 KiB
Python

#!/usr/bin/env python3
"""Bootstrap script - generates .env and .env.make from pyproject.toml schema."""
import sys
from pathlib import Path
# Add parent directory to path to import from alfred package
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from alfred.settings_bootstrap import ConfigSource, bootstrap_env
def main():
"""
Initialize .env file from settings schema in pyproject.toml.
- Reads schema from [tool.alfred.settings_schema]
- Generates secrets automatically
- Preserves existing secrets
- Validates all settings
- Writes .env and .env.make
"""
try:
base_dir = Path(__file__).resolve().parent.parent
config_source = ConfigSource.from_base_dir(base_dir)
bootstrap_env(config_source)
except FileNotFoundError as e:
print(f"{e}")
return 1
except ValueError as e:
print(f"❌ Validation error: {e}")
return 1
except Exception as e:
print(f"❌ Bootstrap failed: {e}")
import traceback # noqa: PLC0415
traceback.print_exc()
return 1
return 0
if __name__ == "__main__":
sys.exit(main())