diff --git a/openbb_terminal/config_terminal.py b/openbb_terminal/config_terminal.py index d412d2e0663b..93f1b147e55c 100644 --- a/openbb_terminal/config_terminal.py +++ b/openbb_terminal/config_terminal.py @@ -7,7 +7,7 @@ # IMPORTATION INTERNAL from openbb_terminal.core.config import ( # pylint: disable=unused-import # noqa - make_paths, + paths_helper, ) from openbb_terminal.core.config.paths import USER_ENV_FILE, REPOSITORY_ENV_FILE from .helper_classes import TerminalStyle as _TerminalStyle diff --git a/openbb_terminal/core/config/paths.py b/openbb_terminal/core/config/paths.py index 751ccf0e9ca6..6fdfed29bc8e 100644 --- a/openbb_terminal/core/config/paths.py +++ b/openbb_terminal/core/config/paths.py @@ -9,3 +9,5 @@ USER_ENV_FILE = SETTINGS_DIRECTORY / ".env" USER_DATA_DIRECTORY = HOME_DIRECTORY / "OpenBBUserData" + +CUSTOM_IMPORTS_DIRECTORY = USER_DATA_DIRECTORY / "custom_imports" diff --git a/openbb_terminal/core/config/make_paths.py b/openbb_terminal/core/config/paths_helper.py similarity index 66% rename from openbb_terminal/core/config/make_paths.py rename to openbb_terminal/core/config/paths_helper.py index bcff3972752a..93656f237644 100644 --- a/openbb_terminal/core/config/make_paths.py +++ b/openbb_terminal/core/config/paths_helper.py @@ -1,11 +1,15 @@ # IMPORTATION STANDARD import os from typing import List +import shutil + from openbb_terminal.core.config.paths import ( SETTINGS_DIRECTORY, USER_DATA_DIRECTORY, USER_ENV_FILE, REPOSITORY_ENV_FILE, + CUSTOM_IMPORTS_DIRECTORY, + REPOSITORY_DIRECTORY, ) @@ -29,11 +33,23 @@ def create_files(list_files: List): pass +def copy_files(from_dir, to_dir): + """ + Copy default/example files from the repo + to the user data folder""" + + if from_dir.exists(): + shutil.copytree(from_dir, to_dir, dirs_exist_ok=True) + + dirs_list = [ SETTINGS_DIRECTORY, USER_DATA_DIRECTORY, USER_DATA_DIRECTORY / "styles", + CUSTOM_IMPORTS_DIRECTORY, + CUSTOM_IMPORTS_DIRECTORY / "econometrics", ] dirs_files = [USER_ENV_FILE, REPOSITORY_ENV_FILE] create_paths(dirs_list) create_files(dirs_files) +copy_files(REPOSITORY_DIRECTORY / "custom_imports", CUSTOM_IMPORTS_DIRECTORY) diff --git a/openbb_terminal/dashboards/futures.ipynb b/openbb_terminal/dashboards/futures.ipynb index 847a97a2cb58..fcf8c6aaee78 100644 --- a/openbb_terminal/dashboards/futures.ipynb +++ b/openbb_terminal/dashboards/futures.ipynb @@ -15,7 +15,10 @@ "import plotly.graph_objs as go\n", "import yfinance as yf\n", "import pandas as pd\n", - "from IPython.display import display" + "from IPython.display import display\n", + "from pathlib import Path\n", + "\n", + "from openbb_terminal.core.config.paths import CUSTOM_IMPORTS_DIRECTORY" ] }, { @@ -25,9 +28,7 @@ "metadata": {}, "outputs": [], "source": [ - "full_path = os.path.abspath(\n", - " os.path.join(os.getcwd(), \"..\", \"..\", \"custom_imports\", \"dashboards\", \"futures.csv\")\n", - ")\n", + "full_path = CUSTOM_IMPORTS_DIRECTORY / \"dashboards\" / \"futures.csv\"\n", "df = pd.read_csv(full_path)\n", "months = [\"F\", \"G\", \"H\", \"J\", \"K\", \"M\", \"N\", \"Q\", \"U\", \"V\", \"X\", \"Z\"]" ] @@ -282,7 +283,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3.9.13 ('obb')", "language": "python", "name": "python3" }, @@ -296,12 +297,17 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.4" + "version": "3.9.13" }, "metadata": { "interpreter": { "hash": "e896a00ead8b521528d79ac9ef24990696f2b751eb283ab8e0d078c9c4971ffc" } + }, + "vscode": { + "interpreter": { + "hash": "ab0e87f2bc73919b75956d1b3e303320699d53da895be1bb46287d7dc67c6497" + } } }, "nbformat": 4, diff --git a/openbb_terminal/econometrics/econometrics_controller.py b/openbb_terminal/econometrics/econometrics_controller.py index 05f6c908302c..c753e2540cb0 100644 --- a/openbb_terminal/econometrics/econometrics_controller.py +++ b/openbb_terminal/econometrics/econometrics_controller.py @@ -16,6 +16,7 @@ import openbb_terminal.econometrics.regression_model import openbb_terminal.econometrics.regression_view +from openbb_terminal.core.config.paths import CUSTOM_IMPORTS_DIRECTORY from openbb_terminal import feature_flags as obbff from openbb_terminal.decorators import log_start_end from openbb_terminal.helper_funcs import ( @@ -160,7 +161,7 @@ def __init__(self, queue: List[str] = None): for file_type in self.file_types for filepath in chain( Path(obbff.EXPORT_FOLDER_PATH).rglob(f"*.{file_type}"), - Path("custom_imports").rglob(f"*.{file_type}"), + Path(CUSTOM_IMPORTS_DIRECTORY / "econometrics").rglob(f"*.{file_type}"), ) if filepath.is_file() } @@ -246,7 +247,7 @@ def print_help(self): mt = MenuText("econometrics/") mt.add_param( "_data_loc", - f"\n\t{obbff.EXPORT_FOLDER_PATH}\n\t{Path('custom_imports').resolve()}", + f"\n\t{obbff.EXPORT_FOLDER_PATH}\n\t{str(CUSTOM_IMPORTS_DIRECTORY/'econometrics')}", ) mt.add_raw("\n") mt.add_cmd("load") diff --git a/openbb_terminal/parent_classes.py b/openbb_terminal/parent_classes.py index 8160c257283c..26c641499956 100644 --- a/openbb_terminal/parent_classes.py +++ b/openbb_terminal/parent_classes.py @@ -22,6 +22,7 @@ import pandas as pd import numpy as np +from openbb_terminal.core.config.paths import CUSTOM_IMPORTS_DIRECTORY from openbb_terminal.decorators import log_start_end from openbb_terminal.menu import session @@ -857,10 +858,10 @@ def call_load(self, other_args: List[str]): # This seems to block the .exe since the folder needs to be manually created # This block makes sure that we only look for the file if the -f flag is used # Adding files in the argparse choices, will fail for the .exe even without -f + STOCKS_CUSTOM_IMPORTS = CUSTOM_IMPORTS_DIRECTORY / "stocks" try: - if ns_parser.filepath not in os.listdir( - os.path.join("custom_imports", "stocks") - ): + file_list = [x.name for x in STOCKS_CUSTOM_IMPORTS.iterdir()] + if ns_parser.filepath not in file_list: console.print( f"[red]{ns_parser.filepath} not found in custom_imports/stocks/ " "folder[/red].\n" @@ -871,9 +872,7 @@ def call_load(self, other_args: List[str]): return df_stock_candidate = stocks_helper.load_custom( - os.path.join( - os.path.join("custom_imports", "stocks"), ns_parser.filepath - ) + str(STOCKS_CUSTOM_IMPORTS / ns_parser.filepath) ) if df_stock_candidate.empty: return diff --git a/styles/user/.gitkeep b/styles/user/.gitkeep deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/terminal.py b/terminal.py index 8b1f8baa647b..19e0001f629f 100644 --- a/terminal.py +++ b/terminal.py @@ -18,7 +18,7 @@ from prompt_toolkit.formatted_text import HTML from openbb_terminal.core.config import ( # pylint: disable=unused-import # noqa - make_paths, + paths_helper, ) from openbb_terminal.common import feedparser_view from openbb_terminal.core.config.paths import ( diff --git a/tests/openbb_terminal/stocks/test_stocks_helper.py b/tests/openbb_terminal/stocks/test_stocks_helper.py index 8e1d0f092310..78c3f7c19165 100644 --- a/tests/openbb_terminal/stocks/test_stocks_helper.py +++ b/tests/openbb_terminal/stocks/test_stocks_helper.py @@ -8,6 +8,7 @@ # IMPORTATION INTERNAL from openbb_terminal.stocks import stocks_helper +from openbb_terminal.core.config.paths import CUSTOM_IMPORTS_DIRECTORY from openbb_terminal import helper_funcs @@ -107,7 +108,7 @@ def test_load_week_or_month(recorder, weekly, monthly): @pytest.mark.record_stdout @pytest.mark.parametrize( "path", - ["none", os.path.join(os.path.join("custom_imports", "stocks"), "test.csv")], + ["none", CUSTOM_IMPORTS_DIRECTORY / "stocks" / "test.csv"], ) def test_load_custom_output(path): stocks_helper.load_custom(path) @@ -126,7 +127,7 @@ def test_load_custom_output_wrong_path(path): @pytest.mark.vcr @pytest.mark.parametrize( "path", - [os.path.join(os.path.join("custom_imports", "stocks"), "test.csv")], + [CUSTOM_IMPORTS_DIRECTORY / "stocks" / "test.csv"], ) def test_load_custom_output_df(path): df = stocks_helper.load_custom(path) diff --git a/tests/openbb_terminal/stocks/txt/test_stocks_helper/test_load_custom_output[path1].txt b/tests/openbb_terminal/stocks/txt/test_stocks_helper/test_load_custom_output[path1].txt new file mode 100644 index 000000000000..405bd9367331 --- /dev/null +++ b/tests/openbb_terminal/stocks/txt/test_stocks_helper/test_load_custom_output[path1].txt @@ -0,0 +1,3 @@ +Loaded data has columns: Date, Close/Last, Volume, Open, High, Low + +Column [blue]Date[/blue] set as index.