Skip to content

[performance]: Use hard coded langchain-core version to avoid importlib import #30744

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 8 commits into from
Apr 10, 2025
29 changes: 29 additions & 0 deletions .github/workflows/check_core_versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Check `langchain-core` version equality
Copy link
Collaborator

@eyurtsev eyurtsev Apr 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to generalize this I think. How about we do this as part of the release pipeline so it'll apply to all libraries. We can put logic in workflow to only apply it to libraries that we fixed already (or even skip and force all libraries to include version which I would prefer!)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think generalizing this would be good... maybe in a separate PR where we automate some of the manual and redundant release tasks (like version bumping, etc).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea @Viicos, thanks! Will do :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, maybe I should just do the version stuff across all of our libs at once then :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Viicos, explored dynamic versioning via #30771. pdm-backend has relatively limited support, and it breaks our release CI, so going to stick with keeping the version in pyproject.toml for now.

Maybe if we move to hatch, that switch would make sense.


on:
pull_request:
paths:
- 'libs/core/pyproject.toml'
- 'libs/core/langchain_core/version.py'

jobs:
check_version_equality:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Check version equality
run: |
PYPROJECT_VERSION=$(grep -Po '(?<=^version = ")[^"]*' libs/core/pyproject.toml)
VERSION_PY_VERSION=$(grep -Po '(?<=^VERSION = ")[^"]*' libs/core/langchain_core/version.py)

# Compare the two versions
if [ "$PYPROJECT_VERSION" != "$VERSION_PY_VERSION" ]; then
echo "langchain-core versions in pyproject.toml and version.py do not match!"
echo "pyproject.toml version: $PYPROJECT_VERSION"
echo "version.py version: $VERSION_PY_VERSION"
exit 1
else
echo "Versions match: $PYPROJECT_VERSION"
fi
9 changes: 2 additions & 7 deletions libs/core/langchain_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,13 @@
very lightweight.
"""

from importlib import metadata

from langchain_core._api import (
surface_langchain_beta_warnings,
surface_langchain_deprecation_warnings,
)
from langchain_core.version import VERSION

try:
__version__ = metadata.version(__package__)
except metadata.PackageNotFoundError:
# Case where package metadata is not available.
__version__ = ""
__version__ = VERSION

surface_langchain_deprecation_warnings()
surface_langchain_beta_warnings()
3 changes: 3 additions & 0 deletions libs/core/langchain_core/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""langchain-core version information and utilities."""

VERSION = "0.3.51"
Loading