Skip to content

Commit

Permalink
Merge branch 'develop' into hotfix/Ultima-platform-endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
AdiSai authored Nov 30, 2023
2 parents 667ee20 + a784bba commit 96f5e0a
Show file tree
Hide file tree
Showing 97 changed files with 5,828 additions and 2,706 deletions.
668 changes: 32 additions & 636 deletions openbb_platform/core/README.md

Large diffs are not rendered by default.

71 changes: 54 additions & 17 deletions openbb_platform/core/openbb_core/app/static/account.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Account service."""
# pylint: disable=W0212:protected-access
import json
from functools import wraps
Expand All @@ -17,24 +18,31 @@


class Account:
"""/account
login
logout
save
refresh"""
"""The account service handles the following commands.
/account
login
logout
save
refresh
"""

SESSION_FILE = ".hub_session.json"

def __init__(self, base_app: "BaseApp"):
"""Initialize account service."""
self._base_app = base_app
self._openbb_directory = (
base_app._command_runner.system_settings.openbb_directory
)

def __repr__(self) -> str:
"""Human readable representation of the object."""
return self.__doc__ or ""

def _log_account_command(func): # pylint: disable=E0213
"""Log account command."""

@wraps(func)
def wrapped(self, *args, **kwargs):
try:
Expand Down Expand Up @@ -82,14 +90,15 @@ def _create_hub_service(
hs.connect(email, password, pat)
return hs

@_log_account_command
@_log_account_command # type: ignore
def login(
self,
email: Optional[str] = None,
password: Optional[str] = None,
pat: Optional[str] = None,
remember_me: bool = False,
) -> UserSettings:
return_settings: bool = False,
) -> Optional[UserSettings]:
"""Login to hub.
Parameters
Expand All @@ -102,6 +111,8 @@ def login(
Personal access token, by default None
remember_me : bool, optional
Remember me, by default False
return_settings : bool, optional
Return user settings, by default False
Returns
-------
Expand All @@ -121,12 +132,19 @@ def login(

json.dump(hs.session.model_dump(mode="json"), f, indent=4)

return self._base_app._command_runner.user_settings
if return_settings:
return self._base_app._command_runner.user_settings
return None

@_log_account_command
def save(self) -> UserSettings:
@_log_account_command # type: ignore
def save(self, return_settings: bool = False) -> Optional[UserSettings]:
"""Save user settings.
Parameters
----------
return_settings : bool, optional
Return user settings, by default False
Returns
-------
UserSettings
Expand All @@ -140,12 +158,20 @@ def save(self) -> UserSettings:
else:
hs = HubService(hub_session)
hs.push(self._base_app._command_runner.user_settings)
return self._base_app._command_runner.user_settings

@_log_account_command
def refresh(self) -> UserSettings:
if return_settings:
return self._base_app._command_runner.user_settings
return None

@_log_account_command # type: ignore
def refresh(self, return_settings: bool = False) -> Optional[UserSettings]:
"""Refresh user settings.
Parameters
----------
return_settings : bool, optional
Return user settings, by default False
Returns
-------
UserSettings
Expand All @@ -162,12 +188,20 @@ def refresh(self) -> UserSettings:
updated: UserSettings = UserService.update_default(incoming)
updated.id = self._base_app._command_runner.user_settings.id
self._base_app._command_runner.user_settings = updated
return self._base_app._command_runner.user_settings

@_log_account_command
def logout(self) -> UserSettings:
if return_settings:
return self._base_app._command_runner.user_settings
return None

@_log_account_command # type: ignore
def logout(self, return_settings: bool = False) -> Optional[UserSettings]:
"""Logout from hub.
Parameters
----------
return_settings : bool, optional
Return user settings, by default False
Returns
-------
UserSettings
Expand All @@ -187,4 +221,7 @@ def logout(self) -> UserSettings:
self._base_app._command_runner.user_settings = (
UserService.read_default_user_settings()
)
return self._base_app._command_runner.user_settings

if return_settings:
return self._base_app._command_runner.user_settings
return None
872 changes: 516 additions & 356 deletions openbb_platform/core/poetry.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions openbb_platform/core/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "openbb-core"
version = "1.0.0b2"
version = "1.0.0rc0"
description = "OpenBB package with core functionality"
authors = ["OpenBB Team <[email protected]>"]
readme = "README.md"
Expand All @@ -22,11 +22,14 @@ requests = "^2.31.0"
importlib-metadata = "^6.8.0"
python-dotenv = "^1.0.0"
aiohttp = "^3.9.0"
black = "^23.11.0"
ruff = "^0.1.6"

[tool.poetry.group.dev.dependencies]
pytest = "^7.0.0"
pytest-subtests = "^0.11.0"
pytest-recorder = "^0.2.4"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
79 changes: 49 additions & 30 deletions openbb_platform/dev_install.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Install for development script."""
# noqa: S603,PLW1510,T201
import subprocess
import sys
from pathlib import Path
Expand Down Expand Up @@ -57,61 +56,81 @@
openbb-technical = { path = "./extensions/technical", optional = true, develop = true }
"""

pyproject_toml = toml.load(PYPROJECT)
pyproject_toml["tool"]["poetry"]["dependencies"] = toml.loads(LOCAL_DEPS)["tool"][
"poetry"
]["dependencies"]

TEMP_PYPROJECT = toml.dumps(pyproject_toml)
def extract_dev_dependencies(local_dep_path):
"""Extract development dependencies from a given package's pyproject.toml."""
package_pyproject_path = PLATFORM_PATH / local_dep_path
if package_pyproject_path.exists():
package_pyproject_toml = toml.load(package_pyproject_path / "pyproject.toml")
return (
package_pyproject_toml.get("tool", {})
.get("poetry", {})
.get("group", {})
.get("dev", {})
.get("dependencies", {})
)
return {}


def install_local(_extras: bool = False):
"""Install the Platform locally for development purposes.
def get_all_dev_dependencies():
"""Aggregate development dependencies from all local packages."""
all_dev_dependencies = {}
local_deps = toml.loads(LOCAL_DEPS)["tool"]["poetry"]["dependencies"]
for _, package_info in local_deps.items():
if "path" in package_info:
dev_deps = extract_dev_dependencies(Path(package_info["path"]))
all_dev_dependencies.update(dev_deps)
return all_dev_dependencies

Installs the Platform in editable mode, instead of copying the source code to
the site-packages directory. This makes any changes immediately available
to the interpreter.

Parameters
----------
_extras : bool, optional
Whether to install the Platform with the extra dependencies, by default False
"""
def install_local(_extras: bool = False):
"""Install the Platform locally for development purposes."""
original_lock = LOCK.read_text()
original_pyproject = PYPROJECT.read_text()
extras_args = ["-E", "all"] if _extras else []

pyproject_toml = toml.load(PYPROJECT)
local_deps = toml.loads(LOCAL_DEPS)["tool"]["poetry"]["dependencies"]
pyproject_toml["tool"]["poetry"]["dependencies"].update(local_deps)

if _extras:
dev_dependencies = get_all_dev_dependencies()
pyproject_toml["tool"]["poetry"].setdefault("group", {}).setdefault(
"dev", {}
).setdefault("dependencies", {})
pyproject_toml["tool"]["poetry"]["group"]["dev"]["dependencies"].update(
dev_dependencies
)

TEMP_PYPROJECT = toml.dumps(pyproject_toml)

try:
# we create a temporary pyproject.toml
with open(PYPROJECT, "w", encoding="utf-8", newline="\n") as f:
f.write(TEMP_PYPROJECT)

CMD = [sys.executable, "-m", "poetry"]
extras_args = ["-E", "all"] if _extras else []

subprocess.run( # noqa: PLW1510
subprocess.run(
CMD + ["lock", "--no-update"], cwd=PLATFORM_PATH, check=True # noqa: S603
)
subprocess.run( # noqa: PLW1510
subprocess.run(
CMD + ["install"] + extras_args, cwd=PLATFORM_PATH, check=True # noqa: S603
)

except (Exception, KeyboardInterrupt) as e:
print(e) # noqa: T201
print("Restoring pyproject.toml and poetry.lock") # noqa: T201

# we restore the original pyproject.toml
with open(PYPROJECT, "w", encoding="utf-8", newline="\n") as f:
f.write(original_pyproject)
finally:
# Revert pyproject.toml and poetry.lock to their original state
with open(PYPROJECT, "w", encoding="utf-8", newline="\n") as f:
f.write(original_pyproject)

# we restore the original poetry.lock
with open(LOCK, "w", encoding="utf-8", newline="\n") as f:
f.write(original_lock)
with open(LOCK, "w", encoding="utf-8", newline="\n") as f:
f.write(original_lock)


if __name__ == "__main__":
args = sys.argv[1:]

# pylint: disable=use-a-generator
extras = any([arg.lower() in ["-e", "--extras"] for arg in args])

extras = any(arg.lower() in ["-e", "--extras"] for arg in args)
install_local(extras)
Loading

0 comments on commit 96f5e0a

Please sign in to comment.