From 7a30b958e224e2347f81db3e85e788335f41cfe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milo=C5=A1=20Prchl=C3=ADk?= Date: Fri, 21 Feb 2025 12:50:46 +0100 Subject: [PATCH] Enable preview lint checks of ruff See [1]: preview rules are sometimes interesting rules, but they are not enabled and ruff community collects opinions before deciding whether a rule is worth eing enabled by default. And there are some useful rules, I'd like to start enabling them in smaller groups, to make review easier. Starting with this patch and already enabled rules. [1] https://docs.astral.sh/ruff/preview/#preview --- pyproject.toml | 5 +++++ tests/unit/test_utils.py | 4 ++-- tmt/options.py | 5 ++--- tmt/steps/provision/mrack.py | 12 ++---------- tmt/steps/report/reportportal.py | 2 +- 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 330964bd87..b16217ca54 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -300,6 +300,11 @@ exclude = [ ] [tool.ruff.lint] +# Enable preview rules... +preview = true +# ... but enable them manually for now. +explicit-preview-rules = true + select = [ "F", # pyflakes "E", # pycodestyle error diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 97252433d2..fef46dcc59 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -1013,7 +1013,7 @@ def test_not_in_repository( cls, nested_file: tuple[Path, Path, Path], root_logger): - top_dir, sub_dir, file = nested_file + _, sub_dir, _ = nested_file with pytest.raises(GeneralError, match=r"Failed to add path .* to git index."): git_add(path=sub_dir, logger=root_logger) @@ -1023,7 +1023,7 @@ def test_in_repository( cls, nested_file: tuple[Path, Path, Path], root_logger): - top_dir, sub_dir, file = nested_file + top_dir, sub_dir, _ = nested_file run(ShellScript('git init').to_shell_command(), cwd=top_dir) git_add(path=sub_dir, logger=root_logger) diff --git a/tmt/options.py b/tmt/options.py index 98de58e90b..9dc4cf533b 100644 --- a/tmt/options.py +++ b/tmt/options.py @@ -54,7 +54,7 @@ def rendered(self) -> str: class Path(click.ParamType): name = 'path' - def convert( + def convert( # noqa: RET503 self, value: Any, param: Optional[click.Parameter], @@ -100,8 +100,7 @@ def convert( ctx=ctx, ) - # RET503: ruff does not recognize NoReturn annotation of `self.fail`. - self.fail( # noqa: RET503 + self.fail( f"Field '{param.name}' must be a path-like string, '{type(value).__name__}' found.", param=param, ctx=ctx, diff --git a/tmt/steps/provision/mrack.py b/tmt/steps/provision/mrack.py index 3f0b1ad523..1cc9f5c254 100644 --- a/tmt/steps/provision/mrack.py +++ b/tmt/steps/provision/mrack.py @@ -238,9 +238,7 @@ def _transform_unsupported( def _transform_beaker_pool( constraint: tmt.hardware.TextConstraint, logger: tmt.log.Logger ) -> MrackBaseHWElement: - beaker_operator, actual_value, negate = operator_to_beaker_op( - constraint.operator, constraint.value - ) + beaker_operator, actual_value, _ = operator_to_beaker_op(constraint.operator, constraint.value) return MrackHWBinOp('pool', beaker_operator, actual_value) @@ -464,9 +462,7 @@ def _transform_memory( def _transform_tpm_version( constraint: tmt.hardware.TextConstraint, logger: tmt.log.Logger ) -> MrackBaseHWElement: - beaker_operator, actual_value, negate = operator_to_beaker_op( - constraint.operator, constraint.value - ) + beaker_operator, actual_value, _ = operator_to_beaker_op(constraint.operator, constraint.value) return MrackHWKeyValue('TPM', beaker_operator, actual_value) @@ -474,10 +470,6 @@ def _transform_tpm_version( def _transform_virtualization_is_virtualized( constraint: tmt.hardware.FlagConstraint, logger: tmt.log.Logger ) -> MrackBaseHWElement: - beaker_operator, actual_value, _ = operator_to_beaker_op( - constraint.operator, str(constraint.value) - ) - test = (constraint.operator, constraint.value) if test in [(tmt.hardware.Operator.EQ, True), (tmt.hardware.Operator.NEQ, False)]: diff --git a/tmt/steps/report/reportportal.py b/tmt/steps/report/reportportal.py index a78219b06a..cabb433aa5 100644 --- a/tmt/steps/report/reportportal.py +++ b/tmt/steps/report/reportportal.py @@ -492,7 +492,7 @@ def execute_rp_import(self) -> None: # The datetime *strings* are in fact sorted here, but finding the minimum will work, # because the datetime in ISO format is designed to be lexicographically sortable. launch_time = min( - [r.start_time or self.datetime for r in self.step.plan.execute.results()] + r.start_time or self.datetime for r in self.step.plan.execute.results() ) # Create launch, suites (if "--suite_per_plan") and tests;