From 6fccb743e44e72e230a69739ffab0d5f36abc7e7 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Tue, 4 Apr 2023 14:57:20 +0100 Subject: [PATCH 1/9] move update flair --- openbb_terminal/core/session/local_model.py | 9 +++++++++ openbb_terminal/core/session/session_model.py | 7 +------ tests/openbb_terminal/session/test_session_model.py | 6 ++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/openbb_terminal/core/session/local_model.py b/openbb_terminal/core/session/local_model.py index 4383a3277b23..ed0718ef37d8 100644 --- a/openbb_terminal/core/session/local_model.py +++ b/openbb_terminal/core/session/local_model.py @@ -10,6 +10,7 @@ ) from openbb_terminal.core.session.current_user import ( get_current_user, + get_env_dict, set_credential, set_preference, set_sources, @@ -113,6 +114,14 @@ def remove_cli_history_file(file_path: Path = HIST_FILE_PATH) -> bool: return False +def update_flair(): + """Update the flair.""" + if "FLAIR" not in get_env_dict(): + MAX_FLAIR_LEN = 20 + flair = "[" + get_current_user().profile.username[:MAX_FLAIR_LEN] + "]" + " 🦋" + set_preference("FLAIR", flair) + + def apply_configs(configs: dict): """Apply configurations. diff --git a/openbb_terminal/core/session/session_model.py b/openbb_terminal/core/session/session_model.py index 2accbb34a686..ef505d14d8c4 100644 --- a/openbb_terminal/core/session/session_model.py +++ b/openbb_terminal/core/session/session_model.py @@ -16,10 +16,8 @@ ) from openbb_terminal.core.session.current_user import ( get_current_user, - get_env_dict, set_current_user, set_default_user, - set_preference, ) from openbb_terminal.helper_funcs import system_clear from openbb_terminal.loggers import setup_logging @@ -94,10 +92,7 @@ def login(session: dict) -> LoginStatus: hub_user.profile.load_user_info(session, email) set_current_user(hub_user) Local.apply_configs(configs=configs) - if "FLAIR" not in get_env_dict(): - MAX_FLAIR_LEN = 20 - flair = "[" + hub_user.profile.username[:MAX_FLAIR_LEN] + "]" + " 🦋" - set_preference("FLAIR", flair) + Local.update_flair() return LoginStatus.SUCCESS if response.status_code == 401: return LoginStatus.UNAUTHORIZED diff --git a/tests/openbb_terminal/session/test_session_model.py b/tests/openbb_terminal/session/test_session_model.py index a313d215cefe..e60c16a148d8 100644 --- a/tests/openbb_terminal/session/test_session_model.py +++ b/tests/openbb_terminal/session/test_session_model.py @@ -64,6 +64,7 @@ def test_login_no_response(mocker): path = "openbb_terminal.core.session.session_model." mock_fetch_user_configs = mocker.patch(path + "Hub.fetch_user_configs") mock_apply_configs = mocker.patch(path + "Local.apply_configs") + mock_update_flair = mocker.patch(path + "Local.update_flair") mock_fetch_user_configs.return_value = None @@ -71,12 +72,14 @@ def test_login_no_response(mocker): mock_fetch_user_configs.assert_called_once_with(TEST_SESSION) mock_apply_configs.assert_not_called() + mock_update_flair.assert_not_called() def test_login_fail_response(mocker): path = "openbb_terminal.core.session.session_model." mock_fetch_user_configs = mocker.patch(path + "Hub.fetch_user_configs") mock_apply_configs = mocker.patch(path + "Local.apply_configs") + mock_update_flair = mocker.patch(path + "Local.update_flair") response = Response() response.status_code = 400 @@ -86,12 +89,14 @@ def test_login_fail_response(mocker): mock_fetch_user_configs.assert_called_once_with(TEST_SESSION) mock_apply_configs.assert_not_called() + mock_update_flair.assert_not_called() def test_login_success_response(mocker): path = "openbb_terminal.core.session.session_model." mock_fetch_user_configs = mocker.patch(path + "Hub.fetch_user_configs") mock_apply_configs = mocker.patch(path + "Local.apply_configs") + mock_update_flair = mocker.patch(path + "Local.update_flair") response = Response() response.status_code = 200 @@ -104,6 +109,7 @@ def test_login_success_response(mocker): mock_fetch_user_configs.assert_called_once_with(TEST_SESSION) mock_apply_configs.assert_called_once() + mock_update_flair.assert_called_once() @pytest.mark.parametrize( From 408fa8b013f8175c78dd9571ac55e6aed75e1911 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Wed, 5 Apr 2023 10:49:37 +0100 Subject: [PATCH 2/9] sort repr --- openbb_terminal/core/models/base_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbb_terminal/core/models/base_model.py b/openbb_terminal/core/models/base_model.py index 7d254e77462a..2c2ca1edd9bf 100644 --- a/openbb_terminal/core/models/base_model.py +++ b/openbb_terminal/core/models/base_model.py @@ -11,7 +11,7 @@ class BaseModel: def __repr__(self) -> str: """Return string representation of model.""" dataclass_repr = "" - for key, value in self.__dict__.items(): + for key, value in sorted(self.__dict__.items()): if key.startswith("_"): continue dataclass_repr += f" {key}='{value}', \n" From 82d19409f0d520d3f65a2c801ac7b1ecee0b3a18 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Wed, 5 Apr 2023 11:01:07 +0100 Subject: [PATCH 3/9] remove packaged sys model var --- openbb_terminal/core/models/system_model.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openbb_terminal/core/models/system_model.py b/openbb_terminal/core/models/system_model.py index afc638bd5de2..4356125b36d8 100644 --- a/openbb_terminal/core/models/system_model.py +++ b/openbb_terminal/core/models/system_model.py @@ -28,7 +28,6 @@ class SystemModel(BaseModel): # OpenBB section VERSION = "3.0.0rc1" - PACKAGED: bool = getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS") # Logging section LOGGING_APP_NAME: str = "gst" From 91c397c9edd0aca60c0440f6f785290df618610d Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Wed, 5 Apr 2023 11:01:25 +0100 Subject: [PATCH 4/9] update decorator for check api key --- openbb_terminal/decorators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbb_terminal/decorators.py b/openbb_terminal/decorators.py index 68ef114a5708..e4127690959f 100644 --- a/openbb_terminal/decorators.py +++ b/openbb_terminal/decorators.py @@ -137,7 +137,7 @@ def wrapper_decorator(*args, **kwargs): undefined_apis_name = ", ".join(undefined_apis) console.print( f"[red]{undefined_apis_name} not defined. " - "Set API Keys in ~/.openbb_terminal/.env or under keys menu.[/red]" + "Set the API key under keys menu.[/red]" ) # pragma: allowlist secret return None return func(*args, **kwargs) From 7117e4cd109eb9199927081d4f9e85ac2a735ae4 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Wed, 5 Apr 2023 11:06:01 +0100 Subject: [PATCH 5/9] ruff --- openbb_terminal/core/models/system_model.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openbb_terminal/core/models/system_model.py b/openbb_terminal/core/models/system_model.py index 4356125b36d8..b56cb72e933d 100644 --- a/openbb_terminal/core/models/system_model.py +++ b/openbb_terminal/core/models/system_model.py @@ -1,5 +1,4 @@ import platform -import sys from typing import Literal from pydantic.dataclasses import dataclass From a8c20a42f1025b37859260e479971bbfbf83e6af Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Wed, 5 Apr 2023 11:50:58 +0100 Subject: [PATCH 6/9] change if stat --- openbb_terminal/core/session/session_controller.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/openbb_terminal/core/session/session_controller.py b/openbb_terminal/core/session/session_controller.py index 0c3cd4ebb16a..93e47862da6a 100644 --- a/openbb_terminal/core/session/session_controller.py +++ b/openbb_terminal/core/session/session_controller.py @@ -50,9 +50,7 @@ def get_user_input() -> Tuple[str, str, bool]: is_password=True, ) save_str = s.prompt(message="> Remember me? (y/n): ", is_password=False).lower() - save = False - if save_str == "y": - save = True + save = True if save_str == "y" else False return email, password, save From e1a8452e3d396f8780b0b2e6fc811647602dd460 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Wed, 5 Apr 2023 11:57:38 +0100 Subject: [PATCH 7/9] ruff --- openbb_terminal/core/session/session_controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbb_terminal/core/session/session_controller.py b/openbb_terminal/core/session/session_controller.py index 93e47862da6a..c71c0ebcfc27 100644 --- a/openbb_terminal/core/session/session_controller.py +++ b/openbb_terminal/core/session/session_controller.py @@ -50,7 +50,7 @@ def get_user_input() -> Tuple[str, str, bool]: is_password=True, ) save_str = s.prompt(message="> Remember me? (y/n): ", is_password=False).lower() - save = True if save_str == "y" else False + save = save_str == "y" return email, password, save From edef5b0b8d242bc3d098ea2ab911149f664fea43 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Wed, 5 Apr 2023 12:01:27 +0100 Subject: [PATCH 8/9] no need for new var --- openbb_terminal/core/session/session_controller.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openbb_terminal/core/session/session_controller.py b/openbb_terminal/core/session/session_controller.py index c71c0ebcfc27..8d3ccd1d5fa2 100644 --- a/openbb_terminal/core/session/session_controller.py +++ b/openbb_terminal/core/session/session_controller.py @@ -49,8 +49,7 @@ def get_user_input() -> Tuple[str, str, bool]: message="> Password: ", is_password=True, ) - save_str = s.prompt(message="> Remember me? (y/n): ", is_password=False).lower() - save = save_str == "y" + save = s.prompt(message="> Remember me? (y/n): ", is_password=False).lower() == "y" return email, password, save From 427bd7b735f6bbd4f4092a9b70c7b5aa741516c8 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Wed, 5 Apr 2023 12:22:18 +0100 Subject: [PATCH 9/9] pylint --- openbb_terminal/stocks/stocks_helper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openbb_terminal/stocks/stocks_helper.py b/openbb_terminal/stocks/stocks_helper.py index e2ccd2f168e6..48d85636827b 100644 --- a/openbb_terminal/stocks/stocks_helper.py +++ b/openbb_terminal/stocks/stocks_helper.py @@ -1,8 +1,8 @@ """Main helper.""" __docformat__ = "numpy" -# pylint: disable=unsupported-assignment-operation,too-many-lines -# pylint: disable=no-member,too-many-branches,too-many-arguments +# pylint: disable=unsupported-assignment-operation, too-many-lines +# pylint: disable=no-member, too-many-branches, too-many-arguments # pylint: disable=inconsistent-return-statements # pylint: disable=consider-using-dict-items