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

Core: move parse_simple_args #3705

Merged
merged 32 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
399e898
Moving Docker folder into Build
Chavithra Nov 23, 2022
e3e3712
Workflows : update Docker
Chavithra Nov 23, 2022
7655afa
Docker : update compose image version
Chavithra Nov 23, 2022
7c4acc1
Docker : fix volumes path
Chavithra Nov 23, 2022
1305f13
Merge branch 'main' of github.com:OpenBB-finance/OpenBBTerminal
Chavithra Nov 23, 2022
606a8a3
Merge branch 'main' of github.com:OpenBB-finance/OpenBBTerminal
Chavithra Nov 27, 2022
cb09e40
Merge branch 'main' of github.com:OpenBB-finance/OpenBBTerminal
Chavithra Nov 27, 2022
69cb64d
Merge branch 'main' of github.com:OpenBB-finance/OpenBBTerminal
Chavithra Nov 28, 2022
a4fce79
Merge branch 'main' of github.com:OpenBB-finance/OpenBBTerminal
Chavithra Nov 28, 2022
80aa476
Merge branch 'main' of github.com:OpenBB-finance/OpenBBTerminal
Chavithra Nov 28, 2022
cb08bf0
Merge branch 'main' of github.com:OpenBB-finance/OpenBBTerminal
Chavithra Nov 29, 2022
b6300ab
Merge branch 'main' of github.com:OpenBB-finance/OpenBBTerminal
Chavithra Nov 29, 2022
1a78841
Merge branch 'main' of github.com:OpenBB-finance/OpenBBTerminal
Chavithra Nov 29, 2022
1d9ce6f
Merge branch 'main' of github.com:OpenBB-finance/OpenBBTerminal
Chavithra Nov 29, 2022
971c5eb
Merge branch 'main' of github.com:OpenBB-finance/OpenBBTerminal
Chavithra Nov 29, 2022
663b6ce
Merge branch 'main' of github.com:OpenBB-finance/OpenBBTerminal
Chavithra Nov 30, 2022
01aaf2e
Merge branch 'main' of github.com:OpenBB-finance/OpenBBTerminal
Chavithra Dec 3, 2022
a29c0bd
Merge branch 'main' of github.com:OpenBB-finance/OpenBBTerminal
Chavithra Dec 4, 2022
6aa40e3
Merge branch 'main' of github.com:OpenBB-finance/OpenBBTerminal
Chavithra Dec 4, 2022
8176d82
Update core
Chavithra Dec 5, 2022
db620f7
Update helper_funcs
Chavithra Dec 5, 2022
3934f1c
Update dashboards
Chavithra Dec 5, 2022
cf56b90
Update reports
Chavithra Dec 5, 2022
e74dc06
Update keys_controller
Chavithra Dec 5, 2022
eee6511
Update settings_controller
Chavithra Dec 5, 2022
ab3fa33
Update sources_controller
Chavithra Dec 5, 2022
d60c3e0
Tests : fix __mock_parse_simple_args
Chavithra Dec 5, 2022
8ca186a
Merge branch 'main' into move_parse_simple_args
Chavithra Dec 5, 2022
672ba4f
Merge branch 'main' into move_parse_simple_args
Chavithra Dec 5, 2022
6a231b3
Reduce lines
Chavithra Dec 5, 2022
6c932c3
Merge branch 'move_parse_simple_args' of github.com:Chavithra/OpenBBT…
Chavithra Dec 5, 2022
49f3583
Merge branch 'main' into move_parse_simple_args
jmaslek Dec 5, 2022
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
7 changes: 4 additions & 3 deletions openbb_terminal/core/completer/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def __mock_parse_known_args_and_warn(

def __mock_parse_simple_args(parser: ArgumentParser, other_args: List[str]) -> None:
"""Add the arguments that would have normally added by:
- openbb_terminal.helper_funcs.parse_simple_args
- openbb_terminal.parent_classes.BaseController.parse_simple_args

Parameters
----------
Expand Down Expand Up @@ -199,8 +199,9 @@ def __patch_controller_functions(controller):
)

patcher_list = [
patch(
target="openbb_terminal.parent_classes.parse_simple_args",
patch.object(
target=controller,
attribute="parse_simple_args",
side_effect=__mock_parse_simple_args,
return_value=None,
),
Expand Down
225 changes: 115 additions & 110 deletions openbb_terminal/dashboards/dashboards_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from openbb_terminal.menu import session
from openbb_terminal.parent_classes import BaseController
from openbb_terminal.rich_config import console, MenuText
from openbb_terminal.helper_funcs import parse_simple_args

# pylint: disable=consider-using-with

Expand Down Expand Up @@ -69,146 +68,152 @@ def print_help(self):
@log_start_end(log=logger)
def call_stocks(self, other_args: List[str]):
"""Process stocks command"""
create_call_voila(other_args, "stocks", "stocks")
self.create_call_voila(other_args, "stocks", "stocks")

@log_start_end(log=logger)
def call_correlation(self, other_args: List[str]):
"""Process correlation command"""
create_call_voila(other_args, "correlation", "correlation")
self.create_call_voila(other_args, "correlation", "correlation")

@log_start_end(log=logger)
def call_vsurf(self, other_args: List[str]):
"""Process vsurf command"""
create_call_voila(other_args, "vsurf", "")
self.create_call_voila(other_args, "vsurf", "")

@log_start_end(log=logger)
def call_chains(self, other_args: List[str]):
"""Process chains command"""
create_call_voila(other_args, "chains", "")
self.create_call_voila(other_args, "chains", "")

@log_start_end(log=logger)
def call_shortdata(self, other_args: List[str]):
"""Process shortdata command"""
create_call_voila(other_args, "shortdata", "")
self.create_call_voila(other_args, "shortdata", "")

@log_start_end(log=logger)
def call_crypto(self, other_args: List[str]):
"""Process crypto command"""
create_call_voila(other_args, "crypto", "")
self.create_call_voila(other_args, "crypto", "")

@log_start_end(log=logger)
def call_futures(self, other_args: List[str]):
"""Process futures command"""
create_call_voila(other_args, "futures", "")
self.create_call_voila(other_args, "futures", "")

@log_start_end(log=logger)
def call_forecast(self, other_args: List[str]):
"""Process forecast command"""
create_call_voila(other_args, "forecast", "")
self.create_call_voila(other_args, "forecast", "")

@log_start_end(log=logger)
def call_forecasting(self, other_args: List[str]):
"""Process forecasting command"""
create_call_streamlit(other_args, "forecast")


def create_call_voila(other_args: List[str], name: str, filename: str = None) -> None:
filename = filename if filename else name

parser = argparse.ArgumentParser(
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
prog=name,
description=f"""Shows {name} dashboard""",
)
parser.add_argument(
"-j",
"--jupyter",
action="store_true",
default=False,
dest="jupyter",
help="Shows dashboard in jupyter-lab.",
)
parser.add_argument(
"-n",
"--no-input",
action="store_true",
default=False,
dest="input",
help="Skips confirmation to run server.",
)
parser.add_argument(
"-d",
"--dark",
action="store_true",
default=False,
dest="dark",
help="Whether to show voila in dark mode",
)
ns_parser = parse_simple_args(parser, other_args)

if ns_parser:
cmd = "jupyter-lab" if ns_parser.jupyter else "voila"
base_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "voila")
file = os.path.join(base_path, f"{filename}.ipynb")
if not ns_parser.input:
console.print(
f"Warning: opens a port on your computer to run a {cmd} server."
self.create_call_streamlit(other_args, "forecast")

@classmethod
def create_call_voila(
cls, other_args: List[str], name: str, filename: str = None
) -> None:
filename = filename if filename else name

parser = argparse.ArgumentParser(
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
prog=name,
description=f"""Shows {name} dashboard""",
)
parser.add_argument(
"-j",
"--jupyter",
action="store_true",
default=False,
dest="jupyter",
help="Shows dashboard in jupyter-lab.",
)
parser.add_argument(
"-n",
"--no-input",
action="store_true",
default=False,
dest="input",
help="Skips confirmation to run server.",
)
parser.add_argument(
"-d",
"--dark",
action="store_true",
default=False,
dest="dark",
help="Whether to show voila in dark mode",
)
ns_parser = cls.parse_simple_args(parser, other_args)

if ns_parser:
cmd = "jupyter-lab" if ns_parser.jupyter else "voila"
base_path = os.path.join(
os.path.abspath(os.path.dirname(__file__)), "voila"
)
response = input("Would you like us to run the server for you [yn]? ")
args = ""
if ns_parser.dark and not ns_parser.jupyter:
args += "--theme=dark"
if ns_parser.input or response.lower() == "y":
cfg.LOGGING_SUPPRESS = True
subprocess.Popen(
f"{cmd} {file} {args}",
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True, # nosec
file = os.path.join(base_path, f"{filename}.ipynb")
if not ns_parser.input:
console.print(
f"Warning: opens a port on your computer to run a {cmd} server."
)
response = input("Would you like us to run the server for you [yn]? ")
args = ""
if ns_parser.dark and not ns_parser.jupyter:
args += "--theme=dark"
if ns_parser.input or response.lower() == "y":
cfg.LOGGING_SUPPRESS = True
subprocess.Popen(
f"{cmd} {file} {args}",
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True, # nosec
)
cfg.LOGGING_SUPPRESS = False
else:
console.print(f"Type: {cmd} voila/{file}\ninto a terminal to run.")

@classmethod
def create_call_streamlit(
cls, other_args: List[str], name: str, filename: str = None
) -> None:
filename = filename if filename else name

parser = argparse.ArgumentParser(
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
prog=name,
description=f"""Shows streamlit {name} dashboard""",
)
parser.add_argument(
"-n",
"--no-input",
action="store_true",
default=False,
dest="input",
help="Skips confirmation to run server.",
)
ns_parser = cls.parse_simple_args(parser, other_args)

if ns_parser:
cmd = "streamlit run"
base_path = os.path.join(
os.path.abspath(os.path.dirname(__file__)), "stream"
)
cfg.LOGGING_SUPPRESS = False
else:
console.print(f"Type: {cmd} voila/{file}\ninto a terminal to run.")


def create_call_streamlit(
other_args: List[str], name: str, filename: str = None
) -> None:
filename = filename if filename else name

parser = argparse.ArgumentParser(
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
prog=name,
description=f"""Shows streamlit {name} dashboard""",
)
parser.add_argument(
"-n",
"--no-input",
action="store_true",
default=False,
dest="input",
help="Skips confirmation to run server.",
)
ns_parser = parse_simple_args(parser, other_args)

if ns_parser:
cmd = "streamlit run"
base_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "stream")
file = os.path.join(base_path, f"{filename}.py")
if not ns_parser.input:
console.print(
f"Warning: opens a port on your computer to run a {cmd} server."
)
response = input("Would you like us to run the server for you [yn]? ")
args = ""
if ns_parser.input or response.lower() == "y":
subprocess.Popen(
f"{cmd} {file} {args}",
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True,
)
else:
console.print(f"Type: {cmd} stream/{file}\ninto a terminal to run.")
file = os.path.join(base_path, f"{filename}.py")
if not ns_parser.input:
console.print(
f"Warning: opens a port on your computer to run a {cmd} server."
)
response = input("Would you like us to run the server for you [yn]? ")
args = ""
if ns_parser.input or response.lower() == "y":
subprocess.Popen(
f"{cmd} {file} {args}",
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True,
)
else:
console.print(f"Type: {cmd} stream/{file}\ninto a terminal to run.")
41 changes: 0 additions & 41 deletions openbb_terminal/helper_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,47 +966,6 @@ def patch_pandas_text_adjustment():
pandas.io.formats.format.TextAdjustment.adjoin = text_adjustment_adjoin


def parse_simple_args(parser: argparse.ArgumentParser, other_args: List[str]):
"""Parse list of arguments into the supplied parser.

Parameters
----------
parser: argparse.ArgumentParser
Parser with predefined arguments
other_args: List[str]
List of arguments to parse

Returns
-------
ns_parser:
Namespace with parsed arguments
"""
parser.add_argument(
"-h", "--help", action="store_true", help="show this help message"
)

if obbff.USE_CLEAR_AFTER_CMD:
system_clear()

try:
(ns_parser, l_unknown_args) = parser.parse_known_args(other_args)
except SystemExit:
# In case the command has required argument that isn't specified
console.print("\n")
return None

if ns_parser.help:
txt_help = parser.format_help()
console.print(f"[help]{txt_help}[/help]")
return None

if l_unknown_args:
console.print(f"The following args couldn't be interpreted: {l_unknown_args}")
console.print("\n")

return ns_parser


def lambda_financials_colored_values(val: str) -> str:
"""Add a color to a value."""
if val == "N/A" or str(val) == "nan":
Expand Down
Loading