summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrique Joaquim <henriquecjoaquim@gmail.com>2024-05-22 12:46:19 +0100
committerGitHub <noreply@github.com>2024-05-22 11:46:19 +0000
commitf91791dbf94a7066628e0b43b0e7a751c46b8de5 (patch)
treef50d35d1aaf7bc89d033de1f1edc35db73c08fc0
parent8baf4d74b23fdeb3e6bfcaa8d648c3a3a9deb6b6 (diff)
[BugFix] Revamp the usage of list syntax on routines (#6450)
* using list syntax on routines * black * ruff * simplify * black
-rw-r--r--cli/openbb_cli/argparse_translator/argparse_class_processor.py1
-rw-r--r--cli/openbb_cli/argparse_translator/argparse_translator.py3
-rw-r--r--cli/openbb_cli/controllers/base_controller.py21
-rw-r--r--cli/openbb_cli/controllers/base_platform_controller.py1
-rw-r--r--cli/openbb_cli/controllers/cli_controller.py22
-rw-r--r--cli/tests/test_controllers_settings_controller.py1
-rw-r--r--ruff.toml2
7 files changed, 30 insertions, 21 deletions
diff --git a/cli/openbb_cli/argparse_translator/argparse_class_processor.py b/cli/openbb_cli/argparse_translator/argparse_class_processor.py
index 6fff39aa18e..d7ddcdafcd2 100644
--- a/cli/openbb_cli/argparse_translator/argparse_class_processor.py
+++ b/cli/openbb_cli/argparse_translator/argparse_class_processor.py
@@ -92,7 +92,6 @@ class ArgparseClassProcessor:
if name.startswith("__") or name.startswith("_"):
continue
if inspect.ismethod(member):
-
class_name = cls._get_class_name(target)
methods[f"{class_name}_{name}"] = ArgparseTranslator(
func=member,
diff --git a/cli/openbb_cli/argparse_translator/argparse_translator.py b/cli/openbb_cli/argparse_translator/argparse_translator.py
index 7931b22304f..605fbe6b41f 100644
--- a/cli/openbb_cli/argparse_translator/argparse_translator.py
+++ b/cli/openbb_cli/argparse_translator/argparse_translator.py
@@ -33,7 +33,6 @@ class ArgparseActionType(Enum):
class CustomArgument(BaseModel):
-
name: str
type: Optional[Any]
dest: str
@@ -62,7 +61,6 @@ class CustomArgument(BaseModel):
# override
def model_dump(self, **kwargs):
-
res = super().model_dump(**kwargs)
# Check if choices is present and if it's an empty tuple remove it
@@ -152,7 +150,6 @@ class ReferenceToCustomArgumentsProcessor:
def build_custom_groups(self):
"""Build the custom groups from the reference."""
for route, v in self.reference.items():
-
for provider, args in v["parameters"].items():
if provider == "standard":
continue
diff --git a/cli/openbb_cli/controllers/base_controller.py b/cli/openbb_cli/controllers/base_controller.py
index b1952da5fcf..206e8a735bd 100644
--- a/cli/openbb_cli/controllers/base_controller.py
+++ b/cli/openbb_cli/controllers/base_controller.py
@@ -799,11 +799,22 @@ class BaseController(metaclass=ABCMeta):
return None
try:
- # If the user uses a comma separated list of arguments, split them
- for index, arg in enumerate(other_args):
- if "," in arg:
- parts = arg.split(",")
- other_args[index : index + 1] = parts
+ # Determine the index of the routine arguments
+ routine_args_index = next(
+ (
+ i + 1
+ for i, arg in enumerate(other_args)
+ if arg in ("-i", "--input")
+ and "routine_args" in [action.dest for action in parser._actions]
+ ),
+ -1,
+ )
+ # Split comma-separated arguments, except for the argument at routine_args_index
+ other_args = [
+ part
+ for index, arg in enumerate(other_args)
+ for part in (arg.split(",") if index != routine_args_index else [arg])
+ ]
(ns_parser, l_unknown_args) = parser.parse_known_args(other_args)
diff --git a/cli/openbb_cli/controllers/base_platform_controller.py b/cli/openbb_cli/controllers/base_platform_controller.py
index df67c708e14..ed8f0087516 100644
--- a/cli/openbb_cli/controllers/base_platform_controller.py
+++ b/cli/openbb_cli/controllers/base_platform_controller.py
@@ -158,7 +158,6 @@ class PlatformController(BaseController):
title = f"{self.PATH}{translator.func.__name__}"
if obbject:
-
if isinstance(obbject, OBBject):
if session.max_obbjects_exceeded() and obbject.results:
session.obbject_registry.remove()
diff --git a/cli/openbb_cli/controllers/cli_controller.py b/cli/openbb_cli/controllers/cli_controller.py
index 49eaf92da33..ccd54ae9114 100644
--- a/cli/openbb_cli/controllers/cli_controller.py
+++ b/cli/openbb_cli/controllers/cli_controller.py
@@ -355,7 +355,7 @@ class CLIController(BaseController):
"--input",
help="Select multiple inputs to be replaced in the routine and separated by commas. E.g. GME,AMC,BTC-USD",
dest="routine_args",
- type=lambda s: [str(item) for item in s.split(",")],
+ type=str,
)
parser.add_argument(
"-e",
@@ -431,17 +431,22 @@ class CLIController(BaseController):
with open(routine_path) as fp:
raw_lines = list(fp)
+ script_inputs = []
# Capture ARGV either as list if args separated by commas or as single value
- if ns_parser.routine_args:
- script_inputs = (
- ns_parser.routine_args
- if "," not in ns_parser.routine_args
- else ns_parser.routine_args.split(",")
+ if routine_args := ns_parser.routine_args:
+ pattern = r"\[(.*?)\]"
+ matches = re.findall(pattern, routine_args)
+
+ for match in matches:
+ routine_args = routine_args.replace(f"[{match}]", "")
+ script_inputs.append(match)
+
+ script_inputs.extend(
+ [val for val in routine_args.split(",") if val]
)
err, parsed_script = parse_openbb_script(
- raw_lines=raw_lines,
- script_inputs=script_inputs if ns_parser.routine_args else None,
+ raw_lines=raw_lines, script_inputs=script_inputs
)
# If there err output is not an empty string then it means there was an
@@ -546,7 +551,6 @@ def run_cli(jobs_cmds: Optional[List[str]] = None, test_mode=False):
t_controller.print_help()
while ret_code:
-
# There is a command in the queue
if t_controller.queue and len(t_controller.queue) > 0:
# If the command is quitting the menu we want to return in here
diff --git a/cli/tests/test_controllers_settings_controller.py b/cli/tests/test_controllers_settings_controller.py
index 43928139205..7540b3bea4f 100644
--- a/cli/tests/test_controllers_settings_controller.py
+++ b/cli/tests/test_controllers_settings_controller.py
@@ -11,7 +11,6 @@ from openbb_cli.controllers.settings_controller import SettingsController
@pytest.fixture
def mock_session():
with patch("openbb_cli.controllers.settings_controller.session") as mock:
-
mock.settings.USE_INTERACTIVE_DF = False
mock.settings.ALLOWED_NUMBER_OF_ROWS = 20
mock.settings.TIMEZONE = "UTC"
diff --git a/ruff.toml b/ruff.toml
index 385bdf9232c..cae9b8373d1 100644
--- a/ruff.toml
+++ b/ruff.toml
@@ -41,7 +41,7 @@ force-wrap-aliases = true
[lint.pylint]
max-args = 8
-max-branches = 25
+max-branches = 26
max-returns = 9
max-statements = 30