From c9b50b7e5b12daeb1b265369345013814d67d5d6 Mon Sep 17 00:00:00 2001 From: Charlie Doern Date: Wed, 3 Dec 2025 17:05:47 -0500 Subject: [PATCH] fix: check if distro dirs exist before listing (#4301) # What does this PR do? DISTRO_DIR and DISTRIBS_BASE_DIR need to exist for them to be iterated. our current logic allows us to iterdir without checking if they exist ## Test Plan rm ~/.llama/distributions ``` llama stack list-deps starter --format uv | sh Using Python 3.12.11 environment at: venv Audited 51 packages in 12ms Using Python 3.12.11 environment at: venv Audited 3 packages in 2ms Using Python 3.12.11 environment at: venv Audited 1 package in 3ms Using Python 3.12.11 environment at: venv Audited 3 packages in 5ms ``` Signed-off-by: Charlie Doern --- src/llama_stack/core/utils/config_resolution.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/llama_stack/core/utils/config_resolution.py b/src/llama_stack/core/utils/config_resolution.py index 2a85837b6..946497e2a 100644 --- a/src/llama_stack/core/utils/config_resolution.py +++ b/src/llama_stack/core/utils/config_resolution.py @@ -111,15 +111,14 @@ Did you mean one of these distributions? def _get_available_distros() -> list[str]: """Get list of available distro names.""" - if not DISTRO_DIR.exists() and not DISTRIBS_BASE_DIR.exists(): - return [] - return list( - set( - [d.name for d in DISTRO_DIR.iterdir() if d.is_dir() and not d.name.startswith(".")] - + [d.name for d in DISTRIBS_BASE_DIR.iterdir() if d.is_dir() and not d.name.startswith(".")] - ) - ) + distros = [] + if DISTRO_DIR.exists(): + distros.extend([d.name for d in DISTRO_DIR.iterdir() if d.is_dir() and not d.name.startswith(".")]) + if DISTRIBS_BASE_DIR.exists(): + distros.extend([d.name for d in DISTRIBS_BASE_DIR.iterdir() if d.is_dir() and not d.name.startswith(".")]) + + return list(set(distros)) def _format_distro_suggestions(distros: list[str], user_input: str) -> str: