mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 04:31:13 +00:00
New path for logs (#2502)
* add log path * add test to check if log file is in correct dir * small change * Adding paths * change to paths.py * black Co-authored-by: Chavithra Parana <chavithra@gmail.com>
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
# IMPORTATION STANDARD
|
||||
import os
|
||||
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")
|
||||
|
||||
11
openbb_terminal/core/config/paths.py
Normal file
11
openbb_terminal/core/config/paths.py
Normal file
@@ -0,0 +1,11 @@
|
||||
# IMPORTATION STANDARD
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
HOME_DIRECTORY = Path.home()
|
||||
REPOSITORY_DIRECTORY = Path(__file__).parent.parent.parent.parent
|
||||
USER_DATA_DIRECTORY = HOME_DIRECTORY / "OpenBBUserData"
|
||||
SETTINGS_DIRECTORY = HOME_DIRECTORY / ".openbb_terminal"
|
||||
|
||||
REPOSITORY_ENV_FILE = REPOSITORY_DIRECTORY / ".env"
|
||||
USER_ENV_FILE = SETTINGS_DIRECTORY / ".env"
|
||||
@@ -2,6 +2,7 @@
|
||||
import os
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
from openbb_terminal.core.config.paths import USER_DATA_DIRECTORY
|
||||
|
||||
# IMPORTATION THIRDPARTY
|
||||
|
||||
@@ -12,8 +13,7 @@ from pathlib import Path
|
||||
def get_log_dir() -> Path:
|
||||
"""Retrieve application's log directory."""
|
||||
|
||||
file_path = Path(__file__)
|
||||
log_dir = file_path.parent.parent.parent.parent.absolute().joinpath("logs")
|
||||
log_dir = USER_DATA_DIRECTORY.joinpath("logs")
|
||||
|
||||
if not os.path.isdir(log_dir.absolute()):
|
||||
os.mkdir(log_dir.absolute())
|
||||
|
||||
@@ -58,7 +58,7 @@ def get_app_id() -> str:
|
||||
if e.errno == 30:
|
||||
print("Please move the application into a writable location.")
|
||||
print(
|
||||
"Note for macOS users: copy `Gamestonk Terminal` folder outside the DMG."
|
||||
"Note for macOS users: copy `OpenBB Terminal` folder outside the DMG."
|
||||
)
|
||||
else:
|
||||
raise e
|
||||
|
||||
@@ -1,24 +1,32 @@
|
||||
from openbb_terminal.core.log.generation.directories import get_log_dir, get_log_sub_dir
|
||||
from pathlib import Path
|
||||
import logging
|
||||
|
||||
from openbb_terminal.core.log.generation.directories import get_log_dir, get_log_sub_dir
|
||||
from openbb_terminal.loggers import setup_logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
setup_logging()
|
||||
|
||||
|
||||
def test_get_log_dir(mocker, tmp_path):
|
||||
def test_get_log_dir(mocker):
|
||||
mock_file_path = mocker.Mock()
|
||||
mock_file_path.parent.parent.parent.parent = tmp_path
|
||||
mocker.patch(
|
||||
"openbb_terminal.core.log.generation.directories.Path",
|
||||
return_value=mock_file_path,
|
||||
)
|
||||
|
||||
log_dir = get_log_dir()
|
||||
logger.info("Testing log")
|
||||
|
||||
assert isinstance(log_dir, Path)
|
||||
assert log_dir.parent.parent == tmp_path
|
||||
|
||||
log_file = Path(logging.getLoggerClass().root.handlers[0].baseFilename)
|
||||
|
||||
assert log_file.parent == log_dir
|
||||
|
||||
log_dir_bis = get_log_dir()
|
||||
|
||||
assert isinstance(log_dir, Path)
|
||||
assert log_dir.parent.parent == tmp_path
|
||||
assert log_dir_bis == log_dir
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user