Skip to content

Make __version__ a constant #1669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/python_test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Python CI

Check notice on line 1 in .github/workflows/python_test.yml

View workflow job for this annotation

GitHub Actions / benchmark

Benchmark results

........... WARNING: the benchmark result may be unstable * Not enough samples to get a stable result (95% certainly of less than 1% variation) Try to rerun the benchmark with more runs, values and/or loops. Run 'python -m pyperf system tune' command to reduce the system jitter. Use pyperf stats, pyperf dump and pyperf hist to analyze results. Use --quiet option to hide these warnings. create_5_000_run_trees: Mean +- std dev: 717 ms +- 58 ms ........... WARNING: the benchmark result may be unstable * Not enough samples to get a stable result (95% certainly of less than 1% variation) Try to rerun the benchmark with more runs, values and/or loops. Run 'python -m pyperf system tune' command to reduce the system jitter. Use pyperf stats, pyperf dump and pyperf hist to analyze results. Use --quiet option to hide these warnings. create_10_000_run_trees: Mean +- std dev: 1.35 sec +- 0.07 sec ........... WARNING: the benchmark result may be unstable * Not enough samples to get a stable result (95% certainly of less than 1% variation) Try to rerun the benchmark with more runs, values and/or loops. Run 'python -m pyperf system tune' command to reduce the system jitter. Use pyperf stats, pyperf dump and pyperf hist to analyze results. Use --quiet option to hide these warnings. create_20_000_run_trees: Mean +- std dev: 2.72 sec +- 0.14 sec ........... WARNING: the benchmark result may be unstable * Not enough samples to get a stable result (95% certainly of less than 1% variation) Try to rerun the benchmark with more runs, values and/or loops. Run 'python -m pyperf system tune' command to reduce the system jitter. Use pyperf stats, pyperf dump and pyperf hist to analyze results. Use --quiet option to hide these warnings. dumps_class_nested_py_branch_and_leaf_200x400: Mean +- std dev: 686 us +- 7 us ........... dumps_class_nested_py_leaf_50x100: Mean +- std dev: 24.3 ms +- 0.2 ms ........... WARNING: the benchmark result may be unstable * Not enough samples to get a stable result (95% certainly of less than 1% variation) Try to rerun the benchmark with more runs, values and/or loops. Run 'python -m pyperf system tune' command to reduce the system jitter. Use pyperf stats, pyperf dump and pyperf hist to analyze results. Use --quiet option to hide these warnings. dumps_class_nested_py_leaf_100x200: Mean +- std dev: 98.9 ms +- 0.9 ms ........... dumps_dataclass_nested_50x100: Mean +- std dev: 24.6 ms +- 0.2 ms ........... WARNING: the benchmark result may be unstable * the standard deviation (7.45 ms) is 14% of the mean (54.8 ms) Try to rerun the benchmark with more runs, values and/or loops. Run 'python -m pyperf system tune' command to reduce the system jitter. Use pyperf stats, pyperf dump and pyperf hist to analyze results. Use --quiet option to hide these warnings. dumps_pydantic_nested_50x100: Mean +- std dev: 54.8 ms +- 7.5 ms ........... WARNING: the benchmark result may be unstable * the standard deviation (35.8 ms) is 16% of the mean (228 ms) Try to rerun the benchmark with more runs, values and/or loops. Run 'python -m pyperf system tune' command to reduce the system jitter. Use pyperf stats, pyperf dump and pyperf hist to analyze results. Use --quiet option to hide these warnings. dumps_pydanticv1_nested_50x100: Mean +- std dev: 228 ms +- 36 ms

Check notice on line 1 in .github/workflows/python_test.yml

View workflow job for this annotation

GitHub Actions / benchmark

Comparison against main

+-----------------------------------------------+----------+------------------------+ | Benchmark | main | changes | +===============================================+==========+========================+ | dumps_pydantic_nested_50x100 | 57.7 ms | 54.8 ms: 1.05x faster | +-----------------------------------------------+----------+------------------------+ | dumps_class_nested_py_leaf_100x200 | 103 ms | 98.9 ms: 1.04x faster | +-----------------------------------------------+----------+------------------------+ | dumps_class_nested_py_leaf_50x100 | 24.8 ms | 24.3 ms: 1.02x faster | +-----------------------------------------------+----------+------------------------+ | dumps_dataclass_nested_50x100 | 25.1 ms | 24.6 ms: 1.02x faster | +-----------------------------------------------+----------+------------------------+ | dumps_class_nested_py_branch_and_leaf_200x400 | 700 us | 686 us: 1.02x faster | +-----------------------------------------------+----------+------------------------+ | create_10_000_run_trees | 1.35 sec | 1.35 sec: 1.00x slower | +-----------------------------------------------+----------+------------------------+ | create_20_000_run_trees | 2.65 sec | 2.72 sec: 1.02x slower | +-----------------------------------------------+----------+------------------------+ | create_5_000_run_trees | 698 ms | 717 ms: 1.03x slower | +-----------------------------------------------+----------+------------------------+ | dumps_pydanticv1_nested_50x100 | 216 ms | 228 ms: 1.06x slower | +-----------------------------------------------+----------+------------------------+ | Geometric mean | (ref) | 1.01x faster | +-----------------------------------------------+----------+------------------------+

on:
push:
Expand Down Expand Up @@ -40,6 +40,8 @@
poetry run pip install -U langchain langchain-core langchain_anthropic langchain_openai
- name: Build ${{ matrix.python-version }}
run: poetry build
- name: Check version alignment
run: make check-version
- name: Lint ${{ matrix.python-version }}
run: make lint
- name: Run Unit tests ${{ matrix.python-version }}
Expand Down
21 changes: 21 additions & 0 deletions python/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,24 @@ api_docs_build:

api_docs_clean:
git clean -fd ./docs/

sync-version:
# Update version in __init__.py to match pyproject.toml
$(eval VERSION := $(shell grep '^version =' pyproject.toml | sed 's/version = "\(.*\)"/\1/'))
sed -i '' 's/__version__ = "[^"]*"/__version__ = "$(VERSION)"/' langsmith/__init__.py
echo "Synced version: $(VERSION)"

check-version:
# Get version from pyproject.toml
$(eval VERSION := $(shell grep '^version =' pyproject.toml | sed 's/version = "\(.*\)"/\1/'))
# Get version from __init__.py
$(eval INIT_VERSION := $(shell grep '__version__ =' langsmith/__init__.py | sed 's/__version__ = "\(.*\)"/\1/'))
@echo "Checking version alignment..."
@echo "pyproject.toml version: $(VERSION)"
@echo "__init__.py version: $(INIT_VERSION)"
@if [ "$(VERSION)" = "$(INIT_VERSION)" ]; then \
echo "✅ Versions are aligned"; \
else \
echo "❌ Version mismatch! Please run 'make sync-version' to sync versions"; \
exit 1; \
fi
16 changes: 4 additions & 12 deletions python/langsmith/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""LangSmith Client."""

from importlib import metadata
from typing import TYPE_CHECKING, Any

if TYPE_CHECKING:
Expand All @@ -18,16 +17,11 @@
)
from langsmith.run_trees import RunTree
from langsmith.testing._internal import test, unit
from langsmith.utils import (
ContextThreadPoolExecutor,
)
from langsmith.utils import ContextThreadPoolExecutor

# Avoid calling into importlib on every call to __version__
version = ""
try:
version = metadata.version(__package__)
except metadata.PackageNotFoundError:
pass
__version__ = "0.3.31"
version = __version__ # for backwards compatibility


def __getattr__(name: str) -> Any:
Expand Down Expand Up @@ -108,9 +102,7 @@ def __getattr__(name: str) -> Any:

return unit
elif name == "ContextThreadPoolExecutor":
from langsmith.utils import (
ContextThreadPoolExecutor,
)
from langsmith.utils import ContextThreadPoolExecutor

return ContextThreadPoolExecutor

Expand Down
4 changes: 4 additions & 0 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,7 @@ dynamic = ["version"]

[tool.poetry.plugins."pytest11"]
langsmith_plugin = "langsmith.pytest_plugin"

[tool.poetry_bumpversion.file."langsmith/__init__.py"]
search = '__version__ = "{current_version}"'
replace = '__version__ = "{new_version}"'
Loading