diff --git a/openbb_sdk/sdk/core/openbb_core/app/command_runner.py b/openbb_sdk/sdk/core/openbb_core/app/command_runner.py index e62327a59e25..6a92d8ad54e3 100644 --- a/openbb_sdk/sdk/core/openbb_core/app/command_runner.py +++ b/openbb_sdk/sdk/core/openbb_core/app/command_runner.py @@ -10,6 +10,7 @@ from pydantic import BaseConfig, Extra, create_model from openbb_core.app.charting_manager import ChartingManager +from openbb_core.app.env import Env from openbb_core.app.logs.logging_manager import LoggingManager from openbb_core.app.model.abstract.error import OpenBBError from openbb_core.app.model.abstract.warning import cast_warning @@ -189,13 +190,11 @@ class StaticCommandRunner: charting_manager: ChartingManager = ChartingManager() @classmethod - def __command( - cls, system_settings: SystemSettings, func: Callable, kwargs: Dict[str, Any] - ) -> OBBject: + def __command(cls, func: Callable, kwargs: Dict[str, Any]) -> OBBject: """Run a command and return the output""" context_manager: Union[warnings.catch_warnings, ContextManager[None]] = ( warnings.catch_warnings(record=True) - if not system_settings.debug_mode + if not Env().DEBUG_MODE else nullcontext() ) @@ -265,7 +264,6 @@ def __execute_func( try: obbject = cls.__command( - system_settings=system_settings, func=func, kwargs=kwargs, ) diff --git a/openbb_sdk/sdk/core/openbb_core/app/env.py b/openbb_sdk/sdk/core/openbb_core/app/env.py new file mode 100644 index 000000000000..131eda8a606b --- /dev/null +++ b/openbb_sdk/sdk/core/openbb_core/app/env.py @@ -0,0 +1,31 @@ +import os +from os import _Environ +from pathlib import Path + +import dotenv + +from openbb_core.app.model.abstract.singleton import SingletonMeta + + +class Env(metaclass=SingletonMeta): + _environ: _Environ + + def __init__(self) -> None: + current_dir = os.path.dirname(os.path.realpath(__file__)) + dotenv.load_dotenv(Path(current_dir, ".env")) + self._environ = os.environ + + @property + def DEBUG_MODE(self) -> bool: + return self.str_to_bool(self._environ.get("DEBUG_MODE", False)) + + @staticmethod + def str_to_bool(value) -> bool: + """Match a string to a boolean value.""" + if isinstance(value, bool): + return value + if value.lower() in {"false", "f", "0", "no", "n"}: + return False + if value.lower() in {"true", "t", "1", "yes", "y"}: + return True + raise ValueError(f"Failed to cast {value} to bool.") diff --git a/openbb_sdk/sdk/core/openbb_core/app/model/charts/charting_settings.py b/openbb_sdk/sdk/core/openbb_core/app/model/charts/charting_settings.py index e07d2c18f441..30d9bf89c60e 100644 --- a/openbb_sdk/sdk/core/openbb_core/app/model/charts/charting_settings.py +++ b/openbb_sdk/sdk/core/openbb_core/app/model/charts/charting_settings.py @@ -1,6 +1,7 @@ from pathlib import Path from typing import Optional +from openbb_core.app.env import Env from openbb_core.app.logs.utils.utils import get_app_id from openbb_core.app.model.system_settings import SystemSettings from openbb_core.app.model.user_settings import UserSettings @@ -28,7 +29,7 @@ def __init__( self.python_version: str = system_settings.python_version self.test_mode = system_settings.test_mode self.app_id: str = get_app_id(user_data_directory) - self.debug_mode: bool = system_settings.debug_mode + self.debug_mode: bool = Env().DEBUG_MODE self.headless: bool = system_settings.headless # User self.plot_enable_pywry: bool = user_settings.preferences.plot_enable_pywry diff --git a/openbb_sdk/sdk/core/openbb_core/app/model/system_settings.py b/openbb_sdk/sdk/core/openbb_core/app/model/system_settings.py index 95126730b00c..81d34cb116dc 100644 --- a/openbb_sdk/sdk/core/openbb_core/app/model/system_settings.py +++ b/openbb_sdk/sdk/core/openbb_core/app/model/system_settings.py @@ -45,7 +45,6 @@ class SystemSettings(Tagged): # Others test_mode: bool = False - debug_mode: bool = False headless: bool = False class Config: diff --git a/openbb_sdk/sdk/core/openbb_core/app/router.py b/openbb_sdk/sdk/core/openbb_core/app/router.py index 18b37c341429..1400b57f98ed 100644 --- a/openbb_sdk/sdk/core/openbb_core/app/router.py +++ b/openbb_sdk/sdk/core/openbb_core/app/router.py @@ -22,6 +22,7 @@ from pydantic.validators import find_validators from typing_extensions import Annotated, ParamSpec, _AnnotatedAlias +from openbb_core.app.env import Env from openbb_core.app.model.abstract.warning import OpenBBWarning from openbb_core.app.model.command_context import CommandContext from openbb_core.app.model.obbject import OBBject @@ -238,12 +239,13 @@ def complete_signature( if model: if model not in provider_interface.models: - warnings.warn( - message=f"\nSkipping api route '/{func.__name__}'.\n" - f"Model '{model}' not found.\n\n" - "Check available models in ProviderInterface().models", - category=OpenBBWarning, - ) + if Env().DEBUG_MODE: + warnings.warn( + message=f"\nSkipping api route '/{func.__name__}'.\n" + f"Model '{model}' not found.\n\n" + "Check available models in ProviderInterface().models", + category=OpenBBWarning, + ) return None cls.validate_signature( diff --git a/openbb_sdk/sdk/core/openbb_core/app/service/system_service.py b/openbb_sdk/sdk/core/openbb_core/app/service/system_service.py index b4338417f507..92313b1f13aa 100644 --- a/openbb_sdk/sdk/core/openbb_core/app/service/system_service.py +++ b/openbb_sdk/sdk/core/openbb_core/app/service/system_service.py @@ -14,7 +14,6 @@ class SystemService: "log_collect", "test_mode", "headless", - "debug_mode", "dbms_uri", } diff --git a/openbb_sdk/sdk/core/tests/app/model/charts/test_chart_settings.py b/openbb_sdk/sdk/core/tests/app/model/charts/test_chart_settings.py index e5635b23e429..eea479aa76d0 100644 --- a/openbb_sdk/sdk/core/tests/app/model/charts/test_chart_settings.py +++ b/openbb_sdk/sdk/core/tests/app/model/charts/test_chart_settings.py @@ -19,7 +19,6 @@ mock_system_settings.version = "mock_version" mock_system_settings.python_version = "mock_python_version" mock_system_settings.test_mode = True -mock_system_settings.debug_mode = True mock_system_settings.headless = True @@ -36,7 +35,6 @@ def test_charting_settings(): assert charting_settings.python_version == "mock_python_version" assert charting_settings.test_mode is True assert charting_settings.app_id == "mock_app_id" - assert charting_settings.debug_mode is True assert charting_settings.headless is True assert charting_settings.plot_enable_pywry is True assert charting_settings.plot_pywry_width == 100