Skip to content

Commit 786d371

Browse files
committed
hooks: update hooks and test for langchain >= 1.0.0
In `langchain` v1.0.0, the API has changed completely. The old interfaces are available in optional `langchain_classic` package, for which we need to collect data files (same as we had to for `langchain` for `langchain` < 1.0.0). Put the old test under version check, and create a counterpart for `langchain_classic`. In addition, try to set up a basic test for the new `langchain` itself; since this requires access to an LLM model, have the test use `ollama`, and exit if it cannot connect to the local instance. This way, we can at least check on the CI that everything works up until the point where access to the model is required (and locally, it is possible to run complete test by running a docker container with the model).
1 parent 120cbd8 commit 786d371

6 files changed

Lines changed: 65 additions & 3 deletions

File tree

.github/workflows/pr-test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ jobs:
173173
# Install additional intake plugins for test_intake_plugins
174174
pip show -qq intake && pip install --prefer-binary intake-xarray
175175
176+
# test_langchain_with_ollama requires langchain-ollama to be installed together with langchain
177+
pip show -qq langchain && pip install --prefer-binary langchain-ollama
178+
176179
# Install PyInstaller
177180
pip install ${{ matrix.pyinstaller }}
178181

_pyinstaller_hooks_contrib/stdhooks/hook-langchain.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@
1212

1313
from PyInstaller.utils.hooks import collect_data_files
1414

15+
# This was required with langchain < 1.0.0; in contemporary versions, the package does not contain any data files,
16+
# so this should be effectively a no-op.
1517
datas = collect_data_files('langchain')
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# ------------------------------------------------------------------
2+
# Copyright (c) 2025 PyInstaller Development Team.
3+
#
4+
# This file is distributed under the terms of the GNU General Public
5+
# License (version 2.0 or later).
6+
#
7+
# The full license is available in LICENSE, distributed with
8+
# this software.
9+
#
10+
# SPDX-License-Identifier: GPL-2.0-or-later
11+
# ------------------------------------------------------------------
12+
13+
from PyInstaller.utils.hooks import collect_data_files
14+
15+
datas = collect_data_files('langchain_classic')

news/960.update.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update ``langchain`` hooks for ``langchain`` v.1.0.x.

requirements-test-libraries.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ eth-rlp==2.2.0
236236
z3c.rml==5.0.1; python_version >= "3.9"
237237
freetype-py==2.5.1
238238
vaderSentiment==3.3.2
239-
# At time of writing, the type annotations used by lanchain do not seem to be compatible with python 3.14.
240-
langchain==0.3.27; python_version >= "3.9" and python_version < "3.14"
239+
langchain==1.0.2; python_version >= "3.10"
240+
langchain-classic==1.0.2; python_version >= "3.10"
241241
seedir==0.5.1
242242
# Starting with v0.4.0, cel-python depends on google-re2, which does not provide binary wheels for python 3.14.
243243
cel-python==0.4.0; python_version >= "3.9" and python_version < "3.14"

tests/test_libraries.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1961,13 +1961,54 @@ def test_vadersentiment(pyi_builder):
19611961
""")
19621962

19631963

1964-
@importorskip('langchain')
1964+
@requires('langchain < 1.0')
19651965
def test_langchain_llm_summarization_checker(pyi_builder):
19661966
pyi_builder.test_source("""
19671967
import langchain.chains.llm_summarization_checker.base
19681968
""")
19691969

19701970

1971+
# In langchain 1.0.0, the old API was moved into langchain-classic package.
1972+
@requires('langchain-classic >= 1.0')
1973+
def test_langchain_classic_llm_summarization_checker(pyi_builder):
1974+
pyi_builder.test_source("""
1975+
import langchain_classic.chains.llm_summarization_checker.base
1976+
""")
1977+
1978+
1979+
@requires('langchain >= 1.0')
1980+
@requires('langchain-ollama')
1981+
def test_langchain_with_ollama(pyi_builder):
1982+
pyi_builder.test_source("""
1983+
import time
1984+
from langchain.chat_models import init_chat_model
1985+
1986+
model = init_chat_model("ollama:gemma3:1b") # requires langchain-ollama
1987+
1988+
try:
1989+
start_time = time.time()
1990+
response = model.invoke("What is LangChain?")
1991+
elapsed = time.time() - start_time
1992+
print(f"Answer took {elapsed:.1f} seconds:")
1993+
except Exception as e:
1994+
# Gracefully handle the situation where local instance of ollama is not running - this should be the usual case with
1995+
# this test running on PyInstaller's CI.
1996+
#
1997+
# If you want to set up a local instance for complete test, see:
1998+
# https://github.com/ollama/ollama?tab=readme-ov-file#ollama
1999+
if "Connection refused" in str(e):
2000+
print("Local instance of ollama does not seem to be running.")
2001+
raise SystemExit(0)
2002+
raise
2003+
2004+
for block in response.content_blocks:
2005+
if block["type"] == "reasoning":
2006+
print(block.get("reasoning"))
2007+
elif block["type"] == "text":
2008+
print(block.get("text"))
2009+
""")
2010+
2011+
19712012
@importorskip('seedir')
19722013
def test_seedir(pyi_builder):
19732014
pyi_builder.test_source("""

0 commit comments

Comments
 (0)