Skip to content

Commit

Permalink
Merge branch 'develop' into feature/improved-web-security
Browse files Browse the repository at this point in the history
  • Loading branch information
piiq authored May 13, 2024
2 parents 2881f04 + f47e7ad commit e18526a
Show file tree
Hide file tree
Showing 51 changed files with 2,337 additions and 1,322 deletions.
5 changes: 5 additions & 0 deletions assets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Assets

This folder should hold assets read by OpenBB applications, such as OpenBB Hub or marketing website.

The goal is to be more explicit about which assets are being used externally and cannot be deleted before checking where they are used.
6 changes: 6 additions & 0 deletions assets/extensions/obbject.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"packageName": "openbb-charting",
"description": "Create custom charts from OBBject data."
}
]
258 changes: 258 additions & 0 deletions assets/extensions/provider.json

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletions assets/extensions/router.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[
{
"packageName": "openbb-commodity",
"description": "Commodity market data."
},
{
"packageName": "openbb-crypto",
"description": "Cryptocurrency market data."
},
{
"packageName": "openbb-currency",
"description": "Foreign exchange (FX) market data."
},
{
"packageName": "openbb-derivatives",
"description": "Derivatives market data."
},
{
"packageName": "openbb-econometrics",
"description": "Econometrics analysis tools."
},
{
"packageName": "openbb-economy",
"description": "Economic data."
},
{
"packageName": "openbb-equity",
"description": "Equity market data."
},
{
"packageName": "openbb-etf",
"description": "Exchange Traded Funds market data."
},
{
"packageName": "openbb-fixedincome",
"description": "Fixed Income market data."
},
{
"packageName": "openbb-index",
"description": "Indices data."
},
{
"packageName": "openbb-news",
"description": "Financial market news data."
},
{
"packageName": "openbb-quantitative",
"description": "Quantitative analysis tools."
},
{
"packageName": "openbb-regulators",
"description": "Financial market regulators data."
},
{
"packageName": "openbb-technical",
"description": "Technical Analysis tools."
}
]
115 changes: 115 additions & 0 deletions assets/scripts/generate_extension_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
"""Generate assets from modules."""

from importlib import import_module
from json import dump
from pathlib import Path
from typing import Any, Dict, List

from poetry.core.pyproject.toml import PyProjectTOML

THIS_DIR = Path(__file__).parent
PROVIDERS_PATH = Path(THIS_DIR, "..", "..", "openbb_platform/providers")
EXTENSIONS_PATH = Path(THIS_DIR, "..", "..", "openbb_platform/extensions")
OBBJECT_EXTENSIONS_PATH = Path(
THIS_DIR, "..", "..", "openbb_platform/obbject_extensions"
)


def to_title(string: str) -> str:
"""Format string to title."""
return " ".join(string.split("_")).title()


def get_packages(path: Path, plugin_key: str) -> Dict[str, Any]:
"""Get packages."""
SKIP = ["tests", "__pycache__"]
folders = [f for f in path.glob("*") if f.is_dir() and f.stem not in SKIP]
packages: Dict[str, Any] = {}
for f in folders:
pyproject = PyProjectTOML(Path(f, "pyproject.toml"))
poetry = pyproject.data["tool"]["poetry"]
name = poetry["name"]
plugin = poetry.get("plugins", {}).get(plugin_key)
packages[name] = list(plugin.values())[0] if plugin else ""
return packages


def write(filename: str, data: Any):
"""Write to json."""
with open(Path(THIS_DIR, "..", "extensions", f"{filename}.json"), "w") as json_file:
dump(data, json_file, indent=4)


def to_camel(string: str):
"""Convert string to camel case."""
components = string.split("_")
return components[0] + "".join(x.title() for x in components[1:])


def createItem(package_name: str, obj: object, attrs: List[str]) -> Dict[str, str]:
"""Create dictionary item from object attributes."""
item = {"packageName": package_name}
item.update(
{to_camel(a): getattr(obj, a) for a in attrs if getattr(obj, a) is not None}
)
return item


def generate_provider_extensions() -> None:
"""Generate providers_extensions.json."""
packages = get_packages(PROVIDERS_PATH, "openbb_provider_extension")
data: List[Dict[str, str]] = []
attrs = [
"repr_name",
"description",
"credentials",
"v3_credentials",
"website",
"instructions",
"logo_url",
]

for pkg_name, plugin in sorted(packages.items()):
file_obj = plugin.split(":")
if len(file_obj) == 2:
file, obj = file_obj[0], file_obj[1]
module = import_module(file)
provider_obj = getattr(module, obj)
data.append(createItem(pkg_name, provider_obj, attrs))
write("provider", data)


def generate_router_extensions() -> None:
"""Generate router_extensions.json."""
packages = get_packages(EXTENSIONS_PATH, "openbb_core_extension")
data: List[Dict[str, str]] = []
attrs = ["description"]
for pkg_name, plugin in sorted(packages.items()):
file_obj = plugin.split(":")
if len(file_obj) == 2:
file, obj = file_obj[0], file_obj[1]
module = import_module(file)
router_obj = getattr(module, obj)
data.append(createItem(pkg_name, router_obj, attrs))
write("router", data)


def generate_obbject_extensions() -> None:
"""Generate obbject_extensions.json."""
packages = get_packages(OBBJECT_EXTENSIONS_PATH, "openbb_obbject_extension")
data: List[Dict[str, str]] = []
attrs = ["description"]
for pkg_name, plugin in sorted(packages.items()):
file_obj = plugin.split(":")
if len(file_obj) == 2:
file, obj = file_obj[0], file_obj[1]
module = import_module(file)
ext_obj = getattr(module, obj)
data.append(createItem(pkg_name, ext_obj, attrs))
write("obbject", data)


if __name__ == "__main__":
generate_provider_extensions()
generate_router_extensions()
generate_obbject_extensions()
7 changes: 4 additions & 3 deletions build/pypi/openbb_platform/PUBLISH.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

1. Install the packages on Google Colaboratory via PyPi and test to check if everything is working as expected.
2. Install the packages in a new environment locally via PyPi and test to check if everything is working as expected.
3. Open a new PR with the `release/<package>-<version>` branch pointing to the `develop` branch.
4. Merge the `release/<package>-<version>` branch to the `develop` branch.
5. If any bugs are encountered, create a new branch - `hotfix` for `main` and `bugfix` for `develop` and merge them accordingly.
3. Regenerate assets for external use by running `python assets/scripts/generate_extension_data.py`
4. Open a new PR with the `release/<package>-<version>` branch pointing to the `develop` branch.
5. Merge the `release/<package>-<version>` branch to the `develop` branch.
6. If any bugs are encountered, create a new branch - `hotfix` for `main` and `bugfix` for `develop` and merge them accordingly.
36 changes: 0 additions & 36 deletions cli/openbb_cli/assets/i18n/en.yml

This file was deleted.

1 change: 0 additions & 1 deletion cli/openbb_cli/config/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
STYLES_DIRECTORY = ASSETS_DIRECTORY / "styles"
ENV_FILE_SETTINGS = SETTINGS_DIRECTORY / ".cli.env"
HIST_FILE_PROMPT = SETTINGS_DIRECTORY / ".cli.his"
I18N_FILE = ASSETS_DIRECTORY / "i18n"


DEFAULT_ROUTINES_URL = "https://openbb-cms.directus.app/items/Routines"
Expand Down
36 changes: 10 additions & 26 deletions cli/openbb_cli/config/menu_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from typing import Dict, List

import i18n
from openbb import obb

# https://rich.readthedocs.io/en/stable/appendix/colors.html#appendix-colors
Expand Down Expand Up @@ -92,10 +91,8 @@ def _format_cmd_description(
self, name: str, description: str, trim: bool = True
) -> str:
"""Truncate command description length if it is too long."""
if not description:
description = i18n.t(self.menu_path + name)
if description == self.menu_path + name:
description = ""
if not description or description == f"{self.menu_path}{name}":
description = ""
return (
description[: self.CMD_DESCRIPTION_LENGTH - 3] + "..."
if len(description) > self.CMD_DESCRIPTION_LENGTH and trim
Expand All @@ -122,23 +119,9 @@ def add_section(
else:
self.menu_text += text

def add_custom(self, name: str):
"""Append custom text (after translation)."""
self.menu_text += f"{i18n.t(self.menu_path + name)}"

def add_info(self, text: str):
"""Append information text (after translation)."""
self.menu_text += f"[info]{i18n.t(self.menu_path + text)}:[/info]\n"

def add_param(self, name: str, value: str, col_align: int = 0):
"""Append parameter (after translation)."""
parameter_translated = i18n.t(self.menu_path + name)
space = (
(col_align - len(parameter_translated)) * " "
if col_align > len(parameter_translated)
else ""
)
self.menu_text += f"[param]{parameter_translated}{space}:[/param] {value}\n"
self.menu_text += f"[info]{text}:[/info]\n"

def add_cmd(self, name: str, description: str = "", disable: bool = False):
"""Append command text (after translation)."""
Expand Down Expand Up @@ -174,10 +157,8 @@ def add_menu(
"""Append menu text (after translation)."""
spacing = (self.CMD_NAME_LENGTH - len(name) + self.SECTION_SPACING) * " "

if not description:
description = i18n.t(self.menu_path + name)
if description == self.menu_path + name:
description = ""
if not description or description == f"{self.menu_path}{name}":
description = ""

if len(description) > self.CMD_DESCRIPTION_LENGTH:
description = description[: self.CMD_DESCRIPTION_LENGTH - 3] + "..."
Expand All @@ -186,9 +167,12 @@ def add_menu(
tag = "unvl" if disable else "menu"
self.menu_text += f"[{tag}]> {menu}[/{tag}]\n"

def add_setting(self, name: str, status: bool = True):
def add_setting(self, name: str, status: bool = True, description: str = ""):
"""Append menu text (after translation)."""
spacing = (self.CMD_NAME_LENGTH - len(name) + self.SECTION_SPACING) * " "
indentation = self.SECTION_SPACING * " "
color = "green" if status else "red"
self.menu_text += f"[{color}]{indentation}{name}{spacing}{i18n.t(self.menu_path + name)}[/{color}]\n"

self.menu_text += (
f"[{color}]{indentation}{name}{spacing}{description}[/{color}]\n"
)
Loading

0 comments on commit e18526a

Please sign in to comment.