[BugFix] Revamp the usage of list syntax on routines (#6450)

* using list syntax on routines

* black

* ruff

* simplify

* black
This commit is contained in:
Henrique Joaquim
2024-05-22 12:46:19 +01:00
committed by GitHub
parent 8baf4d74b2
commit f91791dbf9
7 changed files with 30 additions and 21 deletions

View File

@@ -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,

View File

@@ -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

View File

@@ -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)

View File

@@ -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()

View File

@@ -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

View File

@@ -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"

2
ruff.toml vendored
View File

@@ -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