test_imports.py — langchain Source File
Architecture documentation for test_imports.py, a python file in the langchain codebase. 4 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 2367ce97_9885_ee80_4337_fee70cc81e68["test_imports.py"] 082415a8_067b_221f_7984_07d87009267d["concurrent.futures"] 2367ce97_9885_ee80_4337_fee70cc81e68 --> 082415a8_067b_221f_7984_07d87009267d 3888b2bf_bffe_7c16_770f_a406d400119c["importlib"] 2367ce97_9885_ee80_4337_fee70cc81e68 --> 3888b2bf_bffe_7c16_770f_a406d400119c f02b765e_0b79_f1fa_161f_0492d5c24a46["subprocess"] 2367ce97_9885_ee80_4337_fee70cc81e68 --> f02b765e_0b79_f1fa_161f_0492d5c24a46 b6ee5de5_719a_eeb5_1e11_e9c63bc22ef8["pathlib"] 2367ce97_9885_ee80_4337_fee70cc81e68 --> b6ee5de5_719a_eeb5_1e11_e9c63bc22ef8 style 2367ce97_9885_ee80_4337_fee70cc81e68 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import concurrent.futures
import importlib
import subprocess
from pathlib import Path
def test_importable_all() -> None:
for path in Path("../core/langchain_core/").glob("*"):
module_name = path.stem
if (
not module_name.startswith(".")
and path.suffix != ".typed"
and module_name != "pydantic_v1"
):
module = importlib.import_module("langchain_core." + module_name)
all_ = getattr(module, "__all__", [])
for cls_ in all_:
getattr(module, cls_)
def try_to_import(module_name: str) -> tuple[int, str]:
"""Try to import a module via subprocess."""
module = importlib.import_module("langchain_core." + module_name)
all_ = getattr(module, "__all__", [])
for cls_ in all_:
getattr(module, cls_)
result = subprocess.run(
["python", "-c", f"import langchain_core.{module_name}"], check=True
)
return result.returncode, module_name
def test_importable_all_via_subprocess() -> None:
"""Test import in isolation.
!!! note
ImportErrors due to circular imports can be raised for one sequence of imports
but not another.
"""
module_names = []
for path in Path("../core/langchain_core/").glob("*"):
module_name = path.stem
if (
not module_name.startswith(".")
and path.suffix != ".typed"
and module_name != "pydantic_v1"
):
module_names.append(module_name)
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
futures = [
executor.submit(try_to_import, module_name) for module_name in module_names
]
for future in concurrent.futures.as_completed(futures):
result = future.result() # Will raise an exception if the callable raised
code, module_name = result
if code != 0:
msg = f"Failed to import {module_name}."
raise ValueError(msg)
Domain
Subdomains
Dependencies
- concurrent.futures
- importlib
- pathlib
- subprocess
Source
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, Serialization subdomain.
What functions are defined in test_imports.py?
test_imports.py defines 3 function(s): test_importable_all, test_importable_all_via_subprocess, try_to_import.
What does test_imports.py depend on?
test_imports.py imports 4 module(s): concurrent.futures, importlib, pathlib, subprocess.
Where is test_imports.py in the architecture?
test_imports.py is located at libs/core/tests/unit_tests/test_imports.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/core/tests/unit_tests).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free