File tree Expand file tree Collapse file tree
src/google/adk/dependencies Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212# See the License for the specific language governing permissions and
1313# limitations under the License.
14+ """Lazy import shim for Vertex AI optional dependencies."""
1415
1516from __future__ import annotations
1617
17- import vertexai
18- from vertexai .preview import example_stores
19- from vertexai .preview import rag
18+ try :
19+ import vertexai
20+ from vertexai .preview import example_stores
21+ from vertexai .preview import rag
22+ except ImportError as e :
23+ raise ImportError (
24+ "Vertex AI features require google-adk[gcp] or google-adk[all]. "
25+ "Install one of those extras to use google.adk.dependencies.vertexai."
26+ ) from e
27+
28+ __all__ = ["example_stores" , "rag" , "vertexai" ]
Original file line number Diff line number Diff line change 2020
2121from __future__ import annotations
2222
23+ import importlib .util
2324import os
2425from pathlib import Path
2526import subprocess
@@ -167,6 +168,25 @@ def test_vertex_ai_session_service_fails_on_creation():
167168 assert "google-cloud-aiplatform" in str (exc_info .value )
168169
169170
171+ def test_vertexai_dependency_shim_raises_clear_importerror ():
172+ """Verify that the Vertex AI dependency shim points users to the gcp extra."""
173+ with mock .patch .dict ("sys.modules" , {"vertexai" : None }):
174+ module_path = _REPO_ROOT / "src/google/adk/dependencies/vertexai.py"
175+ spec = importlib .util .spec_from_file_location (
176+ "_test_google_adk_dependencies_vertexai" , module_path
177+ )
178+ assert spec is not None
179+ assert spec .loader is not None
180+ module = importlib .util .module_from_spec (spec )
181+
182+ with pytest .raises (ImportError ) as exc_info :
183+ spec .loader .exec_module (module )
184+
185+ message = str (exc_info .value )
186+ assert "google-adk[gcp]" in message
187+ assert "google-adk[all]" in message
188+
189+
170190# =============================================================================
171191# Approach 2: High-Fidelity Integration Tests (Clean Venv, Skipped by Default)
172192# =============================================================================
You can’t perform that action at this time.
0 commit comments