MCPcopy Index your code
hub / github.com/github/spec-kit / ensure_constitution_from_template

Function ensure_constitution_from_template

src/specify_cli/commands/init.py:33–69  ·  view source on GitHub ↗

Copy constitution template to memory if it doesn't exist.

(
    project_path: Path, tracker: StepTracker | None = None
)

Source from the content-addressed store, hash-verified

31
32
33def ensure_constitution_from_template(
34 project_path: Path, tracker: StepTracker | None = None
35) -> None:
36 """Copy constitution template to memory if it doesn't exist."""
37 memory_constitution = project_path / ".specify" / "memory" / "constitution.md"
38 template_constitution = (
39 project_path / ".specify" / "templates" / "constitution-template.md"
40 )
41
42 if memory_constitution.exists():
43 if tracker:
44 tracker.add("constitution", "Constitution setup")
45 tracker.skip("constitution", "existing file preserved")
46 return
47
48 if not template_constitution.exists():
49 if tracker:
50 tracker.add("constitution", "Constitution setup")
51 tracker.error("constitution", "template not found")
52 return
53
54 try:
55 memory_constitution.parent.mkdir(parents=True, exist_ok=True)
56 shutil.copy2(template_constitution, memory_constitution)
57 if tracker:
58 tracker.add("constitution", "Constitution setup")
59 tracker.complete("constitution", "copied from template")
60 else:
61 console.print("[cyan]Initialized constitution from template[/cyan]")
62 except Exception as e:
63 if tracker:
64 tracker.add("constitution", "Constitution setup")
65 tracker.error("constitution", str(e))
66 else:
67 console.print(
68 f"[yellow]Warning: Could not initialize constitution: {e}[/yellow]"
69 )
70
71
72def register(app: typer.Typer) -> None:

Callers 1

initFunction · 0.85

Calls 5

skipMethod · 0.80
errorMethod · 0.80
completeMethod · 0.80
printMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected