1.1 changes
This commit is contained in:
127
build.py
127
build.py
@@ -10,13 +10,17 @@ Modes:
|
||||
|
||||
Usage:
|
||||
python build.py dev
|
||||
python build.py dev --cfg amar
|
||||
python build.py deploy --output /path/to/deploy/
|
||||
python build.py models
|
||||
|
||||
Examples:
|
||||
# Set up dev environment
|
||||
# Set up dev environment (soleprint only)
|
||||
python build.py dev
|
||||
|
||||
# Set up dev environment with amar room config
|
||||
python build.py dev --cfg amar
|
||||
|
||||
# Build for deployment
|
||||
python build.py deploy --output ../deploy/soleprint/
|
||||
|
||||
@@ -83,7 +87,7 @@ def generate_models(output_dir: Path):
|
||||
Args:
|
||||
output_dir: Directory where models/pydantic/__init__.py will be created
|
||||
"""
|
||||
config_path = SPR_ROOT / "config" / "soleprint.config.json"
|
||||
config_path = SPR_ROOT / "cfg" / "soleprint.config.json"
|
||||
|
||||
if not config_path.exists():
|
||||
print(f"Warning: Config not found at {config_path}")
|
||||
@@ -111,35 +115,74 @@ def generate_models(output_dir: Path):
|
||||
return result.returncode == 0
|
||||
|
||||
|
||||
def build_dev(output_dir: Path):
|
||||
def copy_cfg(output_dir: Path, cfg_name: str | None):
|
||||
"""Copy configuration files to output directory.
|
||||
|
||||
Args:
|
||||
output_dir: Target directory
|
||||
cfg_name: Name of room config (e.g., 'amar'), or None for base only
|
||||
"""
|
||||
cfg_dir = output_dir / "cfg"
|
||||
ensure_dir(cfg_dir)
|
||||
|
||||
# Always copy base config
|
||||
base_config = SPR_ROOT / "cfg" / "soleprint.config.json"
|
||||
if base_config.exists():
|
||||
copy_path(base_config, cfg_dir / "soleprint.config.json")
|
||||
|
||||
# Copy room-specific config if specified
|
||||
if cfg_name:
|
||||
room_cfg = SPR_ROOT / "cfg" / cfg_name
|
||||
if room_cfg.exists() and room_cfg.is_dir():
|
||||
print(f"\nCopying {cfg_name} room config...")
|
||||
for item in room_cfg.iterdir():
|
||||
if item.name == ".env.example":
|
||||
# Copy .env.example to output root as template
|
||||
copy_path(item, output_dir / ".env.example")
|
||||
elif item.is_dir():
|
||||
copy_path(item, cfg_dir / cfg_name / item.name)
|
||||
else:
|
||||
ensure_dir(cfg_dir / cfg_name)
|
||||
copy_path(item, cfg_dir / cfg_name / item.name)
|
||||
else:
|
||||
print(f"Warning: Room config '{cfg_name}' not found at {room_cfg}")
|
||||
|
||||
|
||||
def build_dev(output_dir: Path, cfg_name: str | None = None):
|
||||
"""
|
||||
Build for development using symlinks.
|
||||
|
||||
Structure:
|
||||
gen/
|
||||
├── main.py -> ../hub/main.py
|
||||
├── index.html -> ../hub/index.html
|
||||
├── requirements.txt -> ../hub/requirements.txt
|
||||
├── dataloader/ -> ../hub/dataloader/
|
||||
├── main.py -> ../soleprint/main.py
|
||||
├── run.py -> ../soleprint/run.py
|
||||
├── index.html -> ../soleprint/index.html
|
||||
├── requirements.txt -> ../soleprint/requirements.txt
|
||||
├── dataloader/ -> ../soleprint/dataloader/
|
||||
├── artery/ -> ../artery/
|
||||
├── atlas/ -> ../atlas/
|
||||
├── station/ -> ../station/
|
||||
├── data/ -> ../data/
|
||||
├── cfg/ # Copied config
|
||||
├── .env.example # From cfg/<room>/.env.example
|
||||
└── models/ # Generated
|
||||
"""
|
||||
print(f"\n=== Building DEV environment ===")
|
||||
print(f"SPR root: {SPR_ROOT}")
|
||||
print(f"Output: {output_dir}")
|
||||
if cfg_name:
|
||||
print(f"Room cfg: {cfg_name}")
|
||||
|
||||
ensure_dir(output_dir)
|
||||
|
||||
# Hub files (symlinks)
|
||||
print("\nLinking hub files...")
|
||||
hub = SPR_ROOT / "hub"
|
||||
create_symlink(hub / "main.py", output_dir / "main.py")
|
||||
create_symlink(hub / "index.html", output_dir / "index.html")
|
||||
create_symlink(hub / "requirements.txt", output_dir / "requirements.txt")
|
||||
create_symlink(hub / "dataloader", output_dir / "dataloader")
|
||||
# Soleprint core files (symlinks)
|
||||
print("\nLinking soleprint files...")
|
||||
soleprint = SPR_ROOT / "soleprint"
|
||||
create_symlink(soleprint / "main.py", output_dir / "main.py")
|
||||
create_symlink(soleprint / "run.py", output_dir / "run.py")
|
||||
create_symlink(soleprint / "index.html", output_dir / "index.html")
|
||||
create_symlink(soleprint / "requirements.txt", output_dir / "requirements.txt")
|
||||
create_symlink(soleprint / "dataloader", output_dir / "dataloader")
|
||||
|
||||
# System directories (symlinks)
|
||||
print("\nLinking systems...")
|
||||
@@ -152,6 +195,10 @@ def build_dev(output_dir: Path):
|
||||
print("\nLinking data...")
|
||||
create_symlink(SPR_ROOT / "data", output_dir / "data")
|
||||
|
||||
# Config (copy, not symlink - may be customized)
|
||||
print("\nCopying config...")
|
||||
copy_cfg(output_dir, cfg_name)
|
||||
|
||||
# Models (generated) - pass output_dir, modelgen adds models/pydantic
|
||||
print("\nGenerating models...")
|
||||
if not generate_models(output_dir):
|
||||
@@ -162,16 +209,19 @@ def build_dev(output_dir: Path):
|
||||
print(f" cd {output_dir}")
|
||||
print(f" python3 -m venv .venv")
|
||||
print(f" .venv/bin/pip install -r requirements.txt")
|
||||
print(f" .venv/bin/python main.py")
|
||||
print(f" .venv/bin/python main.py # Multi-port (production-like)")
|
||||
print(f" .venv/bin/python run.py # Single-port (bare-metal dev)")
|
||||
|
||||
|
||||
def build_deploy(output_dir: Path):
|
||||
def build_deploy(output_dir: Path, cfg_name: str | None = None):
|
||||
"""
|
||||
Build for deployment by copying all files (no symlinks).
|
||||
"""
|
||||
print(f"\n=== Building DEPLOY package ===")
|
||||
print(f"SPR root: {SPR_ROOT}")
|
||||
print(f"Output: {output_dir}")
|
||||
if cfg_name:
|
||||
print(f"Room cfg: {cfg_name}")
|
||||
|
||||
if output_dir.exists():
|
||||
response = input(f"\nOutput directory exists. Overwrite? [y/N] ")
|
||||
@@ -182,13 +232,14 @@ def build_deploy(output_dir: Path):
|
||||
|
||||
ensure_dir(output_dir)
|
||||
|
||||
# Hub files (copy)
|
||||
print("\nCopying hub files...")
|
||||
hub = SPR_ROOT / "hub"
|
||||
copy_path(hub / "main.py", output_dir / "main.py")
|
||||
copy_path(hub / "index.html", output_dir / "index.html")
|
||||
copy_path(hub / "requirements.txt", output_dir / "requirements.txt")
|
||||
copy_path(hub / "dataloader", output_dir / "dataloader")
|
||||
# Soleprint core files (copy)
|
||||
print("\nCopying soleprint files...")
|
||||
soleprint = SPR_ROOT / "soleprint"
|
||||
copy_path(soleprint / "main.py", output_dir / "main.py")
|
||||
copy_path(soleprint / "run.py", output_dir / "run.py")
|
||||
copy_path(soleprint / "index.html", output_dir / "index.html")
|
||||
copy_path(soleprint / "requirements.txt", output_dir / "requirements.txt")
|
||||
copy_path(soleprint / "dataloader", output_dir / "dataloader")
|
||||
|
||||
# System directories (copy)
|
||||
print("\nCopying systems...")
|
||||
@@ -201,6 +252,10 @@ def build_deploy(output_dir: Path):
|
||||
print("\nCopying data...")
|
||||
copy_path(SPR_ROOT / "data", output_dir / "data")
|
||||
|
||||
# Config (copy)
|
||||
print("\nCopying config...")
|
||||
copy_cfg(output_dir, cfg_name)
|
||||
|
||||
# Models (generate fresh) - pass output_dir, modelgen adds models/pydantic
|
||||
print("\nGenerating models...")
|
||||
if not generate_models(output_dir):
|
||||
@@ -215,7 +270,7 @@ def build_deploy(output_dir: Path):
|
||||
copy_path(SPR_ROOT / "schema.json", output_dir / "schema.json")
|
||||
|
||||
# Create run script
|
||||
run_script = output_dir / "run.sh"
|
||||
run_script = output_dir / "start.sh"
|
||||
run_script.write_text("""#!/bin/bash
|
||||
# Soleprint runner
|
||||
cd "$(dirname "$0")"
|
||||
@@ -230,16 +285,16 @@ echo "Starting soleprint on http://localhost:12000"
|
||||
.venv/bin/python main.py
|
||||
""")
|
||||
run_script.chmod(0o755)
|
||||
print(" Created: run.sh")
|
||||
print(" Created: start.sh")
|
||||
|
||||
total_files = count_files(output_dir)
|
||||
print(f"\n✓ Deploy build complete! ({total_files} files)")
|
||||
print(f"\nTo run:")
|
||||
print(f" cd {output_dir}")
|
||||
print(f" ./run.sh")
|
||||
print(f" ./start.sh")
|
||||
print(f"\nOr deploy to server:")
|
||||
print(f" rsync -av {output_dir}/ server:/app/soleprint/")
|
||||
print(f" ssh server 'cd /app/soleprint && ./run.sh'")
|
||||
print(f" ssh server 'cd /app/soleprint && ./start.sh'")
|
||||
|
||||
|
||||
def build_models():
|
||||
@@ -274,6 +329,13 @@ def main():
|
||||
default=SPR_ROOT / "gen",
|
||||
help="Output directory (default: gen/)",
|
||||
)
|
||||
dev_parser.add_argument(
|
||||
"--cfg",
|
||||
"-c",
|
||||
type=str,
|
||||
default=None,
|
||||
help="Room config to include (e.g., 'amar')",
|
||||
)
|
||||
|
||||
# deploy command
|
||||
deploy_parser = subparsers.add_parser(
|
||||
@@ -286,6 +348,13 @@ def main():
|
||||
required=True,
|
||||
help="Output directory for deployment package",
|
||||
)
|
||||
deploy_parser.add_argument(
|
||||
"--cfg",
|
||||
"-c",
|
||||
type=str,
|
||||
default=None,
|
||||
help="Room config to include (e.g., 'amar')",
|
||||
)
|
||||
|
||||
# models command
|
||||
subparsers.add_parser("models", help="Only regenerate models")
|
||||
@@ -293,9 +362,9 @@ def main():
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.command == "dev":
|
||||
build_dev(args.output.resolve())
|
||||
build_dev(args.output.resolve(), args.cfg)
|
||||
elif args.command == "deploy":
|
||||
build_deploy(args.output.resolve())
|
||||
build_deploy(args.output.resolve(), args.cfg)
|
||||
elif args.command == "models":
|
||||
build_models()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user