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. 3 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  6ae87f5b_6e75_8510_cb8b_fd1189257709["test_imports.py"]
  3888b2bf_bffe_7c16_770f_a406d400119c["importlib"]
  6ae87f5b_6e75_8510_cb8b_fd1189257709 --> 3888b2bf_bffe_7c16_770f_a406d400119c
  0c635125_6987_b8b3_7ff7_d60249aecde7["warnings"]
  6ae87f5b_6e75_8510_cb8b_fd1189257709 --> 0c635125_6987_b8b3_7ff7_d60249aecde7
  b6ee5de5_719a_eeb5_1e11_e9c63bc22ef8["pathlib"]
  6ae87f5b_6e75_8510_cb8b_fd1189257709 --> b6ee5de5_719a_eeb5_1e11_e9c63bc22ef8
  style 6ae87f5b_6e75_8510_cb8b_fd1189257709 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import importlib
import warnings
from pathlib import Path

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


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"
        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 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"
    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]

        try:
            mod = importlib.import_module(module_name)
        except ModuleNotFoundError as e:
            msg = f"Could not import {module_name}"
            raise ModuleNotFoundError(msg) from e
        attributes = dir(mod)

        for name in attributes:
            if name.strip().startswith("_"):
                continue
            # Attempt to import the name from the module
            getattr(mod, name)

Subdomains

Dependencies

  • importlib
  • pathlib
  • 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, RunnableInterface subdomain.
What functions are defined in test_imports.py?
test_imports.py defines 2 function(s): test_import_all, test_import_all_using_dir.
What does test_imports.py depend on?
test_imports.py imports 3 module(s): importlib, pathlib, warnings.
Where is test_imports.py in the architecture?
test_imports.py is located at libs/langchain_v1/tests/unit_tests/test_imports.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/langchain_v1/tests/unit_tests).

Analyze Your Own Codebase

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

Try Supermodel Free