Home / File/ check_version.py — langchain Source File

check_version.py — langchain Source File

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

File python LangChainCore ApiManagement 3 imports 4 functions

Entity Profile

Dependency Diagram

graph LR
  38914e20_32e7_35e1_71af_1a3b2e7d5416["check_version.py"]
  b7996424_637b_0b54_6edf_2e18e9c1a8bf["re"]
  38914e20_32e7_35e1_71af_1a3b2e7d5416 --> b7996424_637b_0b54_6edf_2e18e9c1a8bf
  02625e10_fb78_7ecd_1ee2_105ee470faf5["sys"]
  38914e20_32e7_35e1_71af_1a3b2e7d5416 --> 02625e10_fb78_7ecd_1ee2_105ee470faf5
  927570d8_11a6_5c17_0f0d_80baae0c733e["pathlib"]
  38914e20_32e7_35e1_71af_1a3b2e7d5416 --> 927570d8_11a6_5c17_0f0d_80baae0c733e
  style 38914e20_32e7_35e1_71af_1a3b2e7d5416 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Check version consistency between pyproject.toml and __init__.py.

This script validates that the version defined in pyproject.toml matches
the __version__ variable in langchain/__init__.py. Intended for use as
a pre-commit hook to prevent version mismatches.
"""

import re
import sys
from pathlib import Path


def get_pyproject_version(pyproject_path: Path) -> str | None:
    """Extract version from pyproject.toml."""
    content = pyproject_path.read_text()
    match = re.search(r'^version\s*=\s*"([^"]+)"', content, re.MULTILINE)
    return match.group(1) if match else None


def get_init_version(init_path: Path) -> str | None:
    """Extract __version__ from __init__.py."""
    content = init_path.read_text()
    match = re.search(r'^__version__\s*=\s*"([^"]+)"', content, re.MULTILINE)
    return match.group(1) if match else None


def main() -> int:
    """Validate version consistency."""
    script_dir = Path(__file__).parent
    package_dir = script_dir.parent

    pyproject_path = package_dir / "pyproject.toml"
    init_path = package_dir / "langchain" / "__init__.py"

    if not pyproject_path.exists():
        print(f"Error: {pyproject_path} not found")  # noqa: T201
        return 1

    if not init_path.exists():
        print(f"Error: {init_path} not found")  # noqa: T201
        return 1

    pyproject_version = get_pyproject_version(pyproject_path)
    init_version = get_init_version(init_path)

    if pyproject_version is None:
        print("Error: Could not find version in pyproject.toml")  # noqa: T201
        return 1

    if init_version is None:
        print("Error: Could not find __version__ in langchain/__init__.py")  # noqa: T201
        return 1

    if pyproject_version != init_version:
        print("Error: Version mismatch detected!")  # noqa: T201
        print(f"  pyproject.toml: {pyproject_version}")  # noqa: T201
        print(f"  langchain/__init__.py: {init_version}")  # noqa: T201
        return 1

    print(f"Version check passed: {pyproject_version}")  # noqa: T201
    return 0


if __name__ == "__main__":
    sys.exit(main())

Domain

Subdomains

Dependencies

  • pathlib
  • re
  • sys

Frequently Asked Questions

What does check_version.py do?
check_version.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, ApiManagement subdomain.
What functions are defined in check_version.py?
check_version.py defines 4 function(s): get_init_version, get_pyproject_version, main, sys.
What does check_version.py depend on?
check_version.py imports 3 module(s): pathlib, re, sys.
Where is check_version.py in the architecture?
check_version.py is located at libs/langchain_v1/scripts/check_version.py (domain: LangChainCore, subdomain: ApiManagement, directory: libs/langchain_v1/scripts).

Analyze Your Own Codebase

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

Try Supermodel Free