Skip to content

Commit

Permalink
Replace flake8 with Ruff (#12621)
Browse files Browse the repository at this point in the history
* Replace flake8 with Ruff

* Replace flake8 with Ruff

* Fix UP038 - non-pep604-isinstance

* Fix F401 - remove unused imports

* Fix F601 - Remove repeated dictionary key

* Fix not-in-test (E713)

(cherry picked from commit 187cca1)
  • Loading branch information
ogajduse authored and JacobCallahan committed Sep 21, 2023
1 parent 128791d commit 808dd04
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 22 deletions.
2 changes: 0 additions & 2 deletions .flake8

This file was deleted.

13 changes: 4 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,17 @@ repos:
hooks:
- id: trailing-whitespace
exclude: tests/foreman/data/
- id: end-of-file-fixer
- id: check-yaml
- id: debug-statements
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.0
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.277
hooks:
- id: flake8
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: local
hooks:
- id: fix-uuids
Expand Down
23 changes: 23 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,29 @@ exclude = '''
)/
'''

[tool.ruff]
target-version = "py311"
fixable = ["ALL"]

select = [
# "C90", # mccabe
"E", # pycodestyle
"F", # flake8
# "Q", # flake8-quotes
"UP", # pyupgrade
"W", # pycodestyle
]

# Allow lines to be as long as 100 characters.
line-length = 100


[tool.ruff.flake8-quotes]
inline-quotes = "single"

[tool.ruff.mccabe]
max-complexity = 20

[tool.pytest.ini_options]
junit_logging = 'all'
addopts = '--show-capture=no'
1 change: 0 additions & 1 deletion robottelo/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ class Colored(Box):
'rhel7_extra': 'Red Hat Enterprise Linux 7 Server - Extras (RPMs)',
'rhel7_optional': 'Red Hat Enterprise Linux 7 Server - Optional (RPMs)',
'rhel7_sup': 'Red Hat Enterprise Linux 7 Server - Supplementary (RPMs)',
'rhst7_610': 'Red Hat Satellite Tools 6.10 (for RHEL 7 Server) (RPMs)',
}

SM_OVERALL_STATUS = {
Expand Down
4 changes: 2 additions & 2 deletions robottelo/host_helpers/satellite_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def upload_manifest(self, org_id, manifest=None, interface='API', timeout=None):
:returns: the manifest upload result
"""
if not isinstance(manifest, (bytes, io.BytesIO)):
if not isinstance(manifest, bytes | io.BytesIO):
if manifest.content is None:
manifest = clone()
if timeout is None:
Expand All @@ -160,7 +160,7 @@ def upload_manifest(self, org_id, manifest=None, interface='API', timeout=None):
{'file': manifest.filename, 'organization-id': org_id}, timeout=timeout
)
else:
if not isinstance(manifest, (bytes, io.BytesIO)):
if not isinstance(manifest, bytes | io.BytesIO):
manifest = manifest.content
result = self.api.Subscription().upload(
data={'organization_id': org_id}, files={'content': manifest}
Expand Down
2 changes: 1 addition & 1 deletion tests/foreman/api/test_multiple_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _get_readable_attributes(entity):
for field_name in list(attributes.keys()):
if isinstance(
entity.get_fields()[field_name],
(entity_fields.OneToOneField, entity_fields.OneToManyField),
entity_fields.OneToOneField | entity_fields.OneToManyField,
):
del attributes[field_name]

Expand Down
2 changes: 1 addition & 1 deletion tests/foreman/cli/test_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _create_webhook(org, loc, options=None):

def assert_created(options, hook):
for option in options.items():
if not option[0] in ['event', 'organization-id', 'location-id']:
if option[0] not in ['event', 'organization-id', 'location-id']:
assert hook[option[0]] == option[1]


Expand Down
2 changes: 0 additions & 2 deletions tests/foreman/endtoend/test_api_endtoend.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
:Upstream: No
"""
import http
import random
from collections import defaultdict
from pprint import pformat

Expand All @@ -35,7 +34,6 @@
from robottelo.config import user_nailgun_config
from robottelo.constants.repos import CUSTOM_RPM_REPO
from robottelo.utils.issue_handlers import is_open
from robottelo.utils.manifest import clone


API_PATHS = {
Expand Down
2 changes: 1 addition & 1 deletion tests/foreman/ui/test_bookmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def ui_entity(module_org, module_location, request):
# Skip the entities, which can't be tested ATM (not implemented in
# airgun or have open BZs)
skip = entity.get('skip_for_ui')
if isinstance(skip, (tuple, list)):
if isinstance(skip, tuple | list):
open_issues = {issue for issue in skip if is_open(issue)}
pytest.skip(f'There is/are an open issue(s) {open_issues} with entity {entity_name}')
# entities with 1 organization and location
Expand Down
2 changes: 1 addition & 1 deletion tests/robottelo/test_datafactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_return_type(self):
):
assert isinstance(item, str)
for item in datafactory.invalid_id_list():
if not (isinstance(item, (str, int)) or item is None):
if not (isinstance(item, str | int) or item is None):
pytest.fail('Unexpected data type')


Expand Down
4 changes: 2 additions & 2 deletions tests/upgrades/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def test_something_post_upgrade(pre_upgrade_data):
dependant_on_functions = []
for marker in request.node.iter_markers(POST_UPGRADE_MARK):
depend_on = marker.kwargs.get('depend_on')
if isinstance(depend_on, (list, tuple)):
if isinstance(depend_on, list | tuple):
dependant_on_functions.extend(depend_on)
elif depend_on is not None:
dependant_on_functions.append(depend_on)
Expand Down Expand Up @@ -403,7 +403,7 @@ def pytest_collection_modifyitems(items, config):
dependant_on_functions = []
for marker in item.iter_markers(POST_UPGRADE_MARK):
depend_on = marker.kwargs.get('depend_on')
if isinstance(depend_on, (list, tuple)):
if isinstance(depend_on, list | tuple):
dependant_on_functions.extend(depend_on)
elif depend_on is not None:
dependant_on_functions.append(depend_on)
Expand Down

0 comments on commit 808dd04

Please sign in to comment.