mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
move get_branch request to logging_settings
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from pathlib import Path
|
||||
from typing import List, Optional
|
||||
from openbb_core.app.logs.utils.system_utils import get_branch
|
||||
|
||||
from openbb_core.app.logs.utils.utils import get_app_id, get_log_dir, get_session_id
|
||||
from openbb_core.app.model.system_settings import SystemSettings
|
||||
@@ -33,7 +34,7 @@ class LoggingSettings:
|
||||
|
||||
# System
|
||||
self.commit_hash: Optional[str] = system_settings.logging_commit_hash
|
||||
self.branch: Optional[str] = system_settings.logging_branch
|
||||
self.branch: Optional[str] = get_branch(self.commit_hash) if self.commit_hash else None
|
||||
self.app_name: str = system_settings.logging_app_name
|
||||
self.app_id: str = get_app_id(user_data_directory)
|
||||
self.session_id: str = get_session_id()
|
||||
|
||||
@@ -19,7 +19,7 @@ GITHUB_PROJECT_URL = (
|
||||
|
||||
UNKNOWN_COMMIT_PLACEHOLDER = "unknown-commit"
|
||||
UNKNOWN_BRANCH_PLACEHOLDER = "unknown-branch"
|
||||
REPOSITORY_DIRECTORY = Path(__file__).parent.parent.parent.parent.parent
|
||||
REPOSITORY_DIRECTORY = Path(__file__).parent.parent.parent.parent.parent.parent.parent.parent
|
||||
|
||||
|
||||
def get_commit_hash() -> str:
|
||||
@@ -41,6 +41,9 @@ def get_commit_hash() -> str:
|
||||
def get_branch(commit_hash: str, request_timeout: int = 5) -> str:
|
||||
"""Get Branch Name"""
|
||||
|
||||
if commit_hash == UNKNOWN_COMMIT_PLACEHOLDER:
|
||||
return UNKNOWN_BRANCH_PLACEHOLDER
|
||||
|
||||
def get_branch_commit_hash(branch: str) -> str:
|
||||
response = requests.get(
|
||||
f"{GITHUB_PROJECT_URL}/{branch}", timeout=request_timeout
|
||||
|
||||
@@ -36,7 +36,6 @@ class SystemSettings(Tagged):
|
||||
# Logging section
|
||||
logging_app_name: str = FrozenField(default="gst")
|
||||
logging_commit_hash: Optional[str] = FrozenField(default=None)
|
||||
logging_branch: Optional[str] = FrozenField(default=None)
|
||||
logging_frequency: Literal["D", "H", "M", "S"] = FrozenField(default="H")
|
||||
logging_handlers: List[str] = FrozenField(default_factory=lambda: ["file"])
|
||||
logging_rolling_clock: bool = FrozenField(default=False)
|
||||
@@ -73,14 +72,6 @@ class SystemSettings(Tagged):
|
||||
with open(path, mode="w") as file:
|
||||
json.dump({}, file)
|
||||
|
||||
# TODO: Allow setting debug mode from environment variable
|
||||
# @root_validator(allow_reuse=True)
|
||||
# @classmethod
|
||||
# def validate_debug_mode(cls, values):
|
||||
# dm = os.getenv("DEBUG_MODE", "").lower() in ["true", "1"]
|
||||
# values["debug_mode"] = bool(values["debug_mode"] or dm)
|
||||
# return values
|
||||
|
||||
@root_validator(allow_reuse=True)
|
||||
@classmethod
|
||||
def create_openbb_directory(cls, values):
|
||||
@@ -122,14 +113,3 @@ class SystemSettings(Tagged):
|
||||
@classmethod
|
||||
def validate_commit_hash(cls, v):
|
||||
return v or get_commit_hash()
|
||||
|
||||
@root_validator(allow_reuse=True)
|
||||
@classmethod
|
||||
def validate_branch(cls, values):
|
||||
branch = values["logging_branch"]
|
||||
commit_hash = values["logging_commit_hash"]
|
||||
|
||||
if not branch and commit_hash:
|
||||
values["logging_branch"] = get_branch(commit_hash)
|
||||
|
||||
return values
|
||||
|
||||
Reference in New Issue
Block a user