From 68d7dc521ea226957e3829e0c6cbe0bdbea9779b Mon Sep 17 00:00:00 2001 From: Charlie Doern Date: Fri, 1 Aug 2025 12:40:40 -0400 Subject: [PATCH] fix: exclude llama-stack when installing external-providers using `--constraint` with `uv pip install` allows us to effectively skip llama-stack if found in an external providers dependencies Signed-off-by: Charlie Doern --- llama_stack/core/build_conda_env.sh | 20 +++++++++++-- llama_stack/core/build_container.sh | 18 ++++++++---- llama_stack/core/build_venv.sh | 44 +++++++++++++++++++++++++---- 3 files changed, 68 insertions(+), 14 deletions(-) diff --git a/llama_stack/core/build_conda_env.sh b/llama_stack/core/build_conda_env.sh index 48ac3a1ab..4084cdb6c 100755 --- a/llama_stack/core/build_conda_env.sh +++ b/llama_stack/core/build_conda_env.sh @@ -143,8 +143,17 @@ ensure_conda_env_python310() { if [ -n "$external_provider_deps" ]; then IFS='#' read -ra parts <<<"$external_provider_deps" for part in "${parts[@]}"; do - echo "$part" - uv pip install "$part" + echo "Installing external provider: $part" + + # Create a temporary constraint file to exclude llama-stack + cat > /tmp/constraints.txt << 'EOF' +# Exclude llama-stack to avoid circular dependencies +llama-stack==0.0.0 +EOF + + # Install the external provider with constraints to exclude llama-stack + uv pip install --constraint /tmp/constraints.txt "$part" + rm -f /tmp/constraints.txt done fi else @@ -193,7 +202,12 @@ try: module = importlib.import_module(f'$package_name.provider') spec = module.get_provider_spec() if hasattr(spec, 'pip_packages') and spec.pip_packages: - print('\\n'.join(spec.pip_packages)) + # Filter out llama-stack from pip_packages to avoid circular dependency + filtered_packages = [pkg for pkg in spec.pip_packages if not pkg.startswith('llama-stack')] + if filtered_packages: + print('\\n'.join(filtered_packages)) + else: + print('No non-llama-stack dependencies found', file=sys.stderr) except Exception as e: print(f'Error getting provider spec for $package_name: {e}', file=sys.stderr) " | uv pip install -r - diff --git a/llama_stack/core/build_container.sh b/llama_stack/core/build_container.sh index 1376aaa28..e52159df4 100755 --- a/llama_stack/core/build_container.sh +++ b/llama_stack/core/build_container.sh @@ -199,10 +199,11 @@ if [ -n "$external_provider_deps" ]; then read -ra pip_args <<< "$part" quoted_deps=$(printf " %q" "${pip_args[@]}") add_to_container < /tmp/constraints.txt && \\ + echo "llama-stack==0.0.0" >> /tmp/constraints.txt && \\ + +RUN python3 - < /tmp/constraints.txt << 'EOF' +# Exclude llama-stack to avoid circular dependencies +llama-stack==0.0.0 +EOF + + # Install the external provider with constraints to exclude llama-stack + uv pip install --constraint /tmp/constraints.txt "$part" + + # Clean up constraint file + rm -f /tmp/constraints.txt done fi else @@ -183,21 +194,42 @@ run() { if [ -n "$external_provider_deps" ]; then IFS='#' read -ra parts <<<"$external_provider_deps" for part in "${parts[@]}"; do - echo "Installing external provider module: $part" - uv pip install "$part" - echo "Getting provider spec for module: $part and installing dependencies" + echo "Installing external provider: $part" + + # Create a temporary constraint file to exclude llama-stack + cat > /tmp/constraints.txt << 'EOF' +# Exclude llama-stack to avoid circular dependencies +llama-stack==0.0.0 +llama-stack-client==0.0.0 +EOF + + # Install the external provider with constraints to exclude llama-stack + uv pip install --constraint /tmp/constraints.txt "$part" + + echo "Getting provider spec for module: $part and installing additional dependencies" package_name=$(echo "$part" | sed 's/[<>=!].*//') + + # Get additional dependencies from the provider spec (excluding llama-stack) python3 -c " import importlib import sys + try: module = importlib.import_module(f'$package_name.provider') spec = module.get_provider_spec() if hasattr(spec, 'pip_packages') and spec.pip_packages: - print('\\n'.join(spec.pip_packages)) + # Filter out llama-stack from pip_packages to avoid circular dependency + filtered_packages = [pkg for pkg in spec.pip_packages if not pkg.startswith('llama-stack')] + if filtered_packages: + print('\\n'.join(filtered_packages)) + else: + print('No additional dependencies needed', file=sys.stderr) except Exception as e: print(f'Error getting provider spec for $package_name: {e}', file=sys.stderr) -" | uv pip install -r - +" | uv pip install --constraint /tmp/constraints.txt -r - + + # Clean up constraint file + rm -f /tmp/constraints.txt done fi fi