Skip to content

Commit

Permalink
Update ruff to 0.8.0 (#4427)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Nov 26, 2024
1 parent c910fee commit 1b11890
Show file tree
Hide file tree
Showing 18 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ repos:
types: [file, yaml]
entry: yamllint --strict
- repo: https://github.com/pappasam/toml-sort
rev: v0.23.1
rev: v0.24.2
hooks:
- id: toml-sort-fix
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.3
rev: v0.8.0
hooks:
- id: ruff
args:
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def initialize_logger(level: int = 0) -> None:
_logger.debug("Logging initialized to level %s", logging_level)


def initialize_options(arguments: list[str] | None = None) -> None | BaseFileLock:
def initialize_options(arguments: list[str] | None = None) -> BaseFileLock | None:
"""Load config options and store them inside options module."""
cache_dir_lock = None
new_options = cli.get_config(arguments or [])
Expand Down Expand Up @@ -377,7 +377,7 @@ def main(argv: list[str] | None = None) -> int:
_logger.debug("Ignored: %s", match)

if app.yamllint_config.incompatible:
logging.log(
_logger.log(
level=logging.ERROR if options.write_list else logging.WARNING,
msg=app.yamllint_config.incompatible,
)
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self, options: Options):
str(self.runtime.version),
): # pragma: no cover
msg = f"ansible-lint requires {package}{','.join(str(x) for x in self.reqs[package])} and current version is {self.runtime.version}"
logging.error(msg)
_logger.error(msg)
sys.exit(RC.INVALID_CONFIG)

# pylint: disable=import-outside-toplevel
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def __call__(
values: str | Sequence[Any] | None,
option_string: str | None = None,
) -> None:
logging.debug(option_string)
_logger.debug(option_string)
if isinstance(values, str | Path):
values = [values]
if values:
Expand Down
8 changes: 4 additions & 4 deletions src/ansiblelint/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def guess_install_method() -> str:
if (distribution(package_name).read_text("INSTALLER") or "").strip() != "pip":
return ""
except PackageNotFoundError as exc:
logging.debug(exc)
_logger.debug(exc)
return ""

pip = ""
Expand Down Expand Up @@ -251,16 +251,16 @@ def guess_install_method() -> str:

dist = get_default_environment().get_distribution(package_name)
if dist:
logging.debug("Found %s dist", dist)
_logger.debug("Found %s dist", dist)
for _ in uninstallation_paths(dist):
use_pip = True
else:
logging.debug("Skipping %s as it is not installed.", package_name)
_logger.debug("Skipping %s as it is not installed.", package_name)
use_pip = False
except (AttributeError, ModuleNotFoundError) as exc:
# On Fedora 36, we got a AttributeError exception from pip that we want to avoid
# On NixOS, we got a ModuleNotFoundError exception from pip that we want to avoid
logging.debug(exc)
_logger.debug(exc)
use_pip = False

# We only want to recommend pip for upgrade if it looks safe to do so.
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def data(self) -> Any:
self,
)
else:
logging.debug(
_logger.debug(
"data set to None for %s due to being '%s' (%s) kind.",
self.path,
self.kind,
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def _parse_failed_msg(

# testing code to be loaded only with pytest or when executed the rule file
if "pytest" in sys.modules:
import pytest # noqa: TCH002
import pytest # noqa: TC002

from ansiblelint.runner import Runner # pylint: disable=ungrouped-imports

Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/empty_string_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ComparisonToEmptyStringRule(AnsibleLintRule):
tags = ["idiom", "opt-in"]
version_added = "v4.0.0"

empty_string_compare = re.compile("[=!]= ?(\"{2}|'{2})")
empty_string_compare = re.compile(r"[=!]= ?(\"{2}|'{2})")

def matchtask(
self,
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/literal_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ComparisonToLiteralBoolRule(AnsibleLintRule):
tags = ["idiom"]
version_added = "v4.0.0"

literal_bool_compare = re.compile("[=!]= ?(True|true|False|false)")
literal_bool_compare = re.compile(r"[=!]= ?(True|true|False|false)")

def matchtask(
self,
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/loop_var_prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RoleLoopVarPrefix(AnsibleLintRule):
"""

tags = ["idiom"]
prefix = re.compile("")
prefix = re.compile(r"")
severity = "MEDIUM"
_ids = {
"loop-var-prefix[wrong]": "Loop variable name does not match regex.",
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/meta_no_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MetaTagValidRule(AnsibleLintRule):
tags = ["metadata"]
version_added = "v4.0.0"

TAG_REGEXP = re.compile("^[a-z0-9]+$")
TAG_REGEXP = re.compile(r"^[a-z0-9]+$")

def matchyaml(self, file: Lintable) -> list[MatchError]:
"""Find violations inside meta files."""
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def matchyaml(self, file: Lintable) -> list[MatchError]:

if entry:
# match up to the first "/"
regex = re.match("[^/]*", entry)
regex = re.match(r"[^/]*", entry)

if regex:
base_ignore_dir = regex.group(0)
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/rules/syntax_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ class KnownError:
KnownError(
tag="empty-playbook",
regex=re.compile(
"Empty playbook, nothing to do",
r"Empty playbook, nothing to do",
re.MULTILINE | re.DOTALL | re.DOTALL,
),
),
KnownError(
tag="malformed",
regex=re.compile(
"^ERROR! (?P<title>A malformed block was encountered while loading a block[^\n]*)",
r"^ERROR! (?P<title>A malformed block was encountered while loading a block[^\n]*)",
re.MULTILINE | re.DOTALL | re.DOTALL,
),
),
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ def find_children(self, lintable: Lintable) -> list[Lintable]:
playbook_ds = ansiblelint.utils.parse_yaml_from_file(str(lintable.path))
except AnsibleError as exc:
msg = f"Loading {lintable.filename} caused an {type(exc).__name__} exception: {exc}, file was ignored."
logging.exception(msg)
_logger.exception(msg)
return []
results = []
# playbook_ds can be an AnsibleUnicode string, which we consider invalid
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from functools import cache

RE_HAS_JINJA = re.compile(r"{[{%#].*[%#}]}", re.DOTALL)
RE_HAS_GLOB = re.compile("[][*?]")
RE_HAS_GLOB = re.compile(r"[][*?]")
RE_IS_FQCN_OR_NAME = re.compile(r"^\w+(\.\w+\.\w+)?$")


Expand Down
6 changes: 3 additions & 3 deletions src/ansiblelint/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ def _do_transforms(
for match in sorted(matches):
match_id = f"{match.tag}/{match.match_type} {match.filename}:{match.lineno}"
if not isinstance(match.rule, TransformMixin):
logging.debug("%s %s", self.FIX_NA_MSG, match_id)
_logger.debug("%s %s", self.FIX_NA_MSG, match_id)
continue
if self.write_set != {"all"}:
rule = cast(AnsibleLintRule, match.rule)
rule_definition = set(rule.tags)
rule_definition.add(rule.id)
if rule_definition.isdisjoint(self.write_set):
logging.debug("%s %s", self.FIX_NE_MSG, match_id)
_logger.debug("%s %s", self.FIX_NE_MSG, match_id)
continue
if file_is_yaml and not match.yaml_path:
data = cast(CommentedMap | CommentedSeq, data)
Expand All @@ -167,7 +167,7 @@ def _do_transforms(
):
match.yaml_path = get_path_to_task(file, match.lineno, data)

logging.debug("%s %s", self.FIX_APPLY_MSG, match_id)
_logger.debug("%s %s", self.FIX_APPLY_MSG, match_id)
try:
match.rule.transform(match, file, data)
except Exception as exc: # pylint: disable=broad-except
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def taskshandlers_children(
self,
lintable: Lintable,
k: str,
v: None | Any,
v: Any | None,
parent_type: FileType,
) -> list[Lintable]:
"""TasksHandlers Children."""
Expand Down Expand Up @@ -503,7 +503,7 @@ def append_playbook_path(loc: str, playbook_name: str) -> None:
else:
return [Lintable(possible_path, kind=parent_type)]

logging.error(msg)
_logger.error(msg)
return []


Expand Down
2 changes: 1 addition & 1 deletion test/test_rules_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def test_rich_rule_listing() -> None:

def test_rules_id_format(config_options: Options) -> None:
"""Assure all our rules have consistent format."""
rule_id_re = re.compile("^[a-z-]{4,30}$")
rule_id_re = re.compile(r"^[a-z-]{4,30}$")
rules = RulesCollection(
[Path("./src/ansiblelint/rules").resolve()],
options=config_options,
Expand Down

0 comments on commit 1b11890

Please sign in to comment.