Add a pre-commit for distro_codegen but it does not work yet

This commit is contained in:
Ashwin Bharambe 2024-11-18 15:20:49 -08:00
parent 57a9b4d57f
commit 3aedde2ab4
8 changed files with 66 additions and 4 deletions

View file

@ -6,6 +6,8 @@
import concurrent.futures
import importlib
import subprocess
import sys
from functools import partial
from pathlib import Path
from typing import Iterator
@ -55,6 +57,16 @@ def process_template(template_dir: Path, progress) -> None:
raise e
def check_for_changes() -> bool:
"""Check if there are any uncommitted changes."""
result = subprocess.run(
["git", "diff", "--exit-code"],
cwd=REPO_ROOT,
capture_output=True,
)
return result.returncode != 0
def main():
templates_dir = REPO_ROOT / "llama_stack" / "templates"
@ -76,6 +88,15 @@ def main():
list(executor.map(process_func, template_dirs))
progress.update(task, advance=len(template_dirs))
if check_for_changes():
print(
"Distribution template changes detected. Please commit the changes.",
file=sys.stderr,
)
sys.exit(1)
sys.exit(0)
if __name__ == "__main__":
main()

View file

@ -75,7 +75,7 @@ def get_distribution_template() -> DistributionTemplate:
default_shields=[ShieldInput(shield_id="${env.SAFETY_MODEL}")],
),
},
docker_compose_env_vars={
run_config_env_vars={
"LLAMASTACK_PORT": (
"5001",
"Port for the Llama Stack distribution server",

View file

@ -63,7 +63,7 @@ def get_distribution_template() -> DistributionTemplate:
default_shields=[ShieldInput(shield_id="${env.SAFETY_MODEL}")],
),
},
docker_compose_env_vars={
run_config_env_vars={
"LLAMASTACK_PORT": (
"5001",
"Port for the Llama Stack distribution server",

View file

@ -71,7 +71,7 @@ def get_distribution_template() -> DistributionTemplate:
default_shields=[ShieldInput(shield_id="${env.SAFETY_MODEL}")],
),
},
docker_compose_env_vars={
run_config_env_vars={
"LLAMASTACK_PORT": (
"5001",
"Port for the Llama Stack distribution server",