Skip to content
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

feat: expose main_version on /version endpoint #2944

Merged
merged 1 commit into from
Jul 26, 2024
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
25 changes: 21 additions & 4 deletions src/backend/base/langflow/utils/version.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
def get_version_info():
def _compute_non_prerelease_version(prerelease_version: str) -> str:
prerelease_keywords = ["a", "b", "rc", "dev", "post"]
for keyword in prerelease_keywords:
if keyword in prerelease_version:
return prerelease_version.split(keyword)[0][:-1]
return prerelease_version


def _get_version_info():
try:
from langflow.version import __version__ # type: ignore

version = __version__
prerelease_version = __version__
version = _compute_non_prerelease_version(prerelease_version)
package = "Langflow"
except ImportError:
from importlib import metadata

version = metadata.version("langflow-base")
prerelease_version = metadata.version("langflow-base")
version = _compute_non_prerelease_version(prerelease_version)
package = "Langflow Base"
return {"version": version, "package": package}
return {"version": prerelease_version, "main_version": version, "package": package}


VERSION_INFO = _get_version_info()


def get_version_info():
return VERSION_INFO
17 changes: 17 additions & 0 deletions src/backend/tests/unit/test_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from langflow.utils.version import _compute_non_prerelease_version, get_version_info


def test_version():
info = get_version_info()
assert info["version"] is not None
assert info["main_version"] is not None
assert info["package"] is not None


def test_compute_main():
assert "1.0.10" == _compute_non_prerelease_version("1.0.10.post0")
assert "1.0.10" == _compute_non_prerelease_version("1.0.10.a1")
assert "1.0.10" == _compute_non_prerelease_version("1.0.10.b112")
assert "1.0.10" == _compute_non_prerelease_version("1.0.10.rc0")
assert "1.0.10" == _compute_non_prerelease_version("1.0.10.dev9")
assert "1.0.10" == _compute_non_prerelease_version("1.0.10")
Loading