mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
* import order * pylint * no login, go to prompt * add logout and whoami * clear before prompt * black * these are unecessary * error * improve login prompt message * login does not follow the controller pattern, so will name it differently * nop * move logout and change to results * change return obj * ruff * pyupgrade * remove user from statics * message * fetch configs at start * remove unecessary func * unecessary dataclass * change user vars * change login flow * remote logout should not be used * simplify * fix double exit logout bug * wrong exception * apply keys * change controller * mypy * save if no internet * pylint * logout everywhere * breaking changes: move to local/hub models * unused import * fix logout bug * whoami in guest mode * add todo * small bug guest allowed * limit flair length * fix bug on user pull * logout working * handle no connection * logout user when logout * remove keys push * split logger funcs * commant apply configs for now * account to session * rename user * clear sounds better * breaking changes: splitting guest from logged users * pull imports up * delete session model * move logout func * add ability to save and apply keys from remote * no sensitive keys * add support for feature flags * unecessary print * allow settings from differnt modules * change setff to static * change way to set ff * fix bug in applying configs * simplify obbff application * bug on setting configs * allow text ff * obbff in settings * add upload to cfg_plot 1 * data sources + backend * this solves circular import? * move create_session to model * rever logs changes, not needed for now * sync optionally * outline account controller interface * don't sync when guest * block guest on installer * or not and * start routines * fix bug on ff, settings * is installer * implementing chavi suggestions * fix colors on installer prompt * Logging login (#4046) * basic logging for the login * removing unused import * hacking the logs custom filter to not filter the email * black * cooping with the new changes * removing redundant method * ruff * ruff * mypy * SDK login (#4051) * sdk login * adding to the trail map * minor fix * improve sdk expirience * adapting to new changes * add docstrings * block guest from account * change guest msg * change guest messages * add sync on/off * display onoff * missing paragraph * fix glitch on logout * add sys clear * filtering password * filtering the email from user * avoid writing to multiple log files if a user logs out * fix bug, guest allowed in installer without connection * log user on the sdk * split login from lauch * add clear and change messages on account * docstrings * start pull cmd * change account menu description * Fix login bug and decouple some logic (#4056) * fix bug, guest allowed in installer without connection * split login from lauch * improvements on the sdk login --------- Co-authored-by: hjoaquim <h.joaquim@campus.fct.unl.pt> * sync fix * change account controller description * ruff * add help on account cmds * update clear prompt * fix email not in jwt * remove jwt from requiremnts * pull command output * remove character * pull cmd when no data * add space below whoami * fix log filenotfound exception * changed arg name * delete .hist on logout * add asteriscs to password * pylint * uncomment rich config * show only diffs on pull * black# * warn when no changes# * pull msg was switched * apply diff only * breaking?: strbool change * reduce some code * add timeout to hub requests * black * add remote logout * success msg only if success * remove colors in prompt * update docstrings * keep timeout outside funcs * update clear * clear and patch * delete session * routine upload * move .his file to .openbb folder * change apply configs * refactor logout * remove mixed portfolio changes * fix bug in lock file * fix bug pwidth, pheight are floats * fix sources command & add choices * refactor timezone setting * userdata * fix flair * need to cast paths * cast on diff * fix flair default * save session test * get session * data * test remove * test remove with assert * add bad test cases * add exception cases to unittests * test remove cli hist file * black * test apply configs * test apply with sync flag * test create session, session model * login tests, session model * some tests for the hub_model * test logout user * black * test clear vars, reload * test create session * update user-json to user * update user class * add user tests * tests sdk session * tests for hub_model * start account controller tsts * unused import * tests account controller: clear, pull * tests for session_controller * logout success bugfix * add integration test for account * black * move routine related commands to other PR * test for the user input * completed tests for session controller * convert to hist to str) * fix import errors * ruff * ruff tests * fix qa * add help to settings cmds * ruff * fix pull keys bug * point to dev * account model tests * black * ruff * fix for empty feature settings * ruff * don't display config msg if wrong token * general msgs * remove print * ruff * fix sources not updated real time * missing return doc * add guest if no email * Routine remote storage (#4143) * add upload routine command * remove prints * point to local again * add commands * add delete * add download command and upload 409 * list comprehension * add download & save plus upload fixe * add user uuid folder * add list command * ruff * en.yml detail * provide choices to delete & download * add choices to upload * change menu text * starting adding unit tests * bad english * Update test_print_help.txt * genearl msgs * remove print * add docstrings * add unit tests to account controller * change parser * fix routine upload test * add to be implemented tests hub * add to be implemented tests local * add total pages to title * split list into model and view * add docstring * print msg if character * add local model tests * hub tests routines * fix test * point to dev and glob * fix small bug on upload * missing return * log decorators missing * black * ruff * change prompt display * rewrite test * rewrite expected * rewrite call * try passing git action * change .yml everywhere --------- Co-authored-by: Henrique Joaquim <h.joaquim@campus.fct.unl.pt> Co-authored-by: James Maslek <jmaslek11@gmail.com>
230 lines
7.4 KiB
Python
230 lines
7.4 KiB
Python
"""Feature Flags Controller Module"""
|
|
__docformat__ = "numpy"
|
|
|
|
# IMPORTATION STANDARD
|
|
import logging
|
|
from typing import List, Union
|
|
|
|
# IMPORTATION THIRDPARTY
|
|
from dotenv import set_key
|
|
|
|
# IMPORTATION INTERNAL
|
|
from openbb_terminal import feature_flags as obbff
|
|
from openbb_terminal.core.config.paths import USER_ENV_FILE
|
|
from openbb_terminal.custom_prompt_toolkit import NestedCompleter
|
|
from openbb_terminal.decorators import log_start_end
|
|
from openbb_terminal.menu import session
|
|
from openbb_terminal.parent_classes import BaseController
|
|
from openbb_terminal.rich_config import MenuText, console
|
|
from openbb_terminal.session.hub_model import patch_user_configs
|
|
from openbb_terminal.session.user import User
|
|
|
|
# pylint: disable=too-many-lines,no-member,too-many-public-methods,C0302
|
|
# pylint:disable=import-outside-toplevel
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class FeatureFlagsController(BaseController):
|
|
"""Feature Flags Controller class"""
|
|
|
|
CHOICES_COMMANDS: List[str] = [
|
|
"retryload",
|
|
"tab",
|
|
"cls",
|
|
"color",
|
|
"ion",
|
|
"watermark",
|
|
"cmdloc",
|
|
"promptkit",
|
|
"thoughts",
|
|
"reporthtml",
|
|
"exithelp",
|
|
"rcontext",
|
|
"rich",
|
|
"richpanel",
|
|
"tbhint",
|
|
"overwrite",
|
|
]
|
|
PATH = "/featflags/"
|
|
|
|
def __init__(self, queue: List[str] = None):
|
|
"""Constructor"""
|
|
super().__init__(queue)
|
|
|
|
if session and obbff.USE_PROMPT_TOOLKIT:
|
|
choices: dict = {c: {} for c in self.controller_choices}
|
|
self.completer = NestedCompleter.from_nested_dict(choices)
|
|
|
|
def print_help(self):
|
|
"""Print help"""
|
|
mt = MenuText("featflags/")
|
|
mt.add_info("_info_")
|
|
mt.add_raw("\n")
|
|
mt.add_setting("retryload", obbff.RETRY_WITH_LOAD)
|
|
mt.add_setting("tab", obbff.USE_TABULATE_DF)
|
|
mt.add_setting("cls", obbff.USE_CLEAR_AFTER_CMD)
|
|
mt.add_setting("color", obbff.USE_COLOR)
|
|
mt.add_setting("promptkit", obbff.USE_PROMPT_TOOLKIT)
|
|
mt.add_setting("thoughts", obbff.ENABLE_THOUGHTS_DAY)
|
|
mt.add_setting("reporthtml", obbff.OPEN_REPORT_AS_HTML)
|
|
mt.add_setting("exithelp", obbff.ENABLE_EXIT_AUTO_HELP)
|
|
mt.add_setting("rcontext", obbff.REMEMBER_CONTEXTS)
|
|
mt.add_setting("rich", obbff.ENABLE_RICH)
|
|
mt.add_setting("richpanel", obbff.ENABLE_RICH_PANEL)
|
|
mt.add_setting("ion", obbff.USE_ION)
|
|
mt.add_setting("watermark", obbff.USE_WATERMARK)
|
|
mt.add_setting("cmdloc", obbff.USE_CMD_LOCATION_FIGURE)
|
|
mt.add_setting("tbhint", obbff.TOOLBAR_HINT)
|
|
mt.add_setting("overwrite", obbff.FILE_OVERWITE)
|
|
|
|
console.print(text=mt.menu_text, menu="Feature Flags")
|
|
|
|
@staticmethod
|
|
def set_feature_flag(name: str, value: Union[bool, str], force: bool = False):
|
|
"""Set feature flag
|
|
|
|
Parameters
|
|
----------
|
|
name : str
|
|
Environment variable name
|
|
value : str
|
|
Environment variable value
|
|
force : bool, optional
|
|
Force remote storage of feature flag, by default False
|
|
"""
|
|
|
|
if User.is_guest():
|
|
set_key(str(USER_ENV_FILE), name, str(value))
|
|
|
|
# Remove "OPENBB_" prefix from env_var
|
|
if name.startswith("OPENBB_"):
|
|
name = name[7:]
|
|
|
|
# Set obbff.env_var_name = not env_var_value
|
|
setattr(obbff, name, value)
|
|
|
|
# Send feature flag to server
|
|
if not User.is_guest() and User.is_sync_enabled() or force:
|
|
patch_user_configs(
|
|
key=name,
|
|
value=str(value),
|
|
type_="settings",
|
|
auth_header=User.get_auth_header(),
|
|
)
|
|
|
|
def call_overwrite(self, _):
|
|
"""Process overwrite command"""
|
|
FeatureFlagsController.set_feature_flag(
|
|
"OPENBB_FILE_OVERWITE", not obbff.FILE_OVERWITE
|
|
)
|
|
|
|
def call_retryload(self, _):
|
|
"""Process retryload command"""
|
|
FeatureFlagsController.set_feature_flag(
|
|
"OPENBB_RETRY_WITH_LOAD", not obbff.RETRY_WITH_LOAD
|
|
)
|
|
|
|
@log_start_end(log=logger)
|
|
def call_tab(self, _):
|
|
"""Process tab command"""
|
|
FeatureFlagsController.set_feature_flag(
|
|
"OPENBB_USE_TABULATE_DF", not obbff.USE_TABULATE_DF
|
|
)
|
|
|
|
@log_start_end(log=logger)
|
|
def call_cls(self, _):
|
|
"""Process cls command"""
|
|
FeatureFlagsController.set_feature_flag(
|
|
"OPENBB_USE_CLEAR_AFTER_CMD", not obbff.USE_CLEAR_AFTER_CMD
|
|
)
|
|
|
|
@log_start_end(log=logger)
|
|
def call_color(self, _):
|
|
"""Process color command"""
|
|
FeatureFlagsController.set_feature_flag("OPENBB_USE_COLOR", not obbff.USE_COLOR)
|
|
|
|
@log_start_end(log=logger)
|
|
def call_promptkit(self, _):
|
|
"""Process promptkit command"""
|
|
FeatureFlagsController.set_feature_flag(
|
|
"OPENBB_USE_PROMPT_TOOLKIT", not obbff.USE_PROMPT_TOOLKIT
|
|
)
|
|
|
|
@log_start_end(log=logger)
|
|
def call_thoughts(self, _):
|
|
"""Process thoughts command"""
|
|
FeatureFlagsController.set_feature_flag(
|
|
"OPENBB_ENABLE_THOUGHTS_DAY", not obbff.ENABLE_THOUGHTS_DAY
|
|
)
|
|
|
|
@log_start_end(log=logger)
|
|
def call_reporthtml(self, _):
|
|
"""Process reporthtml command"""
|
|
FeatureFlagsController.set_feature_flag(
|
|
"OPENBB_OPEN_REPORT_AS_HTML", not obbff.OPEN_REPORT_AS_HTML
|
|
)
|
|
|
|
@log_start_end(log=logger)
|
|
def call_exithelp(self, _):
|
|
"""Process exithelp command"""
|
|
FeatureFlagsController.set_feature_flag(
|
|
"OPENBB_ENABLE_EXIT_AUTO_HELP", not obbff.ENABLE_EXIT_AUTO_HELP
|
|
)
|
|
|
|
@log_start_end(log=logger)
|
|
def call_rcontext(self, _):
|
|
"""Process rcontext command"""
|
|
FeatureFlagsController.set_feature_flag(
|
|
"OPENBB_REMEMBER_CONTEXTS", not obbff.REMEMBER_CONTEXTS
|
|
)
|
|
|
|
@log_start_end(log=logger)
|
|
def call_dt(self, _):
|
|
"""Process dt command"""
|
|
FeatureFlagsController.set_feature_flag(
|
|
"OPENBB_USE_DATETIME", not obbff.USE_DATETIME
|
|
)
|
|
|
|
@log_start_end(log=logger)
|
|
def call_rich(self, _):
|
|
"""Process rich command"""
|
|
FeatureFlagsController.set_feature_flag(
|
|
"OPENBB_ENABLE_RICH", not obbff.ENABLE_RICH
|
|
)
|
|
|
|
@log_start_end(log=logger)
|
|
def call_richpanel(self, _):
|
|
"""Process richpanel command"""
|
|
FeatureFlagsController.set_feature_flag(
|
|
"OPENBB_ENABLE_RICH_PANEL", not obbff.ENABLE_RICH_PANEL
|
|
)
|
|
|
|
@log_start_end(log=logger)
|
|
def call_ion(self, _):
|
|
"""Process ion command"""
|
|
FeatureFlagsController.set_feature_flag("OPENBB_USE_ION", not obbff.USE_ION)
|
|
|
|
@log_start_end(log=logger)
|
|
def call_watermark(self, _):
|
|
"""Process watermark command"""
|
|
FeatureFlagsController.set_feature_flag(
|
|
"OPENBB_USE_WATERMARK", not obbff.USE_WATERMARK
|
|
)
|
|
|
|
@log_start_end(log=logger)
|
|
def call_cmdloc(self, _):
|
|
"""Process cmdloc command"""
|
|
FeatureFlagsController.set_feature_flag(
|
|
"OPENBB_USE_CMD_LOCATION_FIGURE", not obbff.USE_CMD_LOCATION_FIGURE
|
|
)
|
|
|
|
@log_start_end(log=logger)
|
|
def call_tbhint(self, _):
|
|
"""Process tbhint command"""
|
|
if obbff.TOOLBAR_HINT:
|
|
console.print("Will take effect when running terminal next.")
|
|
FeatureFlagsController.set_feature_flag(
|
|
"OPENBB_TOOLBAR_HINT", not obbff.TOOLBAR_HINT
|
|
)
|