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

Enable more ruff lint rules #2014

Merged
merged 21 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3e3ab1f
Polarion report set to UTC timezone
martinhoyer Apr 18, 2023
c32c28f
Fix flake8 C408: unnecessary collection calls
martinhoyer Apr 18, 2023
f305e87
Fix flake8 C416: unnecessary comprehension
martinhoyer Apr 18, 2023
b895fae
Fix flake8 C401: unnecessary generator set
martinhoyer Apr 18, 2023
05dfbe0
Fix flake8 C405: unnecessary literal set
martinhoyer Apr 19, 2023
94a7cd4
Fix ruff B: flake8-bugbear errors
martinhoyer Apr 19, 2023
478c10e
Fix ruff RUF005: collection-literal-concatenation
martinhoyer Apr 19, 2023
47eb147
Fix ruff N: pep8-naming errors
martinhoyer Apr 19, 2023
b6a60da
Fix ruff UP: pyupgrade errors
martinhoyer Apr 19, 2023
5d90e27
Fix ruff PT: flake8-pytest-style errors
martinhoyer Apr 19, 2023
81da75d
Fix ruff RET: flake8-return errors
martinhoyer Apr 19, 2023
c105887
Fix ruff SIM: flake8-simplify errors
martinhoyer Apr 19, 2023
2587c1e
Remove duplicates from ruff rules selection
martinhoyer Apr 19, 2023
56450a8
Fix ruff PIE: flake8-pie errors
martinhoyer Apr 19, 2023
1a57bcd
Fix ruff RSE102: Unnecessary parentheses on exception
martinhoyer Apr 19, 2023
4a2d00d
Enable passing Pylint checks
martinhoyer Apr 19, 2023
3c4387f
Move isort to ruff
martinhoyer Apr 19, 2023
6c19c97
Fix py<38 mypy type:ignore being on wrong line
martinhoyer Apr 21, 2023
20bead2
Fix ruff RUF010: Use f-strings conversion flags
martinhoyer May 16, 2023
d23d444
Bump pre-commit hooks to latest version
martinhoyer May 16, 2023
ee71a4a
Use f-strings where possible
martinhoyer May 16, 2023
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
15 changes: 5 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ repos:
hooks:
- id: autopep8

- repo: https://github.com/PyCQA/isort
rev: "5.12.0"
hooks:
- id: isort

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.4.0"
hooks:
Expand All @@ -19,7 +14,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.2.0"
rev: "v1.3.0"
hooks:
- id: mypy
# Do not install *types-click* - it's not recommended with Click 8 & newer,
Expand All @@ -38,25 +33,25 @@ repos:
args: [--config-file=pyproject.toml]

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: "0.22.0"
rev: "0.23.1"
hooks:
- id: check-metaschema
name: "Check JSON schemas validity"
files: ^tmt/schemas/.*\.yaml

- repo: https://github.com/adrienverge/yamllint
rev: v1.30.0
rev: v1.32.0
hooks:
- id: yamllint
files: ^tmt/schemas/.*\.yaml

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.261
rev: v0.0.274
hooks:
- id: ruff
args: [--fix]

- repo: https://github.com/teemtee/tmt.git
rev: 1.23.0
rev: 1.24.1
hooks:
- id: tmt-lint
4 changes: 2 additions & 2 deletions bin/tmt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ try:

# Import utils first, before CLI gets a chance to spawn a logger. Without
# tmt.utils, we would not be able to intercept the exception below.
import tmt.utils
import tmt.utils # noqa: I001

import tmt.cli # isort: skip
import tmt.cli

tmt.cli.main()

Expand Down
13 changes: 6 additions & 7 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# documentation build configuration file, created by
# sphinx-quickstart on Mon Apr 27 17:44:03 2015.
Expand Down Expand Up @@ -72,9 +71,9 @@
master_man = 'man.1'

# General information about the project.
project = u'tmt'
copyright = u'Red Hat'
author = u'Petr Šplíchal'
project = 'tmt'
copyright = 'Red Hat'
author = 'Petr Šplíchal'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -241,7 +240,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_man, '', u'tmt Documentation',
(master_man, '', 'tmt Documentation',
[author], 1)
]

Expand Down Expand Up @@ -284,10 +283,10 @@ def __getattr__(cls, name: str) -> 'Mock':
os.makedirs('stories', exist_ok=True)
os.makedirs('spec', exist_ok=True)
for area in areas:
with open('{}.rst'.format(area.lstrip('/')), 'w') as doc:
with open(f"{area.lstrip('/')}.rst", 'w') as doc:
# Anchor and title
doc.write(f'.. _{area}:\n\n')
doc.write('{}\n{}\n'.format(areas[area], '=' * len(areas[area])))
doc.write(f"{areas[area]}\n{'=' * len(areas[area])}\n")
# Included stories
for story in tree.stories(names=[area], whole=True):
if story.enabled:
Expand Down
9 changes: 4 additions & 5 deletions examples/plugins/provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def options(cls, how=None):
help="Example how to pass value."),
option(
'-s', '--switch', is_flag=True,
help="Example how to enable something.")
] + super().options(how)
help="Example how to enable something."),
*super().options(how)]

def default(self, option, default=None):
""" Return the default value for the given option """
Expand Down Expand Up @@ -73,7 +73,7 @@ def go(self):
print("go() called")

# Data dictionary is used to pass information among classes.
data = dict(what='Another default what. Object variable can be used.')
data = {'what': 'Another default what. Object variable can be used.'}

for opt in ['what', 'switch']:
val = self.get(opt)
Expand Down Expand Up @@ -206,8 +206,7 @@ def execute(self, command, **kwargs):

print("execute() called. This is an optional overload...")

output = ["Fedora", "whatever"]
return output
return ["Fedora", "whatever"]

def delete(self):
""" Remove the example instance """
Expand Down
51 changes: 22 additions & 29 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ module = [
]
ignore_missing_imports = true

# code is currently formatted with default isort config
#[tool.isort]
#line_length = 99
#py_version = 37

[tool.autopep8]
max_line_length = 99
in-place = true
Expand All @@ -56,60 +51,58 @@ select = [
"E", # pycodestyle
"W", # pycodestyle
# "C90", # mccabe
# "I", # isort
# "N", # pep8-naming
"I", # isort
"N", # pep8-naming
# "UP", # pyupgrade
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"YTT", # flake8-2020
# "ANN", # flake8-annotations
# "S", # flake8-bandit
# "ISC", # flake8-implicit-str-concat
# "PT", # flake8-pytest-style
# "RET", # flake8-return
# "SIM", # flake8-simplify
"PT", # flake8-pytest-style
"RET", # flake8-return
"SIM", # flake8-simplify
# "ARG", # flake8-unused-arguments
# "BLE", # flake8-blind-except
# "FBT", # flake8-boolean-trap
# "A", # flake8-builtins
"COM", # flake8-commas
# "C4", # flake8-comprehensions
"DTZ", # flake8-datetimez
"T10", # flake8-debugger
# "EM", # flake8-errmsg
"EXE", # flake8-executable
# "ISC", # flake8-implicit-str-concat
# "G", # flake8-logging-format
# "PIE", # flake8-pie
"PIE", # flake8-pie
# "T20", # flake8-print
# "PT", # flake8-pytest-style
# "Q", # flake8-quotes
# "RSE", # flake8-raise
# "RET", # flake8-return
"RSE", # flake8-raise
# "SLF", # flake8-self
# "SIM", # flake8-simplify
# "TCH", # flake8-type-checking
"PGH", # pygrep-hooks
# "PLC", # pylint-convention
# "PLE", # pylint-error
# "PLR", # pylint-refactor
"PLC", # pylint-convention
"PLE", # pylint-error
"PLR01", # pylint-refactor
"PLR02",
"PLR04",
"PLR1",
# "PLW", # pylint-warning
# "TRY", # tryceratops
"RUF", # ruff
]
ignore = [
"C408", # Unnecessary `dict` call (rewrite as a literal)
"C416", # Unnecessary `list` comprehension (rewrite using `list()`)
"C401", # Unnecessary generator (rewrite as a `set` comprehension)
"C405", # Unnecessary `list` literal (rewrite as a `set` literal)
"B904", # Within an `except` clause, raise exceptions with `raise ... from err` or `raise ...
"B00", # B00{1..9}
"B011", # Do not `assert False` (`python -O` removes these calls), raise `AssertionError()`
"B012", # return` inside `finally` blocks cause exceptions to be silenced
"B018", # Found useless expression. Either assign it to a variable or remove it.
"COM812", # Trailing comma missing
"RUF005", # collection-literal-concatenation - Consider {expr} instead of concatenation
"PIE790", # Unnecessary `pass` statement
"PLC1901", # `{}` can be simplified to `{}` as an empty string is falsey
"PLE1205", # Too many arguments for `logging` format string
"RUF008", # Do not use mutable default values for dataclass attributes
"RUF009", # Do not perform function call `field` in dataclass defaults
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
"RUF013", # PEP 484 prohibits implicit `Optional`
]
[tool.ruff.isort]
known-first-party = ["tmt"]

[tool.ruff.per-file-ignores]
"tmt/steps/report/polarion.py" = ["DTZ005"]
Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env python
# coding: utf-8

import re
from io import open
from typing import Dict, List

from setuptools import setup
Expand Down Expand Up @@ -109,7 +107,7 @@
readme = _file.read()

github = 'https://github.com/teemtee/tmt'
download_url = '{0}/archive/main.zip'.format(github)
download_url = f'{github}/archive/main.zip'

setup(
url=github,
Expand Down
4 changes: 2 additions & 2 deletions tests/execute/reboot/get_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def main(key, yaml_file):

def find_value(data, key):
if not isinstance(data, dict):
raise ValueError()
raise ValueError
try:
return data[key]
except KeyError:
Expand All @@ -35,7 +35,7 @@ def find_value(data, key):
return find_value(value, key)
except ValueError:
pass
return
return None


if __name__ == "__main__":
Expand Down
Loading