diff --git a/src/backend/base/langflow/utils/version.py b/src/backend/base/langflow/utils/version.py index 3783cd0e552..98936e34766 100644 --- a/src/backend/base/langflow/utils/version.py +++ b/src/backend/base/langflow/utils/version.py @@ -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 diff --git a/src/backend/tests/unit/text_experimental_components.py b/src/backend/tests/unit/test_experimental_components.py similarity index 100% rename from src/backend/tests/unit/text_experimental_components.py rename to src/backend/tests/unit/test_experimental_components.py diff --git a/src/backend/tests/unit/test_version.py b/src/backend/tests/unit/test_version.py new file mode 100644 index 00000000000..36ac7c5a480 --- /dev/null +++ b/src/backend/tests/unit/test_version.py @@ -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")