Skip to content

Commit 6a8c2ae

Browse files
authored
[CLI] remove dependency on CONDA_PREFIX in CLI (meta-llama#144)
* remove dependency on CONDA_PREFIX in CLI * lint * typo * more robust
1 parent fe460ba commit 6a8c2ae

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
lines changed

llama_stack/cli/stack/build.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,7 @@ def _run_stack_build_command_from_build_config(
100100
llama_stack_path / "tmp/configs/"
101101
)
102102
else:
103-
build_dir = (
104-
Path(os.getenv("CONDA_PREFIX")).parent
105-
/ f"llamastack-{build_config.name}"
106-
)
103+
build_dir = DISTRIBS_BASE_DIR / f"llamastack-{build_config.name}"
107104

108105
os.makedirs(build_dir, exist_ok=True)
109106
build_file_path = build_dir / f"{build_config.name}-build.yaml"
@@ -116,11 +113,6 @@ def _run_stack_build_command_from_build_config(
116113
if return_code != 0:
117114
return
118115

119-
cprint(
120-
f"Build spec configuration saved at {str(build_file_path)}",
121-
color="blue",
122-
)
123-
124116
configure_name = (
125117
build_config.name
126118
if build_config.image_type == "conda"

llama_stack/cli/stack/configure.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,27 @@ def _run_stack_configure_cmd(self, args: argparse.Namespace) -> None:
6565
f"Could not find {build_config_file}. Trying conda build name instead...",
6666
color="green",
6767
)
68-
if os.getenv("CONDA_PREFIX"):
68+
if os.getenv("CONDA_PREFIX", ""):
6969
conda_dir = (
7070
Path(os.getenv("CONDA_PREFIX")).parent / f"llamastack-{args.config}"
7171
)
72-
build_config_file = Path(conda_dir) / f"{args.config}-build.yaml"
72+
else:
73+
cprint(
74+
"Cannot find CONDA_PREFIX. Trying default conda path ~/.conda/envs...",
75+
color="green",
76+
)
77+
conda_dir = (
78+
Path(os.path.expanduser("~/.conda/envs")) / f"llamastack-{args.config}"
79+
)
7380

74-
if build_config_file.exists():
75-
with open(build_config_file, "r") as f:
76-
build_config = BuildConfig(**yaml.safe_load(f))
81+
build_config_file = Path(conda_dir) / f"{args.config}-build.yaml"
7782

78-
self._configure_llama_distribution(build_config, args.output_dir)
79-
return
83+
if build_config_file.exists():
84+
with open(build_config_file, "r") as f:
85+
build_config = BuildConfig(**yaml.safe_load(f))
86+
87+
self._configure_llama_distribution(build_config, args.output_dir)
88+
return
8089

8190
# if we get here, we need to try to find the docker image
8291
cprint(

llama_stack/distribution/build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def build_image(build_config: BuildConfig, build_file_path: Path):
9292
args = [
9393
script,
9494
build_config.name,
95+
str(build_file_path),
9596
" ".join(deps),
9697
]
9798

llama_stack/distribution/build_conda_env.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ if [ -n "$LLAMA_MODELS_DIR" ]; then
1717
echo "Using llama-models-dir=$LLAMA_MODELS_DIR"
1818
fi
1919

20-
if [ "$#" -lt 2 ]; then
21-
echo "Usage: $0 <distribution_type> <build_name> <pip_dependencies> [<special_pip_deps>]" >&2
22-
echo "Example: $0 <distribution_type> mybuild 'numpy pandas scipy'" >&2
20+
if [ "$#" -lt 3 ]; then
21+
echo "Usage: $0 <distribution_type> <build_name> <build_file_path> <pip_dependencies> [<special_pip_deps>]" >&2
22+
echo "Example: $0 <distribution_type> mybuild ./my-stack-build.yaml 'numpy pandas scipy'" >&2
2323
exit 1
2424
fi
2525

@@ -29,7 +29,8 @@ set -euo pipefail
2929

3030
build_name="$1"
3131
env_name="llamastack-$build_name"
32-
pip_dependencies="$2"
32+
build_file_path="$2"
33+
pip_dependencies="$3"
3334

3435
# Define color codes
3536
RED='\033[0;31m'
@@ -123,6 +124,9 @@ ensure_conda_env_python310() {
123124
done
124125
fi
125126
fi
127+
128+
mv $build_file_path $CONDA_PREFIX/
129+
echo "Build spec configuration saved at $CONDA_PREFIX/$build_name-build.yaml"
126130
}
127131

128132
ensure_conda_env_python310 "$env_name" "$pip_dependencies" "$special_pip_deps"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy