mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-28 10:49:56 +02:00
fix(langgraph): use package metadata for API version check
Revert the optional `langgraph_api.__version__` import path in favor of the
cleaner `importlib.metadata.version("langgraph-api")` check for DeltaChannel
API compatibility. This avoids importing the optional API package at compile
time while preserving the same version boundary.
Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
This commit is contained in:
co-authored by
open-swe[bot] <open-swe@users.noreply.github.com>
parent
289b4d4d78
commit
1cc5f1fd48
@@ -9,7 +9,7 @@ from collections.abc import Awaitable, Callable, Hashable, Mapping, Sequence
|
||||
from dataclasses import dataclass, is_dataclass
|
||||
from datetime import timedelta
|
||||
from functools import partial
|
||||
from importlib import import_module
|
||||
from importlib import metadata
|
||||
from inspect import isclass, isfunction, ismethod, signature
|
||||
from types import FunctionType
|
||||
from types import NoneType as NoneType
|
||||
@@ -133,8 +133,8 @@ def _check_delta_channel_api_support(channels: Mapping[str, Any]) -> None:
|
||||
if not any(isinstance(c, DeltaChannel) for c in channels.values()):
|
||||
return
|
||||
try:
|
||||
api_version = import_module("langgraph_api").__version__
|
||||
except ImportError:
|
||||
api_version = metadata.version("langgraph-api")
|
||||
except metadata.PackageNotFoundError:
|
||||
return
|
||||
if Version(api_version) < Version("0.10.0"):
|
||||
raise RuntimeError(
|
||||
|
||||
@@ -8,9 +8,7 @@ is skipped when `langgraph-api` is not installed (local execution).
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import warnings
|
||||
from types import ModuleType
|
||||
from typing import Annotated
|
||||
|
||||
import pytest
|
||||
@@ -19,6 +17,7 @@ from typing_extensions import TypedDict
|
||||
from langgraph.channels.delta import DeltaChannel
|
||||
from langgraph.constants import START
|
||||
from langgraph.graph import StateGraph
|
||||
from langgraph.graph import state as state_module
|
||||
from langgraph.graph.message import _messages_delta_reducer
|
||||
|
||||
|
||||
@@ -42,15 +41,17 @@ def _delta_graph() -> StateGraph:
|
||||
|
||||
@pytest.fixture
|
||||
def api_version(monkeypatch: pytest.MonkeyPatch):
|
||||
"""Override the imported `langgraph_api.__version__` (or simulate absence)."""
|
||||
"""Override the reported `langgraph-api` package version (or simulate absence)."""
|
||||
|
||||
def _set(version: str | None) -> None:
|
||||
if version is None:
|
||||
monkeypatch.setitem(sys.modules, "langgraph_api", None)
|
||||
return
|
||||
module = ModuleType("langgraph_api")
|
||||
setattr(module, "__version__", version)
|
||||
monkeypatch.setitem(sys.modules, "langgraph_api", module)
|
||||
def fake_version(name: str) -> str:
|
||||
if name == "langgraph-api":
|
||||
if version is None:
|
||||
raise state_module.metadata.PackageNotFoundError(name)
|
||||
return version
|
||||
return state_module.metadata.version(name)
|
||||
|
||||
monkeypatch.setattr(state_module.metadata, "version", fake_version)
|
||||
|
||||
return _set
|
||||
|
||||
|
||||
Reference in New Issue
Block a user