Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add path for custom_imports outside the terminal #2567

Merged
merged 32 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ec2953d
add log path
soggyomelette Sep 5, 2022
500bde9
add test to check if log file is in correct dir
soggyomelette Sep 6, 2022
e519e08
env path
soggyomelette Sep 6, 2022
0fd611b
black
soggyomelette Sep 6, 2022
1b3ee94
Merge branch 'main' into new_path_env
soggyomelette Sep 6, 2022
a33b0ff
mypy fix
soggyomelette Sep 6, 2022
dcab155
add styles folder and styles from repo
soggyomelette Sep 6, 2022
10b28ad
add timezone as env variable
soggyomelette Sep 6, 2022
9e9cea0
Merge branch 'main' of https://github.com/OpenBB-finance/OpenBBTermin…
soggyomelette Sep 12, 2022
c25017f
fix changes with main
soggyomelette Sep 12, 2022
9e7daf9
fix test
soggyomelette Sep 14, 2022
ef809fb
flake8
soggyomelette Sep 14, 2022
a034012
fix linting
soggyomelette Sep 14, 2022
b56bc80
fix linting
soggyomelette Sep 14, 2022
1d2859c
changes
soggyomelette Sep 14, 2022
6036fe1
Merge branch 'main' of https://github.com/OpenBB-finance/OpenBBTermin…
soggyomelette Sep 19, 2022
be72188
custom changes
soggyomelette Sep 19, 2022
fdaea95
add custom_imports outside terminal
soggyomelette Sep 20, 2022
2de70cc
black
soggyomelette Sep 20, 2022
7eb7525
black terminal
soggyomelette Sep 20, 2022
403ede7
Merge branch 'main' of https://github.com/OpenBB-finance/OpenBBTermin…
soggyomelette Sep 20, 2022
9ce85fb
fix test
soggyomelette Sep 20, 2022
e7e9d3b
fix merge and remove styles/user
soggyomelette Sep 20, 2022
9aa3dab
Merge branch 'main' of https://github.com/OpenBB-finance/OpenBBTermin…
soggyomelette Sep 20, 2022
af35987
Merge branch 'main' into new_path_custom_imports
minhhoang1023 Sep 20, 2022
54cc8ea
Merge branch 'main' into new_path_custom_imports
soggyomelette Sep 21, 2022
4f624f8
some stylistic changes and remove move_files
soggyomelette Sep 22, 2022
775ba4d
Merge branch 'main' into new_path_custom_imports
soggyomelette Sep 22, 2022
749ea1c
flake8
soggyomelette Sep 22, 2022
b250e90
merge main
soggyomelette Sep 22, 2022
e52a475
Merge branch 'new_path_custom_imports' of https://github.com/OpenBB-f…
soggyomelette Sep 22, 2022
62a6abd
merge move and make into paths_helper
soggyomelette Sep 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.