setup.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from __future__ import annotations
  2. import subprocess
  3. from pathlib import Path
  4. from setup_helpers import HELPER_REGISTRY
  5. from setup_helpers.base import create_base_repo
  6. def clone_template(template_dir: Path, workdir: Path) -> None:
  7. """Clone (or build) template_dir into workdir with full git history."""
  8. create_base_repo(workdir, template_dir)
  9. def run_helpers(helper_names: list[str], workdir: Path, fixtures_dir: Path) -> None:
  10. for name in helper_names:
  11. helper = HELPER_REGISTRY.get(name)
  12. if helper is None:
  13. raise ValueError(f"Unknown setup helper: {name}")
  14. if name == "create_base_repo":
  15. helper(workdir, fixtures_dir / "template-repo") # ty: ignore[invalid-argument-type, too-many-positional-arguments, missing-argument]
  16. elif name == "symlink_superpowers":
  17. import os
  18. helper(workdir, os.environ["SUPERPOWERS_ROOT"]) # ty: ignore[invalid-argument-type, too-many-positional-arguments, missing-argument]
  19. else:
  20. helper(workdir) # ty: ignore[invalid-argument-type, missing-argument]
  21. def run_assertions(assertions: list[str], workdir: Path) -> None:
  22. for assertion in assertions:
  23. result = subprocess.run(
  24. assertion,
  25. shell=True,
  26. cwd=workdir,
  27. capture_output=True,
  28. text=True,
  29. )
  30. if result.returncode != 0:
  31. raise AssertionError(
  32. f"Setup assertion failed: {assertion}\n"
  33. f"stdout: {result.stdout}\nstderr: {result.stderr}"
  34. )