-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose main_version on /version endpoint (#2944)
- Loading branch information
1 parent
cba0ae4
commit 53084bc
Showing
3 changed files
with
38 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |