Home / File/ test_imports.py — langchain Source File

test_imports.py — langchain Source File

Architecture documentation for test_imports.py, a python file in the langchain codebase. 6 imports, 0 dependents.

File python CoreAbstractions MessageSchema 6 imports 6 functions

Entity Profile

Dependency Diagram

graph LR
  67bfb74f_3a86_62e3_0898_e080076e1cc0["test_imports.py"]
  d68b71f1_2253_da0f_5a2f_31c9bb5e42f0["ast"]
  67bfb74f_3a86_62e3_0898_e080076e1cc0 --> d68b71f1_2253_da0f_5a2f_31c9bb5e42f0
  3888b2bf_bffe_7c16_770f_a406d400119c["importlib"]
  67bfb74f_3a86_62e3_0898_e080076e1cc0 --> 3888b2bf_bffe_7c16_770f_a406d400119c
  0c635125_6987_b8b3_7ff7_d60249aecde7["warnings"]
  67bfb74f_3a86_62e3_0898_e080076e1cc0 --> 0c635125_6987_b8b3_7ff7_d60249aecde7
  01d44b95_02da_6b59_b6ed_842bc82dfa56["importlib.util"]
  67bfb74f_3a86_62e3_0898_e080076e1cc0 --> 01d44b95_02da_6b59_b6ed_842bc82dfa56
  b6ee5de5_719a_eeb5_1e11_e9c63bc22ef8["pathlib"]
  67bfb74f_3a86_62e3_0898_e080076e1cc0 --> b6ee5de5_719a_eeb5_1e11_e9c63bc22ef8
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  67bfb74f_3a86_62e3_0898_e080076e1cc0 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  style 67bfb74f_3a86_62e3_0898_e080076e1cc0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import ast
import importlib
import warnings
from importlib.util import find_spec
from pathlib import Path
from typing import Any

# Attempt to recursively import all modules in langchain
PKG_ROOT = Path(__file__).parent.parent.parent

COMMUNITY_NOT_INSTALLED = find_spec("langchain_community") is None


def test_import_all() -> None:
    """Generate the public API for this package."""
    with warnings.catch_warnings():
        warnings.filterwarnings(action="ignore", category=UserWarning)
        library_code = PKG_ROOT / "langchain_classic"
        for path in library_code.rglob("*.py"):
            # Calculate the relative path to the module
            module_name = (
                path.relative_to(PKG_ROOT).with_suffix("").as_posix().replace("/", ".")
            )
            if module_name.endswith("__init__"):
                # Without init
                module_name = module_name.rsplit(".", 1)[0]

            mod = importlib.import_module(module_name)

            all_attrs = getattr(mod, "__all__", [])

            for name in all_attrs:
                # Attempt to import the name from the module
                try:
                    obj = getattr(mod, name)
                    assert obj is not None
                except ModuleNotFoundError as e:
                    # If the module is not installed, we suppress the error
                    if (
                        "Module langchain_community" in str(e)
                        and COMMUNITY_NOT_INSTALLED
                    ):
                        pass
                except Exception as e:
                    msg = f"Could not import {module_name}.{name}"
                    raise AssertionError(msg) from e


def test_import_all_using_dir() -> None:
    """Generate the public API for this package."""
    library_code = PKG_ROOT / "langchain_classic"
    for path in library_code.rglob("*.py"):
        # Calculate the relative path to the module
        module_name = (
            path.relative_to(PKG_ROOT).with_suffix("").as_posix().replace("/", ".")
        )
        if module_name.endswith("__init__"):
            # Without init
            module_name = module_name.rsplit(".", 1)[0]

// ... (106 more lines)

Subdomains

Dependencies

  • ast
  • importlib
  • importlib.util
  • pathlib
  • typing
  • warnings

Frequently Asked Questions

What does test_imports.py do?
test_imports.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, MessageSchema subdomain.
What functions are defined in test_imports.py?
test_imports.py defines 6 function(s): _dict_from_ast, _literal_eval_str, extract_deprecated_lookup, test_import_all, test_import_all_using_dir, test_no_more_changes_to_proxy_community.
What does test_imports.py depend on?
test_imports.py imports 6 module(s): ast, importlib, importlib.util, pathlib, typing, warnings.
Where is test_imports.py in the architecture?
test_imports.py is located at libs/langchain/tests/unit_tests/test_imports.py (domain: CoreAbstractions, subdomain: MessageSchema, directory: libs/langchain/tests/unit_tests).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free