Skip to content

Commit

Permalink
Address ruff RUF
Browse files Browse the repository at this point in the history
  • Loading branch information
shatakshiiii committed May 30, 2024
1 parent d11d09b commit 85b064a
Show file tree
Hide file tree
Showing 22 changed files with 34 additions and 30 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ ignore = [
'PTH120', # `os.path.dirname()` should be replaced by `Path.parent`
'PTH122', # `os.path.splitext()` should be replaced by `Path.suffix`
'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`
'S101', # Use of `assert` detected
'S103', # `os.chmod` setting a permissive mask `0o777` on file or directory
Expand Down
9 changes: 6 additions & 3 deletions src/ansible_navigator/actions/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/ansible_navigator/actions/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/ansible_navigator/actions/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ansible_navigator/actions/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/ansible_navigator/actions/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/ansible_navigator/actions/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,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:
Expand Down
8 changes: 5 additions & 3 deletions src/ansible_navigator/actions/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ansible_navigator/actions/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ansible_navigator/data/catalog_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,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))

Expand Down
2 changes: 1 addition & 1 deletion src/ansible_navigator/data/image_introspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
4 changes: 2 additions & 2 deletions src/ansible_navigator/ui_framework/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

Expand Down
2 changes: 1 addition & 1 deletion src/ansible_navigator/ui_framework/menu_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/ansible_navigator/ui_framework/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/actions/doc/test_stdout_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_execution_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def run_test(

assert os.path.exists(cfg_path)

params = shlex.split(cli_entry) + ["--pp", "never"]
params = [*shlex.split(cli_entry), "--pp", "never"]

monkeypatch.setattr("sys.argv", params)
monkeypatch.setenv("ANSIBLE_NAVIGATOR_CONFIG", cfg_path)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_execution_environment_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def run_test(

assert os.path.exists(cfg_path)

params = shlex.split(cli_entry) + ["--pp", "never"]
params = [*shlex.split(cli_entry), "--pp", "never"]

monkeypatch.setattr("sys.argv", params)
monkeypatch.setenv("ANSIBLE_NAVIGATOR_CONFIG", cfg_path)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_pass_environment_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def run_test(

assert os.path.exists(cfg_path)

params = shlex.split(cli_entry) + ["--pp", "never"]
params = [*shlex.split(cli_entry), "--pp", "never"]

monkeypatch.setattr("sys.argv", params)
monkeypatch.setenv("ANSIBLE_NAVIGATOR_CONFIG", cfg_path)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_set_environment_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def run_test(

assert os.path.exists(cfg_path)

params = shlex.split(cli_entry) + ["--pp", "never"]
params = [*shlex.split(cli_entry), "--pp", "never"]

monkeypatch.setattr("sys.argv", params)
monkeypatch.setenv("ANSIBLE_NAVIGATOR_CONFIG", cfg_path)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_stdout_exit_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,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
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_circular_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 85b064a

Please sign in to comment.