mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-13 12:51:49 +00:00
New path for .env (#2508)
* add log path * add test to check if log file is in correct dir * env path * black * mypy fix * linting * add make_paths and change references * terminal change * change constants to paths * change names * black * mypy * mypy * pylint else * add make paths * remove custom user dir name Co-authored-by: Chavithra <chavithra@gmail.com>
This commit is contained in:
@@ -5,12 +5,13 @@ from distutils.util import strtobool
|
||||
# IMPORTATION THIRDPARTY
|
||||
import dotenv
|
||||
|
||||
from openbb_terminal.core.config.paths import USER_ENV_FILE, ENV_FILE_REPOSITORY
|
||||
|
||||
# IMPORTATION INTERNAL
|
||||
from .helper_classes import TerminalStyle as _TerminalStyle
|
||||
|
||||
env_files = [f for f in os.listdir() if f.endswith(".env")]
|
||||
if env_files:
|
||||
dotenv.load_dotenv(env_files[0])
|
||||
dotenv.load_dotenv(USER_ENV_FILE)
|
||||
dotenv.load_dotenv(ENV_FILE_REPOSITORY, override=True)
|
||||
|
||||
# Terminal UX section
|
||||
theme = _TerminalStyle(
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
# IMPORTATION STANDARD
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
REPO_DIR = Path(__file__).parent.parent.parent.parent
|
||||
USER_DATA_DIR = Path.home() / "OpenBBUserData"
|
||||
USER_HOME = Path(os.path.expanduser("~"))
|
||||
if not os.path.exists(USER_DATA_DIR):
|
||||
os.mkdir(USER_DATA_DIR)
|
||||
ENV_FILE = REPO_DIR.joinpath(".env")
|
||||
28
openbb_terminal/core/config/make_paths.py
Normal file
28
openbb_terminal/core/config/make_paths.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# IMPORTATION STANDARD
|
||||
import os
|
||||
from openbb_terminal.core.config.paths import (
|
||||
SETTINGS_DIRECTORY,
|
||||
USER_DATA_DIRECTORY,
|
||||
USER_ENV_FILE,
|
||||
ENV_FILE_REPOSITORY,
|
||||
)
|
||||
|
||||
|
||||
def create_paths():
|
||||
"""
|
||||
Creates dirs/files for user data and .env files outside the
|
||||
terminal if they don't exist
|
||||
"""
|
||||
if not os.path.exists(SETTINGS_DIRECTORY):
|
||||
os.mkdir(SETTINGS_DIRECTORY)
|
||||
|
||||
if not USER_ENV_FILE.is_file():
|
||||
with open(str(USER_ENV_FILE), "w"):
|
||||
pass
|
||||
|
||||
if not ENV_FILE_REPOSITORY.is_file():
|
||||
with open(str(ENV_FILE_REPOSITORY), "w"):
|
||||
pass
|
||||
|
||||
if not os.path.exists(USER_DATA_DIRECTORY):
|
||||
os.mkdir(USER_DATA_DIRECTORY)
|
||||
@@ -3,9 +3,9 @@ from pathlib import Path
|
||||
|
||||
|
||||
HOME_DIRECTORY = Path.home()
|
||||
REPOSITORY_DIRECTORY = Path(__file__).parent.parent.parent.parent
|
||||
USER_DATA_DIRECTORY = HOME_DIRECTORY / "OpenBBUserData"
|
||||
REPO_DIRECTORY = Path(__file__).parent.parent.parent.parent
|
||||
SETTINGS_DIRECTORY = HOME_DIRECTORY / ".openbb_terminal"
|
||||
|
||||
REPOSITORY_ENV_FILE = REPOSITORY_DIRECTORY / ".env"
|
||||
ENV_FILE_REPOSITORY = HOME_DIRECTORY / ".env"
|
||||
USER_ENV_FILE = SETTINGS_DIRECTORY / ".env"
|
||||
|
||||
USER_DATA_DIRECTORY = HOME_DIRECTORY / "OpenBBUserData"
|
||||
|
||||
@@ -6,7 +6,7 @@ import re
|
||||
# IMPORTATION THIRDPARTY
|
||||
|
||||
# IMPORTATION INTERNAL
|
||||
from openbb_terminal.core.config.constants import REPO_DIR
|
||||
from openbb_terminal.core.config.paths import REPO_DIRECTORY
|
||||
from openbb_terminal.core.log.generation.settings import AppSettings
|
||||
|
||||
|
||||
@@ -57,9 +57,9 @@ class FormatterWithExceptions(logging.Formatter):
|
||||
s_list.append("suspected_ip")
|
||||
elif "@" in word and "." in word:
|
||||
s_list.append("suspected_email")
|
||||
elif f"{REPO_DIR.name}{os.sep}" in word:
|
||||
elif f"{REPO_DIRECTORY.name}{os.sep}" in word:
|
||||
s_list.append(
|
||||
word.split(f"{REPO_DIR.name}{os.sep}")[1]
|
||||
word.split(f"{REPO_DIRECTORY.name}{os.sep}")[1]
|
||||
.replace('"', "")
|
||||
.replace("'", "")
|
||||
)
|
||||
|
||||
@@ -83,20 +83,24 @@ class FeatureFlagsController(BaseController):
|
||||
def call_logcollection(self, _):
|
||||
"""Process logcollection command"""
|
||||
obbff.LOG_COLLECTION = not obbff.LOG_COLLECTION
|
||||
set_key(obbff.ENV_FILE, "OPENBB_LOG_COLLECTION", str(obbff.LOG_COLLECTION))
|
||||
set_key(obbff.USER_ENV_FILE, "OPENBB_LOG_COLLECTION", str(obbff.LOG_COLLECTION))
|
||||
console.print("")
|
||||
|
||||
def call_retryload(self, _):
|
||||
"""Process retryload command"""
|
||||
obbff.RETRY_WITH_LOAD = not obbff.RETRY_WITH_LOAD
|
||||
set_key(obbff.ENV_FILE, "OPENBB_RETRY_WITH_LOAD", str(obbff.RETRY_WITH_LOAD))
|
||||
set_key(
|
||||
obbff.USER_ENV_FILE, "OPENBB_RETRY_WITH_LOAD", str(obbff.RETRY_WITH_LOAD)
|
||||
)
|
||||
console.print("")
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_tab(self, _):
|
||||
"""Process tab command"""
|
||||
obbff.USE_TABULATE_DF = not obbff.USE_TABULATE_DF
|
||||
set_key(obbff.ENV_FILE, "OPENBB_USE_TABULATE_DF", str(obbff.USE_TABULATE_DF))
|
||||
set_key(
|
||||
obbff.USER_ENV_FILE, "OPENBB_USE_TABULATE_DF", str(obbff.USE_TABULATE_DF)
|
||||
)
|
||||
console.print("")
|
||||
|
||||
@log_start_end(log=logger)
|
||||
@@ -104,7 +108,7 @@ class FeatureFlagsController(BaseController):
|
||||
"""Process cls command"""
|
||||
obbff.USE_CLEAR_AFTER_CMD = not obbff.USE_CLEAR_AFTER_CMD
|
||||
set_key(
|
||||
obbff.ENV_FILE,
|
||||
obbff.USER_ENV_FILE,
|
||||
"OPENBB_USE_CLEAR_AFTER_CMD",
|
||||
str(obbff.USE_CLEAR_AFTER_CMD),
|
||||
)
|
||||
@@ -114,7 +118,7 @@ class FeatureFlagsController(BaseController):
|
||||
def call_color(self, _):
|
||||
"""Process color command"""
|
||||
obbff.USE_COLOR = not obbff.USE_COLOR
|
||||
set_key(obbff.ENV_FILE, "OPENBB_USE_COLOR", str(obbff.USE_COLOR))
|
||||
set_key(obbff.USER_ENV_FILE, "OPENBB_USE_COLOR", str(obbff.USE_COLOR))
|
||||
console.print("")
|
||||
|
||||
@log_start_end(log=logger)
|
||||
@@ -122,7 +126,7 @@ class FeatureFlagsController(BaseController):
|
||||
"""Process promptkit command"""
|
||||
obbff.USE_PROMPT_TOOLKIT = not obbff.USE_PROMPT_TOOLKIT
|
||||
set_key(
|
||||
obbff.ENV_FILE,
|
||||
obbff.USER_ENV_FILE,
|
||||
"OPENBB_USE_PROMPT_TOOLKIT",
|
||||
str(obbff.USE_PROMPT_TOOLKIT),
|
||||
)
|
||||
@@ -132,7 +136,7 @@ class FeatureFlagsController(BaseController):
|
||||
def call_predict(self, _):
|
||||
"""Process predict command"""
|
||||
obbff.ENABLE_PREDICT = not obbff.ENABLE_PREDICT
|
||||
set_key(obbff.ENV_FILE, "OPENBB_ENABLE_PREDICT", str(obbff.ENABLE_PREDICT))
|
||||
set_key(obbff.USER_ENV_FILE, "OPENBB_ENABLE_PREDICT", str(obbff.ENABLE_PREDICT))
|
||||
console.print("")
|
||||
|
||||
@log_start_end(log=logger)
|
||||
@@ -140,7 +144,7 @@ class FeatureFlagsController(BaseController):
|
||||
"""Process thoughts command"""
|
||||
obbff.ENABLE_THOUGHTS_DAY = not obbff.ENABLE_THOUGHTS_DAY
|
||||
set_key(
|
||||
obbff.ENV_FILE,
|
||||
obbff.USER_ENV_FILE,
|
||||
"OPENBB_ENABLE_THOUGHTS_DAY",
|
||||
str(obbff.ENABLE_THOUGHTS_DAY),
|
||||
)
|
||||
@@ -151,7 +155,7 @@ class FeatureFlagsController(BaseController):
|
||||
"""Process reporthtml command"""
|
||||
obbff.OPEN_REPORT_AS_HTML = not obbff.OPEN_REPORT_AS_HTML
|
||||
set_key(
|
||||
obbff.ENV_FILE,
|
||||
obbff.USER_ENV_FILE,
|
||||
"OPENBB_OPEN_REPORT_AS_HTML",
|
||||
str(obbff.OPEN_REPORT_AS_HTML),
|
||||
)
|
||||
@@ -162,7 +166,7 @@ class FeatureFlagsController(BaseController):
|
||||
"""Process exithelp command"""
|
||||
obbff.ENABLE_EXIT_AUTO_HELP = not obbff.ENABLE_EXIT_AUTO_HELP
|
||||
set_key(
|
||||
obbff.ENV_FILE,
|
||||
obbff.USER_ENV_FILE,
|
||||
"OPENBB_ENABLE_EXIT_AUTO_HELP",
|
||||
str(obbff.ENABLE_EXIT_AUTO_HELP),
|
||||
)
|
||||
@@ -173,7 +177,7 @@ class FeatureFlagsController(BaseController):
|
||||
"""Process rcontext command"""
|
||||
obbff.REMEMBER_CONTEXTS = not obbff.REMEMBER_CONTEXTS
|
||||
set_key(
|
||||
obbff.ENV_FILE,
|
||||
obbff.USER_ENV_FILE,
|
||||
"OPENBB_REMEMBER_CONTEXTS",
|
||||
str(obbff.REMEMBER_CONTEXTS),
|
||||
)
|
||||
@@ -183,14 +187,14 @@ class FeatureFlagsController(BaseController):
|
||||
def call_dt(self, _):
|
||||
"""Process dt command"""
|
||||
obbff.USE_DATETIME = not obbff.USE_DATETIME
|
||||
set_key(obbff.ENV_FILE, "OPENBB_USE_DATETIME", str(obbff.USE_DATETIME))
|
||||
set_key(obbff.USER_ENV_FILE, "OPENBB_USE_DATETIME", str(obbff.USE_DATETIME))
|
||||
console.print("")
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_rich(self, _):
|
||||
"""Process rich command"""
|
||||
obbff.ENABLE_RICH = not obbff.ENABLE_RICH
|
||||
set_key(obbff.ENV_FILE, "OPENBB_ENABLE_RICH", str(obbff.ENABLE_RICH))
|
||||
set_key(obbff.USER_ENV_FILE, "OPENBB_ENABLE_RICH", str(obbff.ENABLE_RICH))
|
||||
console.print("")
|
||||
|
||||
@log_start_end(log=logger)
|
||||
@@ -198,7 +202,7 @@ class FeatureFlagsController(BaseController):
|
||||
"""Process richpanel command"""
|
||||
obbff.ENABLE_RICH_PANEL = not obbff.ENABLE_RICH_PANEL
|
||||
set_key(
|
||||
obbff.ENV_FILE,
|
||||
obbff.USER_ENV_FILE,
|
||||
"OPENBB_ENABLE_RICH_PANEL",
|
||||
str(obbff.ENABLE_RICH_PANEL),
|
||||
)
|
||||
@@ -208,14 +212,14 @@ class FeatureFlagsController(BaseController):
|
||||
def call_ion(self, _):
|
||||
"""Process ion command"""
|
||||
obbff.USE_ION = not obbff.USE_ION
|
||||
set_key(obbff.ENV_FILE, "OPENBB_USE_ION", str(obbff.USE_ION))
|
||||
set_key(obbff.USER_ENV_FILE, "OPENBB_USE_ION", str(obbff.USE_ION))
|
||||
console.print("")
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_watermark(self, _):
|
||||
"""Process watermark command"""
|
||||
obbff.USE_WATERMARK = not obbff.USE_WATERMARK
|
||||
set_key(obbff.ENV_FILE, "OPENBB_USE_WATERMARK", str(obbff.USE_WATERMARK))
|
||||
set_key(obbff.USER_ENV_FILE, "OPENBB_USE_WATERMARK", str(obbff.USE_WATERMARK))
|
||||
console.print("")
|
||||
|
||||
@log_start_end(log=logger)
|
||||
@@ -223,7 +227,7 @@ class FeatureFlagsController(BaseController):
|
||||
"""Process cmdloc command"""
|
||||
obbff.USE_CMD_LOCATION_FIGURE = not obbff.USE_CMD_LOCATION_FIGURE
|
||||
set_key(
|
||||
obbff.ENV_FILE,
|
||||
obbff.USER_ENV_FILE,
|
||||
"OPENBB_USE_CMD_LOCATION_FIGURE",
|
||||
str(obbff.USE_CMD_LOCATION_FIGURE),
|
||||
)
|
||||
@@ -236,7 +240,7 @@ class FeatureFlagsController(BaseController):
|
||||
console.print("Will take effect when running terminal next.")
|
||||
obbff.TOOLBAR_HINT = not obbff.TOOLBAR_HINT
|
||||
set_key(
|
||||
obbff.ENV_FILE,
|
||||
obbff.USER_ENV_FILE,
|
||||
"OPENBB_TOOLBAR_HINT",
|
||||
str(obbff.TOOLBAR_HINT),
|
||||
)
|
||||
|
||||
@@ -9,7 +9,7 @@ from dotenv import load_dotenv
|
||||
import i18n
|
||||
|
||||
# IMPORTATION INTERNAL
|
||||
from openbb_terminal.core.config.constants import ENV_FILE
|
||||
from openbb_terminal.core.config.paths import USER_ENV_FILE, ENV_FILE_REPOSITORY
|
||||
|
||||
# pylint: disable=no-member
|
||||
|
||||
@@ -22,8 +22,8 @@ i18n.load_path.append(i18n_dict_location)
|
||||
i18n.set("locale", "en")
|
||||
i18n.set("filename_format", "{locale}.{format}")
|
||||
|
||||
if ENV_FILE.is_file():
|
||||
load_dotenv(dotenv_path=ENV_FILE, override=True)
|
||||
load_dotenv(USER_ENV_FILE)
|
||||
load_dotenv(ENV_FILE_REPOSITORY, override=True)
|
||||
|
||||
# Retry unknown commands with `load`
|
||||
RETRY_WITH_LOAD = strtobool(os.getenv("OPENBB_RETRY_WITH_LOAD", "False"))
|
||||
|
||||
@@ -36,7 +36,7 @@ import numpy as np
|
||||
from openbb_terminal.rich_config import console
|
||||
from openbb_terminal import feature_flags as obbff
|
||||
from openbb_terminal import config_plot as cfgPlot
|
||||
from openbb_terminal.core.config.constants import USER_HOME
|
||||
from openbb_terminal.core.config.paths import HOME_DIRECTORY
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -103,7 +103,7 @@ def check_path(path: str) -> str:
|
||||
if not path:
|
||||
return ""
|
||||
if path[0] == "~":
|
||||
path = path.replace("~", USER_HOME.as_posix())
|
||||
path = path.replace("~", HOME_DIRECTORY.as_posix())
|
||||
# Return string of path if such relative path exists
|
||||
if os.path.isfile(path):
|
||||
return path
|
||||
@@ -1272,7 +1272,7 @@ def compose_export_path(func_name: str, dir_path: str) -> Tuple[str, str]:
|
||||
else:
|
||||
if obbff.PACKAGED_APPLICATION:
|
||||
full_path_dir = os.path.join(
|
||||
USER_HOME.as_posix(), "Desktop", "OPENBB-exports"
|
||||
HOME_DIRECTORY.as_posix(), "Desktop", "OPENBB-exports"
|
||||
)
|
||||
|
||||
if not os.path.isdir(full_path_dir):
|
||||
|
||||
@@ -25,6 +25,7 @@ from oandapyV20.exceptions import V20Error
|
||||
|
||||
from openbb_terminal import config_terminal as cfg
|
||||
from openbb_terminal import feature_flags as obbff
|
||||
from openbb_terminal.core.config.paths import USER_ENV_FILE
|
||||
from openbb_terminal.cryptocurrency.coinbase_helpers import (
|
||||
CoinbaseProAuth,
|
||||
make_coinbase_request,
|
||||
@@ -79,7 +80,10 @@ class KeysController(BaseController): # pylint: disable=too-many-public-methods
|
||||
cfg_dict: Dict = {}
|
||||
|
||||
def __init__(
|
||||
self, queue: List[str] = None, menu_usage: bool = True, env_file: str = ".env"
|
||||
self,
|
||||
queue: List[str] = None,
|
||||
menu_usage: bool = True,
|
||||
env_file: str = str(USER_ENV_FILE),
|
||||
):
|
||||
"""Constructor"""
|
||||
super().__init__(queue)
|
||||
|
||||
@@ -16,6 +16,7 @@ from prompt_toolkit.completion import NestedCompleter
|
||||
# IMPORTATION INTERNAL
|
||||
from openbb_terminal import config_plot as cfg_plot
|
||||
from openbb_terminal import feature_flags as obbff
|
||||
from openbb_terminal.core.config.paths import USER_ENV_FILE
|
||||
from openbb_terminal.decorators import log_start_end
|
||||
from openbb_terminal.helper_funcs import (
|
||||
get_flair,
|
||||
@@ -63,7 +64,7 @@ class SettingsController(BaseController):
|
||||
if lang.endswith(".yml")
|
||||
]
|
||||
|
||||
def __init__(self, queue: List[str] = None, env_file: str = ".env"):
|
||||
def __init__(self, queue: List[str] = None, env_file: str = str(USER_ENV_FILE)):
|
||||
"""Constructor"""
|
||||
super().__init__(queue)
|
||||
self.env_file = env_file
|
||||
@@ -138,7 +139,7 @@ class SettingsController(BaseController):
|
||||
def call_dt(self, _):
|
||||
"""Process dt command"""
|
||||
obbff.USE_DATETIME = not obbff.USE_DATETIME
|
||||
set_key(obbff.ENV_FILE, "OPENBB_USE_DATETIME", str(obbff.USE_DATETIME))
|
||||
set_key(obbff.USER_ENV_FILE, "OPENBB_USE_DATETIME", str(obbff.USE_DATETIME))
|
||||
console.print("")
|
||||
|
||||
@log_start_end(log=logger)
|
||||
@@ -175,7 +176,7 @@ class SettingsController(BaseController):
|
||||
console.print(e)
|
||||
obbff.PREFERRED_DATA_SOURCE_FILE = ns_parser.value
|
||||
set_key(
|
||||
obbff.ENV_FILE,
|
||||
obbff.USER_ENV_FILE,
|
||||
"OPENBB_PREFERRED_DATA_SOURCE_FILE",
|
||||
str(ns_parser.value),
|
||||
)
|
||||
@@ -186,7 +187,7 @@ class SettingsController(BaseController):
|
||||
"""Process autoscaling command"""
|
||||
obbff.USE_PLOT_AUTOSCALING = not obbff.USE_PLOT_AUTOSCALING
|
||||
set_key(
|
||||
obbff.ENV_FILE,
|
||||
obbff.USER_ENV_FILE,
|
||||
"OPENBB_USE_PLOT_AUTOSCALING",
|
||||
str(obbff.USE_PLOT_AUTOSCALING),
|
||||
)
|
||||
@@ -213,7 +214,7 @@ class SettingsController(BaseController):
|
||||
other_args.insert(0, "-v")
|
||||
ns_parser = parse_simple_args(parser, other_args)
|
||||
if ns_parser and ns_parser.value:
|
||||
set_key(obbff.ENV_FILE, "OPENBB_PLOT_DPI", str(ns_parser.value))
|
||||
set_key(obbff.USER_ENV_FILE, "OPENBB_PLOT_DPI", str(ns_parser.value))
|
||||
cfg_plot.PLOT_DPI = ns_parser.value
|
||||
console.print("")
|
||||
|
||||
@@ -238,7 +239,7 @@ class SettingsController(BaseController):
|
||||
other_args.insert(0, "-v")
|
||||
ns_parser = parse_simple_args(parser, other_args)
|
||||
if ns_parser:
|
||||
set_key(obbff.ENV_FILE, "OPENBB_PLOT_HEIGHT", str(ns_parser.value))
|
||||
set_key(obbff.USER_ENV_FILE, "OPENBB_PLOT_HEIGHT", str(ns_parser.value))
|
||||
cfg_plot.PLOT_HEIGHT = ns_parser.value
|
||||
console.print("")
|
||||
|
||||
@@ -263,7 +264,7 @@ class SettingsController(BaseController):
|
||||
other_args.insert(0, "-v")
|
||||
ns_parser = parse_simple_args(parser, other_args)
|
||||
if ns_parser:
|
||||
set_key(obbff.ENV_FILE, "OPENBB_PLOT_WIDTH", str(ns_parser.value))
|
||||
set_key(obbff.USER_ENV_FILE, "OPENBB_PLOT_WIDTH", str(ns_parser.value))
|
||||
cfg_plot.PLOT_WIDTH = ns_parser.value
|
||||
console.print("")
|
||||
|
||||
@@ -288,7 +289,7 @@ class SettingsController(BaseController):
|
||||
ns_parser = parse_simple_args(parser, other_args)
|
||||
if ns_parser:
|
||||
set_key(
|
||||
obbff.ENV_FILE,
|
||||
obbff.USER_ENV_FILE,
|
||||
"OPENBB_PLOT_HEIGHT_PERCENTAGE",
|
||||
str(ns_parser.value),
|
||||
)
|
||||
@@ -316,7 +317,7 @@ class SettingsController(BaseController):
|
||||
ns_parser = parse_simple_args(parser, other_args)
|
||||
if ns_parser:
|
||||
set_key(
|
||||
obbff.ENV_FILE,
|
||||
obbff.USER_ENV_FILE,
|
||||
"OPENBB_PLOT_WIDTH_PERCENTAGE",
|
||||
str(ns_parser.value),
|
||||
)
|
||||
@@ -343,7 +344,7 @@ class SettingsController(BaseController):
|
||||
other_args.insert(0, "-v")
|
||||
ns_parser = parse_simple_args(parser, other_args)
|
||||
if ns_parser:
|
||||
set_key(obbff.ENV_FILE, "OPENBB_MONITOR", str(ns_parser.value))
|
||||
set_key(obbff.USER_ENV_FILE, "OPENBB_MONITOR", str(ns_parser.value))
|
||||
cfg_plot.MONITOR = ns_parser.value
|
||||
console.print("")
|
||||
|
||||
@@ -367,7 +368,7 @@ class SettingsController(BaseController):
|
||||
other_args.insert(0, "-v")
|
||||
ns_parser = parse_simple_args(parser, other_args)
|
||||
if ns_parser:
|
||||
set_key(obbff.ENV_FILE, "OPENBB_BACKEND", str(ns_parser.value))
|
||||
set_key(obbff.USER_ENV_FILE, "OPENBB_BACKEND", str(ns_parser.value))
|
||||
if ns_parser.value == "None":
|
||||
cfg_plot.BACKEND = None # type: ignore
|
||||
else:
|
||||
@@ -397,7 +398,9 @@ class SettingsController(BaseController):
|
||||
ns_parser = parse_simple_args(parser, other_args)
|
||||
if ns_parser:
|
||||
if ns_parser.value:
|
||||
set_key(obbff.ENV_FILE, "OPENBB_USE_LANGUAGE", str(ns_parser.value))
|
||||
set_key(
|
||||
obbff.USER_ENV_FILE, "OPENBB_USE_LANGUAGE", str(ns_parser.value)
|
||||
)
|
||||
obbff.USE_LANGUAGE = ns_parser.value
|
||||
else:
|
||||
console.print(
|
||||
@@ -456,7 +459,7 @@ class SettingsController(BaseController):
|
||||
ns_parser.emoji = ""
|
||||
else:
|
||||
ns_parser.emoji = " ".join(ns_parser.emoji)
|
||||
set_key(obbff.ENV_FILE, "OPENBB_USE_FLAIR", str(ns_parser.emoji))
|
||||
set_key(obbff.USER_ENV_FILE, "OPENBB_USE_FLAIR", str(ns_parser.emoji))
|
||||
obbff.USE_FLAIR = ns_parser.emoji
|
||||
console.print("")
|
||||
|
||||
|
||||
34
terminal.py
34
terminal.py
@@ -10,7 +10,6 @@ import platform
|
||||
import sys
|
||||
import webbrowser
|
||||
from typing import List
|
||||
from pathlib import Path
|
||||
import dotenv
|
||||
|
||||
from prompt_toolkit import PromptSession
|
||||
@@ -19,7 +18,13 @@ from prompt_toolkit.styles import Style
|
||||
from prompt_toolkit.formatted_text import HTML
|
||||
|
||||
from openbb_terminal.common import feedparser_view
|
||||
from openbb_terminal.core.config.constants import REPO_DIR, ENV_FILE, USER_HOME
|
||||
from openbb_terminal.core.config.make_paths import create_paths
|
||||
from openbb_terminal.core.config.paths import (
|
||||
REPO_DIRECTORY,
|
||||
USER_ENV_FILE,
|
||||
ENV_FILE_REPOSITORY,
|
||||
HOME_DIRECTORY,
|
||||
)
|
||||
from openbb_terminal.core.log.generation.path_tracking_file_handler import (
|
||||
PathTrackingFileHandler,
|
||||
)
|
||||
@@ -50,7 +55,8 @@ from openbb_terminal.helper_funcs import parse_and_split_input
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
env_file = str(ENV_FILE)
|
||||
env_file = str(USER_ENV_FILE)
|
||||
create_paths()
|
||||
|
||||
|
||||
class TerminalController(BaseController):
|
||||
@@ -323,7 +329,7 @@ class TerminalController(BaseController):
|
||||
"""Process settings command"""
|
||||
from openbb_terminal.settings_controller import SettingsController
|
||||
|
||||
self.queue = self.load_class(SettingsController, self.queue)
|
||||
self.queue = self.load_class(SettingsController, self.queue, env_file)
|
||||
|
||||
def call_featflags(self, _):
|
||||
"""Process feature flags command"""
|
||||
@@ -553,7 +559,9 @@ class TerminalController(BaseController):
|
||||
export_path = self.queue[0].split(" ")[1]
|
||||
# If the path selected does not start from the user root, give relative location from root
|
||||
if export_path[0] == "~":
|
||||
export_path = export_path.replace("~", USER_HOME.as_posix())
|
||||
export_path = export_path.replace(
|
||||
"~", HOME_DIRECTORY.as_posix()
|
||||
)
|
||||
elif export_path[0] != "/":
|
||||
export_path = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)), export_path
|
||||
@@ -599,7 +607,7 @@ def terminal(jobs_cmds: List[str] = None, appName: str = "gst"):
|
||||
if export_path:
|
||||
# If the path selected does not start from the user root, give relative location from terminal root
|
||||
if export_path[0] == "~":
|
||||
export_path = export_path.replace("~", USER_HOME.as_posix())
|
||||
export_path = export_path.replace("~", HOME_DIRECTORY.as_posix())
|
||||
elif export_path[0] != "/":
|
||||
export_path = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)), export_path
|
||||
@@ -623,14 +631,8 @@ def terminal(jobs_cmds: List[str] = None, appName: str = "gst"):
|
||||
t_controller.print_help()
|
||||
check_for_updates()
|
||||
|
||||
env_files = [f for f in os.listdir() if f.endswith(".env")]
|
||||
if env_files:
|
||||
global env_file
|
||||
env_file = env_files[0]
|
||||
dotenv.load_dotenv(env_file)
|
||||
else:
|
||||
# create env file
|
||||
Path(".env")
|
||||
dotenv.load_dotenv(USER_ENV_FILE)
|
||||
dotenv.load_dotenv(ENV_FILE_REPOSITORY, override=True)
|
||||
|
||||
while ret_code:
|
||||
if obbff.ENABLE_QUICK_EXIT:
|
||||
@@ -905,7 +907,7 @@ def main(
|
||||
console.print("[green]OpenBB Terminal Integrated Tests:\n[/green]")
|
||||
for file in test_files:
|
||||
file = file.replace("//", "/")
|
||||
repo_path_position = file.rfind(REPO_DIR.name)
|
||||
repo_path_position = file.rfind(REPO_DIRECTORY.name)
|
||||
if repo_path_position >= 0:
|
||||
file_name = file[repo_path_position:].replace("\\", "/")
|
||||
else:
|
||||
@@ -923,7 +925,7 @@ def main(
|
||||
if fails:
|
||||
console.print("\n[red]Failures:[/red]\n")
|
||||
for key, value in fails.items():
|
||||
repo_path_position = key.rfind(REPO_DIR.name)
|
||||
repo_path_position = key.rfind(REPO_DIRECTORY.name)
|
||||
if repo_path_position >= 0:
|
||||
file_name = key[repo_path_position:].replace("\\", "/")
|
||||
else:
|
||||
|
||||
@@ -2,7 +2,7 @@ import os
|
||||
import pytest
|
||||
from openbb_terminal.core.log.generation import formatter_with_exceptions
|
||||
from openbb_terminal.core.log.generation.settings import AppSettings
|
||||
from openbb_terminal.core.config.constants import REPO_DIR
|
||||
from openbb_terminal.core.config.paths import REPO_DIRECTORY
|
||||
|
||||
app_settings = AppSettings(
|
||||
commit_hash="MOCK_COMMIT_HASH",
|
||||
@@ -33,7 +33,7 @@ def test_extract_log_extra(mocker):
|
||||
|
||||
|
||||
def test_filter_piis():
|
||||
text = f"test 1.1.1.1 chavi@chavi.com {REPO_DIR.name}{os.sep} dd{os.sep}dd"
|
||||
text = f"test 1.1.1.1 chavi@chavi.com {REPO_DIRECTORY.name}{os.sep} dd{os.sep}dd"
|
||||
value = formatter.filter_piis(text)
|
||||
assert value
|
||||
|
||||
|
||||
Reference in New Issue
Block a user