From 29f1fa6abd4b490d6855c2ae18fcdbb10494323e Mon Sep 17 00:00:00 2001 From: Charlie Doern Date: Mon, 17 Nov 2025 16:23:43 -0500 Subject: [PATCH] test(api): pre-commit check to ensure API does not import llama_stack (#4160) # What does this PR do? since llama_stack_api is meant to be _just_ the API definitions of LLS, we should have pre-commit check that prohibits anyone from accidentally importing `from llama_stack` or adding `llama_stack` as a dependency into `llama_stack_api`s pyproject. ## Test Plan pre-commit should pass. Signed-off-by: Charlie Doern --- .pre-commit-config.yaml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c31a39406..f94356fe5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -199,6 +199,27 @@ repos: echo; exit 1; } || true + - id: check-api-independence + name: Ensure llama_stack_api does not import llama_stack + entry: bash + language: system + pass_filenames: false + require_serial: true + always_run: true + files: ^src/llama_stack_api/.*$ + args: + - -c + - | + API_DIR="src/llama_stack_api" + grep -rn --include="*.py" -E '^[^#]*(import llama_stack\b|from llama_stack\b)' "$API_DIR" 2>/dev/null && { + echo "llama_stack_api must not import llama_stack"; + exit 1; + } + [ -f "$API_DIR/pyproject.toml" ] && grep -n 'llama_stack[^_]' "$API_DIR/pyproject.toml" && { + echo "llama_stack_api must not depend on llama_stack in pyproject.toml"; + exit 1; + } + exit 0 ci: autofix_commit_msg: 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks