From 2536c727f78f08f404b3ba1fe46386308ecd6156 Mon Sep 17 00:00:00 2001 From: shatakshiiii Date: Mon, 27 May 2024 13:47:11 +0530 Subject: [PATCH] Address ruff RUF --- pyproject.toml | 1 - src/ansible_navigator/actions/collections.py | 9 ++++++--- src/ansible_navigator/actions/config.py | 2 +- src/ansible_navigator/actions/doc.py | 2 +- src/ansible_navigator/actions/images.py | 2 +- src/ansible_navigator/actions/inventory.py | 6 +++--- src/ansible_navigator/actions/lint.py | 2 +- src/ansible_navigator/actions/run.py | 8 +++++--- src/ansible_navigator/actions/template.py | 2 +- src/ansible_navigator/data/catalog_collections.py | 2 +- src/ansible_navigator/data/image_introspect.py | 2 +- src/ansible_navigator/ui_framework/form.py | 4 ++-- src/ansible_navigator/ui_framework/menu_builder.py | 2 +- src/ansible_navigator/ui_framework/ui.py | 2 +- tests/integration/actions/doc/test_stdout_subprocess.py | 4 ++-- .../settings_from_cli/test_json_schema_errors.py | 2 +- tests/integration/test_execution_environment.py | 2 +- tests/integration/test_execution_environment_image.py | 2 +- tests/integration/test_pass_environment_variable.py | 2 +- tests/integration/test_set_environment_variable.py | 2 +- tests/integration/test_stdout_exit_codes.py | 2 +- tests/unit/test_circular_imports.py | 2 +- 22 files changed, 34 insertions(+), 30 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2fd2f8910..b592c0b24 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -303,7 +303,6 @@ ignore = [ 'PTH118', # `os.path.join()` should be replaced by `Path` with `/` operator 'PTH120', # `os.path.dirname()` should be replaced by `Path.parent` 'RET505', # Unnecessary `else` after `return` statement - 'RUF005', # [*] Consider `[self._name, *shlex.split(self._interaction.action.match.groupdict()["params"] or "")]` instead of concatenation 'RUF012', # Mutable class attributes should be annotated with `typing.ClassVar` 'S108', # Probable insecure usage of temporary file or directory: "/tmp" 'T201' # `print` found diff --git a/src/ansible_navigator/actions/collections.py b/src/ansible_navigator/actions/collections.py index 722177ea0..8de7fcfe1 100644 --- a/src/ansible_navigator/actions/collections.py +++ b/src/ansible_navigator/actions/collections.py @@ -130,9 +130,12 @@ def run(self, interaction: Interaction, app: AppPublic) -> Interaction | None: ) interaction.ui.show_form(notification) - params = [self._name] + shlex.split( - self._interaction.action.match.groupdict()["params"] or "", - ) + params = [ + self._name, + *shlex.split( + self._interaction.action.match.groupdict()["params"] or "", + ), + ] args_updated = self._update_args(params=params, attach_cdc=True) if not args_updated: diff --git a/src/ansible_navigator/actions/config.py b/src/ansible_navigator/actions/config.py index 65ca59440..a2e67d5ed 100644 --- a/src/ansible_navigator/actions/config.py +++ b/src/ansible_navigator/actions/config.py @@ -117,7 +117,7 @@ def run(self, interaction: Interaction, app: AppPublic) -> Interaction | None: interaction.ui.show_form(notification) args_updated = self._update_args( - [self._name] + shlex.split(self._interaction.action.match.groupdict()["params"] or ""), + [self._name, *shlex.split(self._interaction.action.match.groupdict()["params"] or "")], ) if not args_updated: self._prepare_to_exit(interaction) diff --git a/src/ansible_navigator/actions/doc.py b/src/ansible_navigator/actions/doc.py index 76fea322d..1512312f5 100644 --- a/src/ansible_navigator/actions/doc.py +++ b/src/ansible_navigator/actions/doc.py @@ -92,7 +92,7 @@ def run(self, interaction: Interaction, app: AppPublic) -> Interaction | None: # Process the colon prompt and allow update args to identify missing entries if self._plugin_name is None: - args_updated = self._update_args([self._name] + shlex.split(colon_prompt or "")) + args_updated = self._update_args([self._name, *shlex.split(colon_prompt or "")]) if not args_updated: self._prepare_to_exit(interaction) return None diff --git a/src/ansible_navigator/actions/images.py b/src/ansible_navigator/actions/images.py index 1674e3116..1ebee4e45 100644 --- a/src/ansible_navigator/actions/images.py +++ b/src/ansible_navigator/actions/images.py @@ -210,7 +210,7 @@ def run(self, interaction: Interaction, app: AppPublic) -> Interaction | None: self._prepare_to_run(app, interaction) args_updated = self._update_args( - [self._name] + shlex.split(self._interaction.action.match.groupdict()["params"] or ""), + [self._name, *shlex.split(self._interaction.action.match.groupdict()["params"] or "")], ) if not args_updated: self._prepare_to_exit(interaction) diff --git a/src/ansible_navigator/actions/inventory.py b/src/ansible_navigator/actions/inventory.py index f2d54bc27..0f84c9213 100644 --- a/src/ansible_navigator/actions/inventory.py +++ b/src/ansible_navigator/actions/inventory.py @@ -189,7 +189,7 @@ def run(self, interaction: Interaction, app: AppPublic) -> Interaction | None: self._prepare_to_run(app, interaction) args_updated = self._update_args( - [self._name] + shlex.split(self._interaction.action.match.groupdict()["params"] or ""), + [self._name, *shlex.split(self._interaction.action.match.groupdict()["params"] or "")], ) if not args_updated: self._prepare_to_exit(interaction) @@ -392,7 +392,7 @@ def _build_host_content(self) -> Step: step_type="content", value=values, index=self.steps.current.index, - columns=["__name"] + self._show_columns, + columns=["__name", *self._show_columns], show_func=self._refresh, ) except KeyError: @@ -414,7 +414,7 @@ def _build_host_menu(self) -> Step: for host in self._host_vars.values(): host["__type"] = "host" menu.append(MenuEntry(host)) - columns = ["inventory_hostname"] + self._show_columns + columns = ["inventory_hostname", *self._show_columns] return Step( columns=columns, name="host_menu", diff --git a/src/ansible_navigator/actions/lint.py b/src/ansible_navigator/actions/lint.py index d159f6f0e..cea8ede35 100644 --- a/src/ansible_navigator/actions/lint.py +++ b/src/ansible_navigator/actions/lint.py @@ -317,7 +317,7 @@ def run(self, interaction: Interaction, app: AppPublic) -> Interaction | None: self._prepare_to_run(app, interaction) updated = self._update_args( - ["lint"] + shlex.split(interaction.action.match.groupdict()["params"] or ""), + ["lint", *shlex.split(interaction.action.match.groupdict()["params"] or "")], ) if not updated: diff --git a/src/ansible_navigator/actions/run.py b/src/ansible_navigator/actions/run.py index c200e012f..4869fc561 100644 --- a/src/ansible_navigator/actions/run.py +++ b/src/ansible_navigator/actions/run.py @@ -361,7 +361,7 @@ def _init_run(self) -> bool: # Ensure the playbook and inventory are valid args_updated = self._update_args( - ["run"] + shlex.split(self._interaction.action.match.groupdict()["params_run"] or ""), + ["run", *shlex.split(self._interaction.action.match.groupdict()["params_run"] or "")], ) if not args_updated: return False @@ -403,8 +403,10 @@ def _init_replay(self) -> bool: if self.mode == "interactive": args_updated = self._update_args( - ["replay"] - + shlex.split(self._interaction.action.match.groupdict()["params_replay"] or ""), + [ + "replay", + *shlex.split(self._interaction.action.match.groupdict()["params_replay"] or ""), + ], ) if not args_updated: return False diff --git a/src/ansible_navigator/actions/template.py b/src/ansible_navigator/actions/template.py index cdaedc849..3da2d97ac 100644 --- a/src/ansible_navigator/actions/template.py +++ b/src/ansible_navigator/actions/template.py @@ -84,7 +84,7 @@ def run(self, interaction: Interaction, app: AppPublic) -> Interaction | None: template_vars=template_vars, ) if errors: - msgs = ["Errors encountered while templating input"] + errors + msgs = ["Errors encountered while templating input", *errors] msgs.extend(type_msgs) interaction.ui.show_form(warning_notification(msgs)) return None diff --git a/src/ansible_navigator/data/catalog_collections.py b/src/ansible_navigator/data/catalog_collections.py index c15d87a0f..307db5482 100644 --- a/src/ansible_navigator/data/catalog_collections.py +++ b/src/ansible_navigator/data/catalog_collections.py @@ -473,7 +473,7 @@ def parse_args() -> tuple[argparse.Namespace, list[Path]]: parsed_args = parser.parse_args() adjacent = vars(parsed_args).get("adjacent") - directories = [adjacent] + parsed_args.dirs if adjacent else parsed_args.dirs + directories = [adjacent, *parsed_args.dirs] if adjacent else parsed_args.dirs directories.extend(reversed(sys.path)) diff --git a/src/ansible_navigator/data/image_introspect.py b/src/ansible_navigator/data/image_introspect.py index 692cee056..e5eca0087 100644 --- a/src/ansible_navigator/data/image_introspect.py +++ b/src/ansible_navigator/data/image_introspect.py @@ -68,7 +68,7 @@ def worker(pending_queue: Queue[Any], completed_queue: Queue[Any]) -> None: try: command.parse(command) except Exception as exc: # noqa: BLE001 - command.errors = command.errors + [str(exc)] + command.errors = [*command.errors, str(exc)] completed_queue.put(command) diff --git a/src/ansible_navigator/ui_framework/form.py b/src/ansible_navigator/ui_framework/form.py index 55b6453dd..e8b82a979 100644 --- a/src/ansible_navigator/ui_framework/form.py +++ b/src/ansible_navigator/ui_framework/form.py @@ -206,7 +206,7 @@ def _generate_form(self) -> tuple[tuple[int, CursesLine], ...]: elif isinstance(form_field, FieldText): prompt = self._generate_prompt(form_field) - line = CursesLine(tuple(prompt + [self._generate_field_text(form_field)])) + line = CursesLine(tuple([*prompt, self._generate_field_text(form_field)])) lines.append((self._line_number, line)) self._line_number += 1 @@ -216,7 +216,7 @@ def _generate_form(self) -> tuple[tuple[int, CursesLine], ...]: # although option_lines[0] is a CursesLine, only it's first line part is needed # because the prompt needs to be prepended to it first_option_line_part = option_lines[0][0] - line = CursesLine(tuple(prompt + [first_option_line_part])) + line = CursesLine(tuple([*prompt, first_option_line_part])) lines.append((self._line_number, line)) self._line_number += 1 diff --git a/src/ansible_navigator/ui_framework/menu_builder.py b/src/ansible_navigator/ui_framework/menu_builder.py index 588e5c204..1a4a2e703 100644 --- a/src/ansible_navigator/ui_framework/menu_builder.py +++ b/src/ansible_navigator/ui_framework/menu_builder.py @@ -86,7 +86,7 @@ def _menu( lines = [[str(dicts[idx].get(c)) for c in cols] for idx in indices] column_widths = [ max(len(str(v)) for v in c) - for c in zip(*lines + [[re.sub("^__", "", col) for col in cols]], strict=False) + for c in zip([*lines, [re.sub("^__", "", col) for col in cols]], strict=False) ] # add a space column_widths = [c + 1 for c in column_widths] diff --git a/src/ansible_navigator/ui_framework/ui.py b/src/ansible_navigator/ui_framework/ui.py index 7d96af1a8..baf48e6c6 100644 --- a/src/ansible_navigator/ui_framework/ui.py +++ b/src/ansible_navigator/ui_framework/ui.py @@ -535,7 +535,7 @@ def _template_match_action( type_msgs.append("[HINT] Use 'this' to reference it (e.g. {{ this[0] }}") errors, entry = templar(entry, template_vars) if errors: - msgs = ["Errors encountered while templating input"] + errors + msgs = ["Errors encountered while templating input", *errors] msgs.extend(type_msgs) self._show_form(warning_notification(msgs)) return None, None diff --git a/tests/integration/actions/doc/test_stdout_subprocess.py b/tests/integration/actions/doc/test_stdout_subprocess.py index 9db6c3f66..0faa72536 100644 --- a/tests/integration/actions/doc/test_stdout_subprocess.py +++ b/tests/integration/actions/doc/test_stdout_subprocess.py @@ -50,7 +50,7 @@ def command(self) -> tuple[str, ...]: :returns: The constructed command """ - return ("ansible-navigator", self.subcommand) + self.params + return ("ansible-navigator", *self.subcommand, *self.params) # Intentionally not using parametrize so the behavior can be documented @@ -125,7 +125,7 @@ def test( monkeypatch.setenv("PAGER", "cat") monkeypatch.setenv("NO_COLOR", "true") command = shlex_join( - data.command + ("--lf", log_file, "--ee", str(exec_env), "--set-env", "PAGER=cat"), + [*data.command, "--lf", log_file, "--ee", str(exec_env), "--set-env", "PAGER=cat"], ) stdout, _stderr, _exit_code = cmd_in_tty(cmd=command) diff --git a/tests/integration/settings_from_cli/test_json_schema_errors.py b/tests/integration/settings_from_cli/test_json_schema_errors.py index 739e0217f..da3175f00 100644 --- a/tests/integration/settings_from_cli/test_json_schema_errors.py +++ b/tests/integration/settings_from_cli/test_json_schema_errors.py @@ -84,7 +84,7 @@ def test(data: Scenario, subtests: Any, tmp_path: Path) -> None: venv_prefix = f"source {venv} && " log_file = tmp_path / "log.txt" - command = list(data.command) + ["--lf", str(log_file)] + command = [*list(data.command), "--lf", str(log_file)] bash_wrapped = f"/bin/bash -c '{venv_prefix!s}{shlex.join(split_command=command)}'" # Some os.environ are required in order to make it work, likely HOME and PATH at least. diff --git a/tests/integration/test_execution_environment.py b/tests/integration/test_execution_environment.py index e0be32ba6..baf283dfa 100644 --- a/tests/integration/test_execution_environment.py +++ b/tests/integration/test_execution_environment.py @@ -79,7 +79,7 @@ def run_test( assert cfg_path.exists() - params = shlex.split(cli_entry) + ["--pp", "never"] + params = [*shlex.split(cli_entry), "--pp", "never"] monkeypatch.setattr("sys.argv", params) monkeypatch.setenv("ANSIBLE_NAVIGATOR_CONFIG", str(cfg_path)) diff --git a/tests/integration/test_execution_environment_image.py b/tests/integration/test_execution_environment_image.py index 0af390c2f..24a1e2faf 100644 --- a/tests/integration/test_execution_environment_image.py +++ b/tests/integration/test_execution_environment_image.py @@ -91,7 +91,7 @@ def run_test( assert cfg_path.exists() - params = shlex.split(cli_entry) + ["--pp", "never"] + params = [*shlex.split(cli_entry), "--pp", "never"] monkeypatch.setattr("sys.argv", params) monkeypatch.setenv("ANSIBLE_NAVIGATOR_CONFIG", str(cfg_path)) diff --git a/tests/integration/test_pass_environment_variable.py b/tests/integration/test_pass_environment_variable.py index cfdb34286..d52e45f8f 100644 --- a/tests/integration/test_pass_environment_variable.py +++ b/tests/integration/test_pass_environment_variable.py @@ -95,7 +95,7 @@ def run_test( assert cfg_path.exists() - params = shlex.split(cli_entry) + ["--pp", "never"] + params = [*shlex.split(cli_entry), "--pp", "never"] monkeypatch.setattr("sys.argv", params) monkeypatch.setenv("ANSIBLE_NAVIGATOR_CONFIG", str(cfg_path)) diff --git a/tests/integration/test_set_environment_variable.py b/tests/integration/test_set_environment_variable.py index 88e685a86..ffef7025c 100644 --- a/tests/integration/test_set_environment_variable.py +++ b/tests/integration/test_set_environment_variable.py @@ -95,7 +95,7 @@ def run_test( assert cfg_path.exists() - params = shlex.split(cli_entry) + ["--pp", "never"] + params = [*shlex.split(cli_entry), "--pp", "never"] monkeypatch.setattr("sys.argv", params) monkeypatch.setenv("ANSIBLE_NAVIGATOR_CONFIG", str(cfg_path)) diff --git a/tests/integration/test_stdout_exit_codes.py b/tests/integration/test_stdout_exit_codes.py index 45be2542f..145d156ff 100644 --- a/tests/integration/test_stdout_exit_codes.py +++ b/tests/integration/test_stdout_exit_codes.py @@ -195,7 +195,7 @@ def command(self) -> list[str]: :returns: The command """ - return ["ansible-navigator", self.subcommand] + self.params + ["--mode", self.mode] + return ["ansible-navigator", self.subcommand, *self.params, "--mode", self.mode] # Intentionally not using parametrize so the behavior can be documented diff --git a/tests/unit/test_circular_imports.py b/tests/unit/test_circular_imports.py index f8cbe36c9..235185cba 100644 --- a/tests/unit/test_circular_imports.py +++ b/tests/unit/test_circular_imports.py @@ -66,7 +66,7 @@ def _discover_path_importables( continue rel_pt = pkg_dir_path.relative_to(pkg_pth) - pkg_pref = ".".join((pkg_name,) + rel_pt.parts) + pkg_pref = ".".join((pkg_name,) + rel_pt.parts) # noqa: RUF005 yield from ( pkg_path for _, pkg_path, _ in pkgutil.walk_packages(