Skip to content

Commit

Permalink
feat: expose main_version on /version endpoint (langflow-ai#2944)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoloboschi authored Jul 26, 2024
1 parent cba0ae4 commit 53084bc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
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")

0 comments on commit 53084bc

Please sign in to comment.