Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove hold command and its references #6399

Merged
merged 7 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 0 additions & 62 deletions cli/openbb_cli/config/setup.py
Original file line number Diff line number Diff line change
@@ -1,71 +1,9 @@
"""Configuration for the CLI."""

import copy
from pathlib import Path
from typing import TYPE_CHECKING, List, Optional, TypeVar

from openbb_cli.config.constants import ENV_FILE_SETTINGS, SETTINGS_DIRECTORY

if TYPE_CHECKING:
from openbb_charting.core.openbb_figure import OpenBBFigure

# ruff: noqa:PLW0603

OpenBBFigureT = TypeVar("OpenBBFigureT", bound="OpenBBFigure")
HOLD: bool = False
COMMAND_ON_CHART: bool = True
current_figure: Optional[OpenBBFigureT] = None # type: ignore
new_axis: bool = True
legends: List = []
last_legend = ""


# pylint: disable=global-statement
def set_last_legend(leg: str):
"""Set the last legend."""
global last_legend
last_legend = copy.deepcopy(leg)


def reset_legend() -> None:
"""Reset the legend."""
global legends
legends = []


def get_legends() -> list:
"""Get the legends."""
return legends


def set_same_axis() -> None:
"""Set the same axis."""
global new_axis
new_axis = False


def set_new_axis() -> None:
"""Set the new axis."""
global new_axis
new_axis = True


def make_new_axis() -> bool:
"""Make a new axis."""
return new_axis


def get_current_figure() -> Optional["OpenBBFigure"]:
"""Get the current figure."""
return current_figure


def set_current_figure(fig: Optional[OpenBBFigureT] = None):
"""Set the current figure."""
# pylint: disable=global-statement
global current_figure
current_figure = fig


def bootstrap():
"""Setup pre-launch configurations for the CLI."""
Expand Down
124 changes: 0 additions & 124 deletions cli/openbb_cli/controllers/base_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from typing import Any, Dict, List, Literal, Optional, Union

import pandas as pd
from openbb_cli.config import setup
from openbb_cli.config.completer import NestedCompleter
from openbb_cli.config.constants import SCRIPT_TAGS
from openbb_cli.controllers.choices import build_controller_choice_map
Expand Down Expand Up @@ -63,14 +62,12 @@ class BaseController(metaclass=ABCMeta):
"r",
"reset",
"stop",
"hold",
"whoami",
"results",
]

CHOICES_COMMANDS: List[str] = []
CHOICES_MENUS: List[str] = []
HOLD_CHOICES: dict = {}
NEWS_CHOICES: dict = {}
COMMAND_SEPARATOR = "/"
KEYS_MENU = "keys" + COMMAND_SEPARATOR
Expand Down Expand Up @@ -166,113 +163,6 @@ def load_class(self, class_ins, *args, **kwargs):
return old_class.menu()
return class_ins(*args, **kwargs).menu()

def call_hold(self, other_args: List[str]) -> None:
"""Process hold command."""
self.save_class()
parser = argparse.ArgumentParser(
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
prog="hold",
description="Turn on figure holding. This will stop showing images until hold off is run.",
)
parser.add_argument(
"-o",
"--option",
choices=["on", "off"],
type=str,
default="off",
dest="option",
)
parser.add_argument(
"-s",
"--sameaxis",
action="store_true",
default=False,
help="Put plots on the same axis. Best when numbers are on similar scales",
dest="axes",
)
parser.add_argument(
"--title",
type=str,
default="",
dest="title",
nargs="+",
help="When using hold off, this sets the title for the figure.",
)
if other_args and "-" not in other_args[0][0]:
other_args.insert(0, "-o")

ns_parser = self.parse_known_args_and_warn(
parser,
other_args,
)
if ns_parser:
if ns_parser.option == "on":
setup.HOLD = True
setup.COMMAND_ON_CHART = False
if ns_parser.axes:
setup.set_same_axis()
else:
setup.set_new_axis()
if ns_parser.option == "off":
setup.HOLD = False
if setup.get_current_figure() is not None:
# create a subplot
fig = setup.get_current_figure()
if fig is None:
return
if not fig.has_subplots and not setup.make_new_axis():
fig.set_subplots(1, 1, specs=[[{"secondary_y": True}]])

if setup.make_new_axis():
for i, trace in enumerate(fig.select_traces()):
trace.yaxis = f"y{i+1}"

if i != 0:
fig.update_layout(
{
f"yaxis{i+1}": dict(
side="left",
overlaying="y",
showgrid=True,
showline=False,
zeroline=False,
automargin=True,
ticksuffix=(
" " * (i - 1) if i > 1 else ""
),
tickfont=dict(
size=18,
),
title=dict(
font=dict(
size=15,
),
standoff=0,
),
),
}
)
# pylint: disable=undefined-loop-variable
fig.update_layout(margin=dict(l=30 * i))

else:
fig.update_yaxes(title="")

if any(setup.get_legends()):
for trace, new_name in zip(
fig.select_traces(), setup.get_legends()
):
if new_name:
trace.name = new_name

fig.update_layout(title=" ".join(ns_parser.title))
fig.show()
setup.COMMAND_ON_CHART = True

setup.set_current_figure(None)
setup.reset_legend()

def save_class(self) -> None:
"""Save the current instance of the class to be loaded later."""
if session.settings.REMEMBER_CONTEXTS:
Expand Down Expand Up @@ -832,16 +722,6 @@ def parse_known_args_and_warn(
"-h", "--help", action="store_true", help="show this help message"
)

if setup.HOLD:
parser.add_argument(
"--legend",
type=str,
dest="hold_legend_str",
default="",
nargs="+",
help="Label for legend when hold is on.",
)

if export_allowed != "no_export":
choices_export = []
help_export = "Does not export!"
Expand Down Expand Up @@ -925,10 +805,6 @@ def parse_known_args_and_warn(

return None

# This protects against the hidden loads in stocks/fa
if parser.prog != "load" and setup.HOLD:
setup.set_last_legend(" ".join(ns_parser.hold_legend_str))

if l_unknown_args:
session.console.print(
f"The following args couldn't be interpreted: {l_unknown_args}"
Expand Down
6 changes: 1 addition & 5 deletions cli/openbb_cli/controllers/cli_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ def update_runtime_choices(self):
if session.prompt_session and session.settings.USE_PROMPT_TOOLKIT:
# choices: dict = self.choices_default
choices: dict = {c: {} for c in self.controller_choices} # type: ignore
choices["hold"] = {c: None for c in ["on", "off", "-s", "--sameaxis"]}
choices["hold"]["off"] = {"--title": None}

self.ROUTINE_FILES = {
filepath.name: filepath # type: ignore
Expand Down Expand Up @@ -199,8 +197,6 @@ def update_runtime_choices(self):
"-d": "--description",
"--public": None,
"-p": "--public",
"--local": None,
"-l": "--local",
"--tag1": {c: None for c in constants.SCRIPT_TAGS},
"--tag2": {c: None for c in constants.SCRIPT_TAGS},
"--tag3": {c: None for c in constants.SCRIPT_TAGS},
Expand Down Expand Up @@ -481,7 +477,7 @@ def call_exe(self, other_args: List[str]):

except FileNotFoundError:
session.console.print(
f"[red]File '{routine_path}' doesn't exist.[/red]\n"
f"[red]File '{routine_path}' doesn't exist.[/red]"
)
return

Expand Down
Loading