diff --git a/openbb_terminal/core/config/paths.py b/openbb_terminal/core/config/paths.py index 372e9bfdb0e9..c24788ae16ef 100644 --- a/openbb_terminal/core/config/paths.py +++ b/openbb_terminal/core/config/paths.py @@ -28,3 +28,4 @@ def get_user_data_directory(): CUSTOM_IMPORTS_DIRECTORY = USER_DATA_DIRECTORY / "custom_imports" PORTFOLIO_DATA_DIRECTORY = USER_DATA_DIRECTORY / "portfolio" +ROUTINES_DIRECTORY = USER_DATA_DIRECTORY / "routines" diff --git a/openbb_terminal/core/config/paths_helper.py b/openbb_terminal/core/config/paths_helper.py index 2394433988fc..1621d722de19 100644 --- a/openbb_terminal/core/config/paths_helper.py +++ b/openbb_terminal/core/config/paths_helper.py @@ -10,6 +10,7 @@ CUSTOM_IMPORTS_DIRECTORY, USER_EXPORTS_DIRECTORY, PORTFOLIO_DATA_DIRECTORY, + ROUTINES_DIRECTORY, ) @@ -48,6 +49,7 @@ def create_files(list_files: List): PORTFOLIO_DATA_DIRECTORY / "holdings", PORTFOLIO_DATA_DIRECTORY / "allocation", PORTFOLIO_DATA_DIRECTORY / "optimization", + ROUTINES_DIRECTORY, ] dirs_files = [USER_ENV_FILE, REPOSITORY_ENV_FILE] create_paths(dirs_list) diff --git a/terminal.py b/terminal.py index cd20224e7ed5..d831a4336cc9 100644 --- a/terminal.py +++ b/terminal.py @@ -26,6 +26,7 @@ USER_ENV_FILE, REPOSITORY_ENV_FILE, USER_EXPORTS_DIRECTORY, + ROUTINES_DIRECTORY, ) from openbb_terminal.core.log.generation.path_tracking_file_handler import ( PathTrackingFileHandler, @@ -89,13 +90,16 @@ class TerminalController(BaseController): ] PATH = "/" - ROUTINE_CHOICES = { - file: None - for file in os.listdir( - os.path.join(os.path.abspath(os.path.dirname(__file__)), "routines") - ) - if file.endswith(".openbb") + + ROUTINE_FILES = { + filepath.name: filepath + for filepath in (REPOSITORY_DIRECTORY / "routines").rglob("*.openbb") } + ROUTINE_FILES.update( + {filepath.name: filepath for filepath in ROUTINES_DIRECTORY.rglob("*.openbb")} + ) + + ROUTINE_CHOICES = {filename: None for filename in ROUTINE_FILES} GUESS_TOTAL_TRIES = 0 GUESS_NUMBER_TRIES_LEFT = 0 @@ -485,11 +489,7 @@ def call_exe(self, other_args: List[str]): if ns_parser_exe: if ns_parser_exe.path: if ns_parser_exe.path in self.ROUTINE_CHOICES: - path = os.path.join( - os.path.abspath(os.path.dirname(__file__)), - "routines", - ns_parser_exe.path, - ) + path = self.ROUTINE_FILES[ns_parser_exe.path] else: path = ns_parser_exe.path