|
1 | | -from .gmail import GmailLoaderComponent |
2 | | -from .google_bq_sql_executor import BigQueryExecutorComponent |
3 | | -from .google_drive import GoogleDriveComponent |
4 | | -from .google_drive_docs_parser import GoogleDriveDocsParserSA |
5 | | -from .google_drive_docs_watcher import GoogleDriveDocsWatcher |
6 | | -from .google_drive_search import GoogleDriveSearchComponent |
7 | | -from .google_generative_ai import GoogleGenerativeAIComponent |
8 | | -from .google_generative_ai_embeddings import GoogleGenerativeAIEmbeddingsComponent |
9 | | -from .google_oauth_token import GoogleOAuthToken |
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import TYPE_CHECKING, Any |
| 4 | + |
| 5 | +from langbuilder.components._importing import import_mod |
| 6 | + |
| 7 | +if TYPE_CHECKING: |
| 8 | + from langbuilder.components.google.gmail import GmailLoaderComponent |
| 9 | + from langbuilder.components.google.google_bq_sql_executor import BigQueryExecutorComponent |
| 10 | + from langbuilder.components.google.google_drive import GoogleDriveComponent |
| 11 | + from langbuilder.components.google.google_drive_docs_parser import GoogleDriveDocsParserSA |
| 12 | + from langbuilder.components.google.google_drive_docs_watcher import GoogleDriveDocsWatcher |
| 13 | + from langbuilder.components.google.google_drive_search import GoogleDriveSearchComponent |
| 14 | + from langbuilder.components.google.google_generative_ai import GoogleGenerativeAIComponent |
| 15 | + from langbuilder.components.google.google_generative_ai_embeddings import GoogleGenerativeAIEmbeddingsComponent |
| 16 | + from langbuilder.components.google.google_oauth_token import GoogleOAuthToken |
| 17 | + |
| 18 | +_dynamic_imports = { |
| 19 | + "GmailLoaderComponent": "gmail", |
| 20 | + "BigQueryExecutorComponent": "google_bq_sql_executor", |
| 21 | + "GoogleDriveComponent": "google_drive", |
| 22 | + "GoogleDriveDocsParserSA": "google_drive_docs_parser", |
| 23 | + "GoogleDriveDocsWatcher": "google_drive_docs_watcher", |
| 24 | + "GoogleDriveSearchComponent": "google_drive_search", |
| 25 | + "GoogleGenerativeAIComponent": "google_generative_ai", |
| 26 | + "GoogleGenerativeAIEmbeddingsComponent": "google_generative_ai_embeddings", |
| 27 | + "GoogleOAuthToken": "google_oauth_token", |
| 28 | +} |
10 | 29 |
|
11 | 30 | __all__ = [ |
12 | | - "BigQueryExecutorComponent", |
13 | 31 | "GmailLoaderComponent", |
| 32 | + "BigQueryExecutorComponent", |
14 | 33 | "GoogleDriveComponent", |
15 | 34 | "GoogleDriveDocsParserSA", |
16 | 35 | "GoogleDriveDocsWatcher", |
|
19 | 38 | "GoogleGenerativeAIEmbeddingsComponent", |
20 | 39 | "GoogleOAuthToken", |
21 | 40 | ] |
| 41 | + |
| 42 | + |
| 43 | +def __getattr__(attr_name: str) -> Any: |
| 44 | + """Lazily import Google components on attribute access.""" |
| 45 | + if attr_name not in _dynamic_imports: |
| 46 | + msg = f"module '{__name__}' has no attribute '{attr_name}'" |
| 47 | + raise AttributeError(msg) |
| 48 | + try: |
| 49 | + result = import_mod(attr_name, _dynamic_imports[attr_name], __spec__.parent) |
| 50 | + except (ModuleNotFoundError, ImportError, AttributeError) as e: |
| 51 | + msg = f"Could not import '{attr_name}' from '{__name__}': {e}" |
| 52 | + raise AttributeError(msg) from e |
| 53 | + globals()[attr_name] = result |
| 54 | + return result |
| 55 | + |
| 56 | + |
| 57 | +def __dir__() -> list[str]: |
| 58 | + return list(__all__) |
0 commit comments