mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-29 21:42:22 +00:00
Merge branch 'develop' into feature/docs-intros-updates
This commit is contained in:
9
.github/workflows/nightly-build.yml
vendored
9
.github/workflows/nightly-build.yml
vendored
@@ -55,3 +55,12 @@ jobs:
|
||||
with:
|
||||
workflow: docker.yml
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
trigger-pypi-build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Trigger PyPI Build
|
||||
uses: aurelien-baudet/workflow-dispatch@v2
|
||||
with:
|
||||
workflow: nightly-pypi.yml
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
48
.github/workflows/nightly-pypi.yml
vendored
Normal file
48
.github/workflows/nightly-pypi.yml
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
name: Deploy to PyPI - Nightly
|
||||
|
||||
on: workflow_dispatch
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
deploy-nightly-pypi:
|
||||
name: Build and publish nightly distributions 📦 to PyPI
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Setup Python 3.9
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: "3.9"
|
||||
|
||||
- name: Update version in pyproject.toml and Edit docs
|
||||
run: |
|
||||
sed -i 's/name = ".*"/name = "openbb-nightly"/' pyproject.toml
|
||||
sed -i "3s/version = \"\(.*\)\"/version = \"\1.dev$(date +%Y%m%d)\"/" pyproject.toml
|
||||
head pyproject.toml
|
||||
sed -i 's/pip install openbb/pip install openbb-nightly/g; s/from openbb_terminal.sdk import openbb/from openbb_terminal.sdk import openbb-nightly/g' ./website/content/sdk/quickstart/pypi.md
|
||||
|
||||
|
||||
- name: Install pypa/build
|
||||
run: >-
|
||||
python -m
|
||||
pip install
|
||||
build
|
||||
--user
|
||||
|
||||
- name: Build a binary wheel and a source tarball
|
||||
run: >-
|
||||
python -m
|
||||
build
|
||||
--sdist
|
||||
--wheel
|
||||
--outdir dist/
|
||||
.
|
||||
|
||||
- name: Publish distribution 📦 to PyPI
|
||||
uses: pypa/gh-action-pypi-publish@release/v1
|
||||
with:
|
||||
password: ${{ secrets.NIGHTLY_PYPI_API_TOKEN }}
|
||||
4
.github/workflows/pypi.yml
vendored
4
.github/workflows/pypi.yml
vendored
@@ -14,7 +14,7 @@ concurrency:
|
||||
|
||||
jobs:
|
||||
deploy-test-pypi:
|
||||
name: Build and publish distributions 📦 to PyPI and TestPyPI
|
||||
name: Build and publish 📦 to TestPyPI
|
||||
if: startsWith(github.ref, 'refs/heads/release/')
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -47,7 +47,7 @@ jobs:
|
||||
repository_url: https://test.pypi.org/legacy/
|
||||
|
||||
deploy-pypi:
|
||||
name: Build and publish distributions 📦 to PyPI and TestPyPI
|
||||
name: Build and publish 📦 to PyPI
|
||||
if: startsWith(github.ref, 'refs/heads/main')
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ from typing import Any, Callable, Dict, List, Optional
|
||||
import openbb_terminal.config_terminal as cfg
|
||||
from openbb_terminal.core.library.metadata import Metadata
|
||||
from openbb_terminal.core.library.trail_map import TrailMap
|
||||
from openbb_terminal.session.sdk_session import login
|
||||
|
||||
# pylint: disable=import-outside-toplevel
|
||||
|
||||
@@ -249,9 +248,6 @@ class OperationLogger:
|
||||
method_result=method_result,
|
||||
method_chosen=self.__method_chosen,
|
||||
)
|
||||
self.__log_if_login(
|
||||
method_chosen=self.__method_chosen,
|
||||
)
|
||||
self.__log_end(
|
||||
logger=logger,
|
||||
method_chosen=self.__method_chosen,
|
||||
@@ -275,17 +271,6 @@ class OperationLogger:
|
||||
extra={"func_name_override": method_chosen.__name__},
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def __log_if_login(
|
||||
method_chosen: Callable,
|
||||
):
|
||||
if method_chosen.__name__ == login.__name__:
|
||||
from openbb_terminal.core.log.generation.user_logger import ( # pylint: disable=import-outside-toplevel
|
||||
log_user,
|
||||
)
|
||||
|
||||
log_user(with_rollover=False)
|
||||
|
||||
@staticmethod
|
||||
def __log_end(logger: Logger, method_chosen: Callable):
|
||||
logger.info(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# IMPORTATION STANDARD
|
||||
import logging
|
||||
|
||||
from openbb_terminal.core.log.generation import settings_logger, user_logger
|
||||
from openbb_terminal.core.log.generation import settings_logger
|
||||
from openbb_terminal.core.log.generation.common import do_rollover
|
||||
|
||||
# IMPORTATION THIRDPARTY
|
||||
@@ -19,5 +19,4 @@ def log_terminal(test_mode: bool):
|
||||
|
||||
logger.info("START")
|
||||
settings_logger.log_all_settings(with_rollover=False)
|
||||
user_logger.log_user(with_rollover=False)
|
||||
do_rollover()
|
||||
|
||||
@@ -6,6 +6,7 @@ import re
|
||||
# IMPORTATION INTERNAL
|
||||
from openbb_terminal.core.config.paths import HOME_DIRECTORY
|
||||
from openbb_terminal.core.log.generation.settings import AppSettings
|
||||
from openbb_terminal.core.log.generation.user_logger import get_user_uuid
|
||||
|
||||
|
||||
class FormatterWithExceptions(logging.Formatter):
|
||||
@@ -36,8 +37,6 @@ class FormatterWithExceptions(logging.Formatter):
|
||||
record.funcName = record.func_name_override # type: ignore
|
||||
record.lineno = 0
|
||||
|
||||
log_extra["userId"] = getattr(record, "user_id", "NA")
|
||||
|
||||
if hasattr(record, "session_id"):
|
||||
log_extra["sessionId"] = record.session_id # type: ignore
|
||||
|
||||
@@ -149,7 +148,9 @@ class FormatterWithExceptions(logging.Formatter):
|
||||
"appId": app_settings.identifier,
|
||||
"sessionId": app_settings.session_id,
|
||||
"commitHash": app_settings.commit_hash,
|
||||
"userId": get_user_uuid(),
|
||||
}
|
||||
|
||||
log_extra = self.extract_log_extra(record=record)
|
||||
log_prefix_content = {**log_prefix_content, **log_extra}
|
||||
log_prefix = self.LOGPREFIXFORMAT % log_prefix_content
|
||||
|
||||
@@ -42,12 +42,21 @@ class AppSettings:
|
||||
def session_id(self) -> str:
|
||||
return self.__session_id
|
||||
|
||||
@property
|
||||
def user_id(self) -> str:
|
||||
return self.__user_id
|
||||
|
||||
@user_id.setter
|
||||
def user_id(self, value: str):
|
||||
self.__user_id = value
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
commit_hash: str,
|
||||
session_id: str,
|
||||
identifier: str,
|
||||
user_id: str,
|
||||
):
|
||||
"""
|
||||
Args:
|
||||
@@ -55,12 +64,14 @@ class AppSettings:
|
||||
commit_hash (str): Commit hash of the current running code.
|
||||
identifier (str): Unique key identifying a particular installation.
|
||||
session_id (str): Key identifying a particular running session.
|
||||
user_id (str): Hash identifying a particular user.
|
||||
"""
|
||||
|
||||
self.__name = name
|
||||
self.__commit_hash = commit_hash
|
||||
self.__identifier = identifier
|
||||
self.__session_id = session_id
|
||||
self.__user_id = user_id
|
||||
|
||||
|
||||
class LogSettings:
|
||||
|
||||
@@ -1,26 +1,19 @@
|
||||
# IMPORTATION STANDARD
|
||||
import json
|
||||
import logging
|
||||
|
||||
from openbb_terminal.core.log.generation.common import do_rollover
|
||||
|
||||
# IMPORTATION THIRDPARTY
|
||||
# IMPORTATION INTERNAL
|
||||
from openbb_terminal.session.user import User
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
NO_USER_PLACEHOLDER = "NA"
|
||||
|
||||
|
||||
def get_user_uuid() -> str:
|
||||
"""Get user UUID"""
|
||||
|
||||
def log_user(with_rollover: bool = True):
|
||||
"""Log user"""
|
||||
if not User.is_guest():
|
||||
_log_user_info()
|
||||
return User.get_uuid()
|
||||
|
||||
if with_rollover:
|
||||
do_rollover()
|
||||
|
||||
|
||||
def _log_user_info():
|
||||
"""Log user info"""
|
||||
user_info = {"user_uuid": User.get_uuid()}
|
||||
logger.info("USER: %s ", json.dumps(user_info))
|
||||
return NO_USER_PLACEHOLDER
|
||||
|
||||
@@ -1630,6 +1630,7 @@ class EconomyController(BaseController):
|
||||
type=str,
|
||||
nargs="+",
|
||||
dest="query",
|
||||
required="-h" not in other_args,
|
||||
help="Query to evaluate on loaded datasets",
|
||||
)
|
||||
if other_args and "-" not in other_args[0][0]:
|
||||
|
||||
@@ -40,6 +40,7 @@ from openbb_terminal.core.log.generation.settings import (
|
||||
LogSettings,
|
||||
Settings,
|
||||
)
|
||||
from openbb_terminal.core.log.generation.user_logger import get_user_uuid
|
||||
|
||||
logging.getLogger("requests").setLevel(LOGGING_VERBOSITY)
|
||||
logging.getLogger("urllib3").setLevel(LOGGING_VERBOSITY)
|
||||
@@ -166,6 +167,7 @@ def setup_logging(
|
||||
name = app_name or LOGGING_APP_NAME
|
||||
identifier = get_app_id()
|
||||
session_id = session_id or str(START_TIMESTAMP)
|
||||
user_id = get_user_uuid()
|
||||
|
||||
# AWSSettings
|
||||
aws_access_key_id = LOGGING_AWS_ACCESS_KEY_ID
|
||||
@@ -184,6 +186,7 @@ def setup_logging(
|
||||
name=name,
|
||||
identifier=identifier,
|
||||
session_id=session_id,
|
||||
user_id=user_id,
|
||||
),
|
||||
aws_settings=AWSSettings(
|
||||
aws_access_key_id=aws_access_key_id,
|
||||
|
||||
@@ -22,6 +22,7 @@ from openbb_terminal.sdk_core import (
|
||||
)
|
||||
from openbb_terminal import feature_flags as obbff
|
||||
from openbb_terminal.session.user import User
|
||||
from openbb_terminal.terminal_helper import is_auth_enabled
|
||||
|
||||
if User.is_guest():
|
||||
load_dotenv_and_reload_configs()
|
||||
@@ -48,6 +49,14 @@ class OpenBBSDK:
|
||||
self.logout = lib.sdk_session.logout
|
||||
self.news = lib.common_feedparser_model.get_news
|
||||
self.whoami = lib.sdk_session.whoami
|
||||
self._try_to_login()
|
||||
|
||||
def _try_to_login(self):
|
||||
if User.is_guest() and is_auth_enabled():
|
||||
try:
|
||||
self.login()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@property
|
||||
def alt(self):
|
||||
|
||||
@@ -16,7 +16,6 @@ from openbb_terminal.sdk_core.sdk_init import (
|
||||
OPTIMIZATION_TOOLKIT_ENABLED,
|
||||
OPTIMIZATION_TOOLKIT_WARNING,
|
||||
)
|
||||
from openbb_terminal.session.sdk_session import login
|
||||
|
||||
if not FORECASTING_TOOLKIT_ENABLED and not load_env_vars(
|
||||
"OPENBB_DISABLE_FORECASTING_WARNING", strtobool, False
|
||||
@@ -279,9 +278,6 @@ class OperationLogger:
|
||||
method_result=method_result,
|
||||
method_chosen=self.__method_chosen,
|
||||
)
|
||||
self.__log_if_login(
|
||||
method_chosen=self.__method_chosen,
|
||||
)
|
||||
self.__log_end(
|
||||
logger=logger,
|
||||
method_chosen=self.__method_chosen,
|
||||
@@ -305,17 +301,6 @@ class OperationLogger:
|
||||
extra={"func_name_override": method_chosen.__name__},
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def __log_if_login(
|
||||
method_chosen: Callable,
|
||||
):
|
||||
if method_chosen.__name__ == login.__name__:
|
||||
from openbb_terminal.core.log.generation.user_logger import ( # pylint: disable=import-outside-toplevel
|
||||
log_user,
|
||||
)
|
||||
|
||||
log_user(with_rollover=False)
|
||||
|
||||
@staticmethod
|
||||
def __log_end(logger: Logger, method_chosen: Callable):
|
||||
logger.info(
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import logging
|
||||
|
||||
from openbb_terminal.decorators import log_start_end
|
||||
from openbb_terminal.rich_config import console
|
||||
from openbb_terminal.session import (
|
||||
local_model as Local,
|
||||
@@ -5,6 +8,8 @@ from openbb_terminal.session import (
|
||||
)
|
||||
from openbb_terminal.session.user import User
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_session(email: str, password: str, token: str, save: bool):
|
||||
session = ""
|
||||
@@ -13,7 +18,7 @@ def get_session(email: str, password: str, token: str, save: bool):
|
||||
console.print("Creating session from token.")
|
||||
session = session_model.create_session_from_token(token, save) # type: ignore
|
||||
|
||||
if not session:
|
||||
if not session and email:
|
||||
console.print("Creating session from email and password.")
|
||||
session = session_model.create_session(email, password, save) # type: ignore
|
||||
|
||||
@@ -23,6 +28,7 @@ def get_session(email: str, password: str, token: str, save: bool):
|
||||
return session
|
||||
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def login(
|
||||
email: str = "", password: str = "", token: str = "", keep_session: bool = False
|
||||
):
|
||||
@@ -49,11 +55,10 @@ def login(
|
||||
>>> from openbb_terminal.sdk import openbb
|
||||
>>> openbb.login(email="your_email", password="your_password")
|
||||
"""
|
||||
|
||||
session = Local.get_session()
|
||||
if not (email or token):
|
||||
session = Local.get_session()
|
||||
|
||||
if not session:
|
||||
console.print("No local session found. Creating new session.")
|
||||
session = get_session(email, password, token, keep_session)
|
||||
else:
|
||||
console.print("Using local session to login.")
|
||||
@@ -65,6 +70,7 @@ def login(
|
||||
console.print("[green]Login successful.[/green]")
|
||||
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def logout():
|
||||
"""
|
||||
Logout and clear session.
|
||||
@@ -81,6 +87,7 @@ def logout():
|
||||
)
|
||||
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def whoami():
|
||||
"""
|
||||
Display user info.
|
||||
|
||||
@@ -16,6 +16,7 @@ def settings(tmp_path):
|
||||
name="MOCK_NAME",
|
||||
identifier="MOCK_IDENTIFIER",
|
||||
session_id="MOCK_SESSION_ID",
|
||||
user_id="MOCK_USER_ID",
|
||||
),
|
||||
aws_settings=AWSSettings(
|
||||
aws_access_key_id="MOCK_AWS_ACCESS_KEY_ID",
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"userId": "MOCK_USER_ID", "sessionId": "MOCK_SESSION_ID"}
|
||||
{"sessionId": "MOCK_SESSION_ID"}
|
||||
@@ -14,6 +14,7 @@ app_settings = AppSettings(
|
||||
name="MOCK_COMMIT_HASH",
|
||||
identifier="MOCK_COMMIT_HASH",
|
||||
session_id="MOCK_SESSION_ID",
|
||||
user_id="MOCK_USER_ID",
|
||||
)
|
||||
formatter = FormatterWithExceptions(app_settings)
|
||||
|
||||
|
||||
@@ -24,12 +24,14 @@ def test_app_settings():
|
||||
commit_hash = "MOCK_COMMIT_HASH"
|
||||
session_id = "MOCK_SESSION_ID"
|
||||
identifier = "MOCK_IDENTIFIER"
|
||||
user_id = "MOCK_USER_ID"
|
||||
|
||||
app_settings = AppSettings(
|
||||
name=name,
|
||||
commit_hash=commit_hash,
|
||||
session_id=session_id,
|
||||
identifier=identifier,
|
||||
user_id=user_id,
|
||||
)
|
||||
|
||||
assert app_settings.name == name
|
||||
@@ -78,11 +80,13 @@ def test_settings(tmp_path):
|
||||
commit_hash = "MOCK_COMMIT_HASH"
|
||||
session_id = "MOCK_SESSION_ID"
|
||||
identifier = "MOCK_IDENTIFIER"
|
||||
user_id = "MOCK_USER_ID"
|
||||
app_settings = AppSettings(
|
||||
name=name,
|
||||
commit_hash=commit_hash,
|
||||
session_id=session_id,
|
||||
identifier=identifier,
|
||||
user_id=user_id,
|
||||
)
|
||||
|
||||
aws_access_key_id = "MOCK_AWS_ACCESS_KEY_ID"
|
||||
|
||||
@@ -16,6 +16,7 @@ settings = Settings(
|
||||
name="MOCK_COMMIT_HASH",
|
||||
identifier="MOCK_COMMIT_HASH",
|
||||
session_id="MOCK_SESSION_ID",
|
||||
user_id="MOCK_USER_ID",
|
||||
),
|
||||
aws_settings=AWSSettings(
|
||||
aws_access_key_id="MOCK_AWS_ACCESS_KEY_ID",
|
||||
|
||||
@@ -19,6 +19,6 @@ eval [-q QUERY [QUERY ...]]
|
||||
|
||||
| Name | Description | Default | Optional | Choices |
|
||||
| ---- | ----------- | ------- | -------- | ------- |
|
||||
| query | Query to evaluate on loaded datasets | None | True | None |
|
||||
| query | Query to evaluate on loaded datasets | None | False | None |
|
||||
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user