Skip to content

Commit

Permalink
[Feature] Update chart creation so it doesn't break the command execu…
Browse files Browse the repository at this point in the history
…tion (#6382)

* chart execution to not break the whole call

* pylint: disable=broad-exception-caught

---------

Co-authored-by: Danglewood <[email protected]>
  • Loading branch information
hjoaquim and deeleeramone authored May 9, 2024
1 parent 9bdc0f1 commit 83476ad
Showing 1 changed file with 33 additions and 25 deletions.
58 changes: 33 additions & 25 deletions openbb_platform/core/openbb_core/app/command_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,31 +304,38 @@ def _chart(
**kwargs,
) -> None:
"""Create a chart from the command output."""
if "charting" not in obbject.accessors:
raise OpenBBError(
"Charting is not installed. Please install `openbb-charting`."
)
chart_params = {}
extra_params = kwargs.get("extra_params", {})

if hasattr(extra_params, "__dict__") and hasattr(extra_params, "chart_params"):
chart_params = kwargs["extra_params"].__dict__.get("chart_params", {})
elif isinstance(extra_params, dict) and "chart_params" in extra_params:
chart_params = kwargs["extra_params"].get("chart_params", {})

if "chart_params" in kwargs and kwargs["chart_params"] is not None:
chart_params.update(kwargs.pop("chart_params", {}))

if (
"kwargs" in kwargs
and "chart_params" in kwargs["kwargs"]
and kwargs["kwargs"].get("chart_params") is not None
):
chart_params.update(kwargs.pop("kwargs", {}).get("chart_params", {}))

if chart_params:
kwargs.update(chart_params)
obbject.charting.show(render=False, **kwargs)
try:
if "charting" not in obbject.accessors:
raise OpenBBError(
"Charting is not installed. Please install `openbb-charting`."
)
chart_params = {}
extra_params = kwargs.get("extra_params", {})

if hasattr(extra_params, "__dict__") and hasattr(
extra_params, "chart_params"
):
chart_params = kwargs["extra_params"].__dict__.get("chart_params", {})
elif isinstance(extra_params, dict) and "chart_params" in extra_params:
chart_params = kwargs["extra_params"].get("chart_params", {})

if "chart_params" in kwargs and kwargs["chart_params"] is not None:
chart_params.update(kwargs.pop("chart_params", {}))

if (
"kwargs" in kwargs
and "chart_params" in kwargs["kwargs"]
and kwargs["kwargs"].get("chart_params") is not None
):
chart_params.update(kwargs.pop("kwargs", {}).get("chart_params", {}))

if chart_params:
kwargs.update(chart_params)
obbject.charting.show(render=False, **kwargs)
except Exception as e: # pylint: disable=broad-exception-caught
if Env().DEBUG_MODE:
raise OpenBBError(e) from e
warn(str(e), OpenBBWarning)

# pylint: disable=R0913, R0914
@classmethod
Expand Down Expand Up @@ -449,6 +456,7 @@ async def run(
except Exception as e:
if Env().DEBUG_MODE:
raise OpenBBError(e) from e
warn(str(e), OpenBBWarning)

return obbject

Expand Down

0 comments on commit 83476ad

Please sign in to comment.