Skip to content

Commit 8166e01

Browse files
authored
chore(anthropic): add version (#35293)
1 parent 6fe7845 commit 8166e01

File tree

6 files changed

+92
-1
lines changed

6 files changed

+92
-1
lines changed

.github/workflows/check_core_versions.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ on:
99
paths:
1010
- "libs/core/pyproject.toml"
1111
- "libs/core/langchain_core/version.py"
12+
- "libs/partners/anthropic/pyproject.toml"
13+
- "libs/partners/anthropic/langchain_anthropic/_version.py"
1214

1315
permissions:
1416
contents: read
@@ -49,3 +51,17 @@ jobs:
4951
else
5052
echo "Langchain v1 versions match: $LANGCHAIN_PYPROJECT_VERSION"
5153
fi
54+
55+
# Check langchain-anthropic versions
56+
ANTHROPIC_PYPROJECT_VERSION=$(grep -Po '(?<=^version = ")[^"]*' libs/partners/anthropic/pyproject.toml)
57+
ANTHROPIC_VERSION_PY_VERSION=$(grep -Po '(?<=^__version__ = ")[^"]*' libs/partners/anthropic/langchain_anthropic/_version.py)
58+
59+
# Compare langchain-anthropic versions
60+
if [ "$ANTHROPIC_PYPROJECT_VERSION" != "$ANTHROPIC_VERSION_PY_VERSION" ]; then
61+
echo "langchain-anthropic versions in pyproject.toml and _version.py do not match!"
62+
echo "pyproject.toml version: $ANTHROPIC_PYPROJECT_VERSION"
63+
echo "_version.py version: $ANTHROPIC_VERSION_PY_VERSION"
64+
exit 1
65+
else
66+
echo "Langchain-anthropic versions match: $ANTHROPIC_PYPROJECT_VERSION"
67+
fi

libs/partners/anthropic/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,17 @@ format format_diff:
5151
check_imports: $(shell find langchain_anthropic -name '*.py')
5252
uv run --all-groups python ./scripts/check_imports.py $^
5353

54+
check_version:
55+
uv run python ./scripts/check_version.py
56+
5457
######################
5558
# HELP
5659
######################
5760

5861
help:
5962
@echo '----'
60-
@echo 'check_imports - check imports'
63+
@echo 'check_imports - check imports'
64+
@echo 'check_version - validate version consistency'
6165
@echo 'format - run code formatters'
6266
@echo 'lint - run linters'
6367
@echo 'type - run type checking'

libs/partners/anthropic/langchain_anthropic/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Claude (Anthropic) partner package for LangChain."""
22

3+
from langchain_anthropic._version import __version__
34
from langchain_anthropic.chat_models import (
45
ChatAnthropic,
56
convert_to_anthropic_tool,
@@ -9,5 +10,6 @@
910
__all__ = [
1011
"AnthropicLLM",
1112
"ChatAnthropic",
13+
"__version__",
1214
"convert_to_anthropic_tool",
1315
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""Version information for langchain-anthropic."""
2+
3+
__version__ = "1.3.3"
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""Check version consistency between `pyproject.toml` and `_version.py`.
2+
3+
This script validates that the version defined in pyproject.toml matches the
4+
`__version__` variable in `langchain_anthropic/_version.py`. Intended for use as a
5+
pre-commit hook to prevent version mismatches.
6+
"""
7+
8+
import re
9+
import sys
10+
from pathlib import Path
11+
12+
13+
def get_pyproject_version(pyproject_path: Path) -> str | None:
14+
"""Extract version from `pyproject.toml`."""
15+
content = pyproject_path.read_text(encoding="utf-8")
16+
match = re.search(r'^version\s*=\s*"([^"]+)"', content, re.MULTILINE)
17+
return match.group(1) if match else None
18+
19+
20+
def get_version_py_version(version_path: Path) -> str | None:
21+
"""Extract `__version__` from `_version.py`."""
22+
content = version_path.read_text(encoding="utf-8")
23+
match = re.search(r'^__version__\s*=\s*"([^"]+)"', content, re.MULTILINE)
24+
return match.group(1) if match else None
25+
26+
27+
def main() -> int:
28+
"""Validate version consistency."""
29+
script_dir = Path(__file__).parent
30+
package_dir = script_dir.parent
31+
32+
pyproject_path = package_dir / "pyproject.toml"
33+
version_path = package_dir / "langchain_anthropic" / "_version.py"
34+
35+
if not pyproject_path.exists():
36+
print(f"Error: {pyproject_path} not found") # noqa: T201
37+
return 1
38+
39+
if not version_path.exists():
40+
print(f"Error: {version_path} not found") # noqa: T201
41+
return 1
42+
43+
pyproject_version = get_pyproject_version(pyproject_path)
44+
version_py_version = get_version_py_version(version_path)
45+
46+
if pyproject_version is None:
47+
print("Error: Could not find version in pyproject.toml") # noqa: T201
48+
return 1
49+
50+
if version_py_version is None:
51+
print("Error: Could not find __version__ in langchain_anthropic/_version.py") # noqa: T201
52+
return 1
53+
54+
if pyproject_version != version_py_version:
55+
print("Error: Version mismatch detected!") # noqa: T201
56+
print(f" pyproject.toml: {pyproject_version}") # noqa: T201
57+
print(f" langchain_anthropic/_version.py: {version_py_version}") # noqa: T201
58+
return 1
59+
60+
print(f"Version check passed: {pyproject_version}") # noqa: T201
61+
return 0
62+
63+
64+
if __name__ == "__main__":
65+
sys.exit(main())

libs/partners/anthropic/tests/unit_tests/test_imports.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from langchain_anthropic import __all__
22

33
EXPECTED_ALL = [
4+
"__version__",
45
"ChatAnthropic",
56
"convert_to_anthropic_tool",
67
"AnthropicLLM",

0 commit comments

Comments
 (0)