|
5 | 5 | # the root directory of this source tree. |
6 | 6 |
|
7 | 7 | import argparse |
| 8 | +import tomllib |
8 | 9 | from io import StringIO |
| 10 | +from pathlib import Path |
9 | 11 | from unittest.mock import patch |
10 | 12 |
|
11 | 13 | from llama_stack.cli.stack._list_deps import ( |
|
14 | 16 | ) |
15 | 17 |
|
16 | 18 |
|
| 19 | +def _package_names(dependencies: list[str]) -> set[str]: |
| 20 | + return { |
| 21 | + dependency.split("[", 1)[0].split("<", 1)[0].split(">", 1)[0].split("=", 1)[0] for dependency in dependencies |
| 22 | + } |
| 23 | + |
| 24 | + |
| 25 | +def _output_deps(output: str) -> set[str]: |
| 26 | + return {dependency.strip("'") for dependency in output.split()} |
| 27 | + |
| 28 | + |
| 29 | +def test_base_dependencies_do_not_include_oci(): |
| 30 | + pyproject = tomllib.loads(Path("pyproject.toml").read_text()) |
| 31 | + base_dependencies = _package_names(pyproject["project"]["dependencies"]) |
| 32 | + oci_extra = _package_names(pyproject["project"]["optional-dependencies"]["oci"]) |
| 33 | + |
| 34 | + assert "oci" not in base_dependencies |
| 35 | + assert "oracledb" not in base_dependencies |
| 36 | + assert "oci" in oci_extra |
| 37 | + assert "oracledb" in oci_extra |
| 38 | + |
| 39 | + |
17 | 40 | def test_stack_list_deps_basic(): |
18 | 41 | args = argparse.Namespace( |
19 | 42 | config=None, |
@@ -51,6 +74,38 @@ def test_stack_list_deps_with_distro_uv(): |
51 | 74 | assert "uv pip install" in output |
52 | 75 |
|
53 | 76 |
|
| 77 | +def test_starter_distro_list_deps_does_not_include_oci(): |
| 78 | + args = argparse.Namespace( |
| 79 | + config="starter", |
| 80 | + env_name=None, |
| 81 | + providers=None, |
| 82 | + format="deps-only", |
| 83 | + ) |
| 84 | + |
| 85 | + with patch("sys.stdout", new_callable=StringIO) as mock_stdout: |
| 86 | + run_stack_list_deps_command(args) |
| 87 | + output = mock_stdout.getvalue() |
| 88 | + |
| 89 | + deps = _output_deps(output) |
| 90 | + assert "oci" not in deps |
| 91 | + assert "oracledb" not in deps |
| 92 | + |
| 93 | + |
| 94 | +def test_explicit_oci_provider_still_lists_oci_dependency(): |
| 95 | + args = argparse.Namespace( |
| 96 | + config=None, |
| 97 | + env_name="test-env", |
| 98 | + providers="inference=remote::oci", |
| 99 | + format="deps-only", |
| 100 | + ) |
| 101 | + |
| 102 | + with patch("sys.stdout", new_callable=StringIO) as mock_stdout: |
| 103 | + run_stack_list_deps_command(args) |
| 104 | + output = mock_stdout.getvalue() |
| 105 | + |
| 106 | + assert "oci" in _output_deps(output) |
| 107 | + |
| 108 | + |
54 | 109 | def test_list_deps_formatting_quotes_only_for_uv(): |
55 | 110 | deps_only = format_output_deps_only(["mcp>=1.23.0"], [], [], uv=False) |
56 | 111 | assert deps_only.strip() == "mcp>=1.23.0" |
|
0 commit comments