Skip to content

Commit 5b27527

Browse files
authored
Make __version__ a constant (#1669)
1 parent b2b5735 commit 5b27527

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

.github/workflows/python_test.yml

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ jobs:
4040
poetry run pip install -U langchain langchain-core langchain_anthropic langchain_openai
4141
- name: Build ${{ matrix.python-version }}
4242
run: poetry build
43+
- name: Check version alignment
44+
run: make check-version
4345
- name: Lint ${{ matrix.python-version }}
4446
run: make lint
4547
- name: Run Unit tests ${{ matrix.python-version }}

python/Makefile

+21
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,24 @@ api_docs_build:
7777

7878
api_docs_clean:
7979
git clean -fd ./docs/
80+
81+
sync-version:
82+
# Update version in __init__.py to match pyproject.toml
83+
$(eval VERSION := $(shell grep '^version =' pyproject.toml | sed 's/version = "\(.*\)"/\1/'))
84+
sed -i '' 's/__version__ = "[^"]*"/__version__ = "$(VERSION)"/' langsmith/__init__.py
85+
echo "Synced version: $(VERSION)"
86+
87+
check-version:
88+
# Get version from pyproject.toml
89+
$(eval VERSION := $(shell grep '^version =' pyproject.toml | sed 's/version = "\(.*\)"/\1/'))
90+
# Get version from __init__.py
91+
$(eval INIT_VERSION := $(shell grep '__version__ =' langsmith/__init__.py | sed 's/__version__ = "\(.*\)"/\1/'))
92+
@echo "Checking version alignment..."
93+
@echo "pyproject.toml version: $(VERSION)"
94+
@echo "__init__.py version: $(INIT_VERSION)"
95+
@if [ "$(VERSION)" = "$(INIT_VERSION)" ]; then \
96+
echo "✅ Versions are aligned"; \
97+
else \
98+
echo "❌ Version mismatch! Please run 'make sync-version' to sync versions"; \
99+
exit 1; \
100+
fi

python/langsmith/__init__.py

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""LangSmith Client."""
22

3-
from importlib import metadata
43
from typing import TYPE_CHECKING, Any
54

65
if TYPE_CHECKING:
@@ -18,16 +17,11 @@
1817
)
1918
from langsmith.run_trees import RunTree
2019
from langsmith.testing._internal import test, unit
21-
from langsmith.utils import (
22-
ContextThreadPoolExecutor,
23-
)
20+
from langsmith.utils import ContextThreadPoolExecutor
2421

2522
# Avoid calling into importlib on every call to __version__
26-
version = ""
27-
try:
28-
version = metadata.version(__package__)
29-
except metadata.PackageNotFoundError:
30-
pass
23+
__version__ = "0.3.31"
24+
version = __version__ # for backwards compatibility
3125

3226

3327
def __getattr__(name: str) -> Any:
@@ -108,9 +102,7 @@ def __getattr__(name: str) -> Any:
108102

109103
return unit
110104
elif name == "ContextThreadPoolExecutor":
111-
from langsmith.utils import (
112-
ContextThreadPoolExecutor,
113-
)
105+
from langsmith.utils import ContextThreadPoolExecutor
114106

115107
return ContextThreadPoolExecutor
116108

python/pyproject.toml

+4
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,7 @@ dynamic = ["version"]
151151

152152
[tool.poetry.plugins."pytest11"]
153153
langsmith_plugin = "langsmith.pytest_plugin"
154+
155+
[tool.poetry_bumpversion.file."langsmith/__init__.py"]
156+
search = '__version__ = "{current_version}"'
157+
replace = '__version__ = "{new_version}"'

0 commit comments

Comments
 (0)