mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 04:31:13 +00:00
Improve version check (#3544)
This commit is contained in:
@@ -9,7 +9,8 @@ import logging
|
||||
import os
|
||||
import subprocess # nosec
|
||||
import sys
|
||||
from typing import List, Optional
|
||||
from typing import List, Union
|
||||
from packaging import version
|
||||
|
||||
# IMPORTATION THIRDPARTY
|
||||
import requests
|
||||
@@ -220,19 +221,19 @@ def check_for_updates() -> None:
|
||||
r = None
|
||||
|
||||
if r is not None and r.status_code == 200:
|
||||
latest_version = r.json()["tag_name"]
|
||||
latest_version_number = get_version_number(tag=latest_version)
|
||||
current_version_number = get_version_number(tag=obbff.VERSION)
|
||||
latest_tag_name = r.json()["tag_name"]
|
||||
latest_version = version.parse(latest_tag_name)
|
||||
current_version = version.parse(obbff.VERSION)
|
||||
|
||||
if latest_version_number and current_version_number:
|
||||
if check_valid_versions(latest_version, current_version):
|
||||
|
||||
if current_version_number == latest_version_number:
|
||||
if current_version == latest_version:
|
||||
console.print("[green]You are using the latest stable version[/green]")
|
||||
else:
|
||||
console.print(
|
||||
"[yellow]You are not using the latest stable version[/yellow]"
|
||||
)
|
||||
if current_version_number < latest_version_number:
|
||||
if current_version < latest_version:
|
||||
console.print(
|
||||
"[yellow]Check for updates at https://openbb.co/products/terminal#get-started[/yellow]"
|
||||
)
|
||||
@@ -252,21 +253,18 @@ def check_for_updates() -> None:
|
||||
console.print("\n")
|
||||
|
||||
|
||||
def get_version_number(tag: str) -> Optional[str]:
|
||||
"""Get the release number from a tag."""
|
||||
|
||||
if not tag.startswith("v") and len(tag.split(".")) != 3:
|
||||
return None
|
||||
|
||||
if tag.startswith("v"):
|
||||
tag = tag[1:]
|
||||
|
||||
if "rc" in tag.split(".")[-1]:
|
||||
tag_split = tag.split(".")
|
||||
tag_split[-1] = tag_split[-1].split("rc")[0]
|
||||
tag = ".".join(tag_split)
|
||||
|
||||
return tag
|
||||
def check_valid_versions(
|
||||
latest_version: Union[version.LegacyVersion, version.Version],
|
||||
current_version: Union[version.LegacyVersion, version.Version],
|
||||
) -> bool:
|
||||
if (
|
||||
not latest_version
|
||||
or not current_version
|
||||
or not isinstance(latest_version, version.Version)
|
||||
or not isinstance(current_version, version.Version)
|
||||
):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def welcome_message():
|
||||
|
||||
@@ -2,6 +2,7 @@ import sys
|
||||
import unittest
|
||||
from contextlib import contextmanager
|
||||
from unittest.mock import patch
|
||||
import pytest
|
||||
|
||||
from openbb_terminal import terminal_helper
|
||||
from tests.helpers.helpers import check_print
|
||||
@@ -39,3 +40,51 @@ class TestMainHelper(unittest.TestCase):
|
||||
def test_reset(self, mock):
|
||||
# pylint: disable=unused-argument
|
||||
terminal_helper.reset()
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
@pytest.mark.parametrize(
|
||||
"last_release, current_release",
|
||||
[
|
||||
("v0.0.1", "v0.0.1"),
|
||||
("v0.0.2", "v0.0.1"),
|
||||
("v0.0.1", "v0.0.2"),
|
||||
("v1.9.0", "v1.10.0"),
|
||||
("v1.10.0", "v1.9.0"),
|
||||
("xyz", "v1.9.0"),
|
||||
("2.0.0", "2.0.0rc1"),
|
||||
("2.0.0rc1", "2.0.0"),
|
||||
("2.0.0rc1", "2.0.0rc2"),
|
||||
("2.0.0rc2", "2.0.0rc1"),
|
||||
("3.41.99", "88.123.456"),
|
||||
("88.123.456", "3.41.99"),
|
||||
("3.41.99", "3.41.99"),
|
||||
("3.41.99", "3.41.99rc1"),
|
||||
("8.10.01", "8.1.01"),
|
||||
],
|
||||
)
|
||||
def test_check_for_updates(mocker, last_release, current_release):
|
||||
# MOCK GET
|
||||
attrs = {
|
||||
"status_code": 200,
|
||||
"json.return_value": {
|
||||
"url": "mock_url",
|
||||
"assets_url": "mock_url",
|
||||
"upload_url": "mock_url",
|
||||
"html_url": "mock_url",
|
||||
"node_id": "mock_node_id",
|
||||
"tag_name": last_release,
|
||||
"name": "mock_terminal_name",
|
||||
},
|
||||
}
|
||||
mock_response = mocker.Mock(**attrs)
|
||||
mocker.patch(target="requests.get", new=mocker.Mock(return_value=mock_response))
|
||||
|
||||
# MOCK FF VERSION
|
||||
mocker.patch(
|
||||
target="openbb_terminal.feature_flags.VERSION",
|
||||
new=current_release,
|
||||
)
|
||||
|
||||
terminal_helper.check_for_updates()
|
||||
|
||||
4
tests/openbb_terminal/txt/test_terminal_helper/test_check_for_updates[2.0.0-2.0.0rc1].txt
vendored
Normal file
4
tests/openbb_terminal/txt/test_terminal_helper/test_check_for_updates[2.0.0-2.0.0rc1].txt
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[yellow]You are not using the latest stable version[/yellow]
|
||||
[yellow]Check for updates at https://openbb.co/products/terminal#get-started[/yellow]
|
||||
|
||||
|
||||
4
tests/openbb_terminal/txt/test_terminal_helper/test_check_for_updates[2.0.0rc1-2.0.0].txt
vendored
Normal file
4
tests/openbb_terminal/txt/test_terminal_helper/test_check_for_updates[2.0.0rc1-2.0.0].txt
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[yellow]You are not using the latest stable version[/yellow]
|
||||
[yellow]You are using an unreleased version[/yellow]
|
||||
|
||||
|
||||
4
tests/openbb_terminal/txt/test_terminal_helper/test_check_for_updates[2.0.0rc1-2.0.0rc2].txt
vendored
Normal file
4
tests/openbb_terminal/txt/test_terminal_helper/test_check_for_updates[2.0.0rc1-2.0.0rc2].txt
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[yellow]You are not using the latest stable version[/yellow]
|
||||
[yellow]You are using an unreleased version[/yellow]
|
||||
|
||||
|
||||
4
tests/openbb_terminal/txt/test_terminal_helper/test_check_for_updates[2.0.0rc2-2.0.0rc1].txt
vendored
Normal file
4
tests/openbb_terminal/txt/test_terminal_helper/test_check_for_updates[2.0.0rc2-2.0.0rc1].txt
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[yellow]You are not using the latest stable version[/yellow]
|
||||
[yellow]Check for updates at https://openbb.co/products/terminal#get-started[/yellow]
|
||||
|
||||
|
||||
3
tests/openbb_terminal/txt/test_terminal_helper/test_check_for_updates[3.41.99-3.41.99].txt
vendored
Normal file
3
tests/openbb_terminal/txt/test_terminal_helper/test_check_for_updates[3.41.99-3.41.99].txt
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[green]You are using the latest stable version[/green]
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
[yellow]You are not using the latest stable version[/yellow]
|
||||
[yellow]Check for updates at https://openbb.co/products/terminal#get-started[/yellow]
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
[yellow]You are not using the latest stable version[/yellow]
|
||||
[yellow]You are using an unreleased version[/yellow]
|
||||
|
||||
|
||||
4
tests/openbb_terminal/txt/test_terminal_helper/test_check_for_updates[8.10.01-8.1.01].txt
vendored
Normal file
4
tests/openbb_terminal/txt/test_terminal_helper/test_check_for_updates[8.10.01-8.1.01].txt
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[yellow]You are not using the latest stable version[/yellow]
|
||||
[yellow]Check for updates at https://openbb.co/products/terminal#get-started[/yellow]
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
[yellow]You are not using the latest stable version[/yellow]
|
||||
[yellow]Check for updates at https://openbb.co/products/terminal#get-started[/yellow]
|
||||
|
||||
|
||||
3
tests/openbb_terminal/txt/test_terminal_helper/test_check_for_updates[v0.0.1-v0.0.1].txt
vendored
Normal file
3
tests/openbb_terminal/txt/test_terminal_helper/test_check_for_updates[v0.0.1-v0.0.1].txt
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[green]You are using the latest stable version[/green]
|
||||
|
||||
|
||||
4
tests/openbb_terminal/txt/test_terminal_helper/test_check_for_updates[v0.0.1-v0.0.2].txt
vendored
Normal file
4
tests/openbb_terminal/txt/test_terminal_helper/test_check_for_updates[v0.0.1-v0.0.2].txt
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[yellow]You are not using the latest stable version[/yellow]
|
||||
[yellow]You are using an unreleased version[/yellow]
|
||||
|
||||
|
||||
4
tests/openbb_terminal/txt/test_terminal_helper/test_check_for_updates[v0.0.2-v0.0.1].txt
vendored
Normal file
4
tests/openbb_terminal/txt/test_terminal_helper/test_check_for_updates[v0.0.2-v0.0.1].txt
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[yellow]You are not using the latest stable version[/yellow]
|
||||
[yellow]Check for updates at https://openbb.co/products/terminal#get-started[/yellow]
|
||||
|
||||
|
||||
4
tests/openbb_terminal/txt/test_terminal_helper/test_check_for_updates[v1.10.0-v1.9.0].txt
vendored
Normal file
4
tests/openbb_terminal/txt/test_terminal_helper/test_check_for_updates[v1.10.0-v1.9.0].txt
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[yellow]You are not using the latest stable version[/yellow]
|
||||
[yellow]Check for updates at https://openbb.co/products/terminal#get-started[/yellow]
|
||||
|
||||
|
||||
4
tests/openbb_terminal/txt/test_terminal_helper/test_check_for_updates[v1.9.0-v1.10.0].txt
vendored
Normal file
4
tests/openbb_terminal/txt/test_terminal_helper/test_check_for_updates[v1.9.0-v1.10.0].txt
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[yellow]You are not using the latest stable version[/yellow]
|
||||
[yellow]You are using an unreleased version[/yellow]
|
||||
|
||||
|
||||
3
tests/openbb_terminal/txt/test_terminal_helper/test_check_for_updates[xyz-v1.9.0].txt
vendored
Normal file
3
tests/openbb_terminal/txt/test_terminal_helper/test_check_for_updates[xyz-v1.9.0].txt
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[red]You are using an unrecognized version.[/red]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user