Skip to content

Commit

Permalink
Add path for custom_imports outside the terminal (#2567)
Browse files Browse the repository at this point in the history
* add log path

* add test to check if log file is in correct dir

* env path

* black

* mypy fix

* add styles folder and styles from repo

* add timezone as env variable

* fix changes with main

* fix test

* flake8

* fix linting

* fix linting

* changes

* custom changes

* add custom_imports outside terminal

* black

* black terminal

* fix test

* fix merge and remove styles/user

* some stylistic changes and remove move_files

* flake8

* merge main

* merge move and make into paths_helper

Co-authored-by: minhhoang1023 <40023817+minhhoang1023@users.noreply.github.com>
  • Loading branch information
soggyomelette and minhhoang1023 authored Sep 22, 2022
1 parent 16b2a7a commit c4658b6
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 18 deletions.
2 changes: 1 addition & 1 deletion openbb_terminal/config_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions openbb_terminal/core/config/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
USER_ENV_FILE = SETTINGS_DIRECTORY / ".env"

USER_DATA_DIRECTORY = HOME_DIRECTORY / "OpenBBUserData"

CUSTOM_IMPORTS_DIRECTORY = USER_DATA_DIRECTORY / "custom_imports"
Original file line number Diff line number Diff line change
@@ -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,
)


Expand All @@ -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)
18 changes: 12 additions & 6 deletions openbb_terminal/dashboards/futures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand All @@ -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\"]"
]
Expand Down Expand Up @@ -282,7 +283,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3.9.13 ('obb')",
"language": "python",
"name": "python3"
},
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions openbb_terminal/econometrics/econometrics_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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")
Expand Down
11 changes: 5 additions & 6 deletions openbb_terminal/parent_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down
Empty file removed styles/user/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
5 changes: 3 additions & 2 deletions tests/openbb_terminal/stocks/test_stocks_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Loaded data has columns: Date, Close/Last, Volume, Open, High, Low

Column [blue]Date[/blue] set as index.

0 comments on commit c4658b6

Please sign in to comment.