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

Remove RUF from ruff ignores #3346

Merged
merged 3 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ ignore = [
"PTH",
"PLR",
"PLW",
"RUF",
"S",
"SLF",
"T",
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/_mockings.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _write_module_stub(


# pylint: disable=too-many-branches
def _perform_mockings() -> None: # noqa: C901
def _perform_mockings() -> None:
"""Mock modules and roles."""
for role_name in options.mock_roles:
if re.match(r"\w+\.\w+\.\w+$", role_name):
Expand All @@ -74,7 +74,7 @@ def _perform_mockings() -> None: # noqa: C901
_make_module_stub(module_name)


def _perform_mockings_cleanup() -> None: # noqa: C901
def _perform_mockings_cleanup() -> None:
"""Clean up mocked modules and roles."""
for role_name in options.mock_roles:
if re.match(r"\w+\.\w+\.\w+$", role_name):
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Options: # pylint: disable=too-many-instance-attributes,too-few-public-me
cache_dir: str | None = None
colored: bool = True
configured: bool = False
cwd: Path = Path(".")
cwd: Path = Path(".") # noqa: RUF009
display_relative_path: bool = True
exclude_paths: list[str] = field(default_factory=list)
format: str = "brief"
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def transform(self, match, lintable, data):


# pylint: disable=too-many-nested-blocks
def load_plugins( # noqa: max-complexity: 11
def load_plugins( # : max-complexity: 11
dirs: list[str],
) -> Iterator[AnsibleLintRule]:
"""Yield a rule class."""
Expand Down Expand Up @@ -437,7 +437,7 @@ def extend(self, more: list[AnsibleLintRule]) -> None:
"""Combine rules."""
self.rules.extend(more)

def run( # noqa: max-complexity: 12
def run( # : max-complexity: 12
self,
file: Lintable,
tags: set[str] | None = None,
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/command_instead_of_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def matchtask(
return False


if "pytest" in sys.modules: # noqa: C901
if "pytest" in sys.modules:
import pytest

from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/fqcn.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
if TYPE_CHECKING:
from ruamel.yaml.comments import CommentedMap, CommentedSeq

from ansiblelint.file_utils import Lintable # noqa: F811
from ansiblelint.file_utils import Lintable

_logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def _coerce(other: object) -> Version:
raise NotImplementedError(f"Unable to coerce object type {type(other)} to Version")


if "pytest" in sys.modules: # noqa: C901
if "pytest" in sys.modules:
import pytest

from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def blacken(text: str) -> str:
).rstrip("\n")


if "pytest" in sys.modules: # noqa: C901
if "pytest" in sys.modules:
import pytest

from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/rules/name.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
if TYPE_CHECKING:
from ruamel.yaml.comments import CommentedMap, CommentedSeq

from ansiblelint.file_utils import Lintable # noqa: F811
from ansiblelint.file_utils import Lintable


class NameRule(AnsibleLintRule, TransformMixin):
Expand Down Expand Up @@ -172,7 +172,7 @@ def transform(
match.fixed = True


if "pytest" in sys.modules: # noqa: C901
if "pytest" in sys.modules:
from ansiblelint.config import options
from ansiblelint.file_utils import Lintable # noqa: F811
from ansiblelint.rules import RulesCollection
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/no_free_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def matchtask(
return results


if "pytest" in sys.modules: # noqa: C901
if "pytest" in sys.modules:
import pytest

from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/no_log_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def matchtask(
)


if "pytest" in sys.modules: # noqa: C901
if "pytest" in sys.modules:
import pytest

from ansiblelint.testing import RunFromText # pylint: disable=ungrouped-imports
Expand Down
3 changes: 2 additions & 1 deletion src/ansiblelint/rules/only_builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def matchtask(
allowed_collections = [
"ansible.builtin",
"ansible.legacy",
] + options.only_builtins_allow_collections
*options.only_builtins_allow_collections,
]
allowed_modules = builtins + options.only_builtins_allow_modules

is_allowed = (
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/playbook_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def matchyaml(self, file: Lintable) -> list[MatchError]:
return result


if "pytest" in sys.modules: # noqa: C901
if "pytest" in sys.modules:
import pytest

from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/risky_file_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def matchtask(
return mode is None


if "pytest" in sys.modules: # noqa: C901
if "pytest" in sys.modules:
import pytest

from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/risky_shell_pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def matchtask(
)


if "pytest" in sys.modules: # noqa: C901
if "pytest" in sys.modules:
import pytest

from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/skip_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (c) 20192020, Ansible by Red Hat
# (c) 2019-2020, Ansible by Red Hat
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
# https://github.com/PyCQA/pylint/issues/3240
# pylint: disable=unsubscriptable-object
CompletedProcess = subprocess.CompletedProcess[Any]
from ansiblelint.errors import MatchError # noqa: E402
from ansiblelint.errors import MatchError
else:
CompletedProcess = subprocess.CompletedProcess

# pylint: disable=wrong-import-position
from ansiblelint.runner import Runner # noqa: E402
from ansiblelint.runner import Runner


class RunFromText:
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/testing/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import pytest
from _pytest.fixtures import SubRequest

from ansiblelint.config import Options, options # noqa: F401
from ansiblelint.config import Options, options
from ansiblelint.constants import DEFAULT_RULESDIR
from ansiblelint.rules import RulesCollection
from ansiblelint.testing import RunFromText
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def normalize_task_v2(task: dict[str, Any]) -> dict[str, Any]:
_extract_ansible_parsed_keys_from_task(
result,
task,
ansible_parsed_keys + (action,),
(*ansible_parsed_keys, action),
)

if not isinstance(action, str):
Expand Down
8 changes: 4 additions & 4 deletions src/ansiblelint/yaml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def _nested_items_path(
if isinstance(value, (dict, list)):
yield from _nested_items_path(
data_collection=value,
parent_path=parent_path + [key],
parent_path=[*parent_path, key],
)


Expand Down Expand Up @@ -423,7 +423,7 @@ def _get_path_to_task_in_nested_tasks_block(
last_lineno_in_block, # 1-based
)
if subtask_path:
return [task_key] + list(subtask_path)
return [task_key, *list(subtask_path)]
# line is not part of this nested tasks block
return []

Expand Down Expand Up @@ -623,7 +623,7 @@ def add_octothorpe_protection(string: str) -> str:
"""Modify strings to protect "#" from full-line-comment post-processing."""
try:
if "#" in string:
# is \uFF03 (fullwidth number sign)
# # is \uFF03 (fullwidth number sign)
# ﹟ is \uFE5F (small number sign)
string = string.replace("#", "\uFF03#\uFE5F")
# this is safe even if this sequence is present
Expand All @@ -638,7 +638,7 @@ def drop_octothorpe_protection(string: str) -> str:
"""Remove string protection of "#" after full-line-comment post-processing."""
try:
if "\uFF03#\uFE5F" in string:
# is \uFF03 (fullwidth number sign)
# # is \uFF03 (fullwidth number sign)
# ﹟ is \uFE5F (small number sign)
string = string.replace("\uFF03#\uFE5F", "#")
except (ValueError, TypeError):
Expand Down
30 changes: 18 additions & 12 deletions test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,33 +113,38 @@ def test_ensure_write_cli_does_not_consume_lintables(

def test_config_can_be_overridden(base_arguments: list[str]) -> None:
"""Check that config can be overridden from CLI."""
no_override = cli.get_config(base_arguments + ["-t", "bad_tag"])
no_override = cli.get_config([*base_arguments, "-t", "bad_tag"])

overridden = cli.get_config(
base_arguments + ["-t", "bad_tag", "-c", "test/fixtures/tags.yml"],
[*base_arguments, "-t", "bad_tag", "-c", "test/fixtures/tags.yml"],
)

assert no_override.tags + ["skip_ansible_lint"] == overridden.tags
assert [*no_override.tags, "skip_ansible_lint"] == overridden.tags


def test_different_config_file(base_arguments: list[str]) -> None:
"""Ensures an alternate config_file can be used."""
diff_config = cli.get_config(
base_arguments + ["-c", "test/fixtures/ansible-config.yml"],
[*base_arguments, "-c", "test/fixtures/ansible-config.yml"],
)
no_config = cli.get_config(base_arguments + ["-v"])
no_config = cli.get_config([*base_arguments, "-v"])

assert diff_config.verbosity == no_config.verbosity


def test_expand_path_user_and_vars_config_file(base_arguments: list[str]) -> None:
"""Ensure user and vars are expanded when specified as exclude_paths."""
config1 = cli.get_config(
base_arguments + ["-c", "test/fixtures/exclude-paths-with-expands.yml"],
[*base_arguments, "-c", "test/fixtures/exclude-paths-with-expands.yml"],
)
config2 = cli.get_config(
base_arguments
+ ["--exclude", "~/.ansible/roles", "--exclude", "$HOME/.ansible/roles"],
[
*base_arguments,
"--exclude",
"~/.ansible/roles",
"--exclude",
"$HOME/.ansible/roles",
],
)

assert str(config1.exclude_paths[0]) == os.path.expanduser("~/.ansible/roles")
Expand Down Expand Up @@ -171,7 +176,8 @@ def test_path_from_cli_depend_on_cwd(
) -> None:
"""Check that CLI-provided paths are relative to CWD."""
# Issue 572
arguments = base_arguments + [
arguments = [
*base_arguments,
"--exclude",
"test/fixtures/config-with-relative-path.yml",
]
Expand All @@ -196,13 +202,13 @@ def test_path_from_cli_depend_on_cwd(
def test_config_failure(base_arguments: list[str], config_file: str) -> None:
"""Ensures specific config files produce error code 3."""
with pytest.raises(SystemExit, match="^3$"):
cli.get_config(base_arguments + ["-c", config_file])
cli.get_config([*base_arguments, "-c", config_file])


def test_extra_vars_loaded(base_arguments: list[str]) -> None:
"""Ensure ``extra_vars`` option is loaded from file config."""
config = cli.get_config(
base_arguments + ["-c", "test/fixtures/config-with-extra-vars.yml"],
[*base_arguments, "-c", "test/fixtures/config-with-extra-vars.yml"],
)

assert config.extra_vars == {"foo": "bar", "knights_favorite_word": "NI"}
Expand All @@ -214,5 +220,5 @@ def test_extra_vars_loaded(base_arguments: list[str]) -> None:
)
def test_config_dev_null(base_arguments: list[str], config_file: str) -> None:
"""Ensures specific config files produce error code 3."""
cfg = cli.get_config(base_arguments + ["-c", config_file])
cfg = cli.get_config([*base_arguments, "-c", config_file])
assert cfg.config_file == "/dev/null"