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

Replace flake8 with Ruff #12621

Merged
merged 6 commits into from
Sep 21, 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
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
Comment on lines 10 to 14
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also run pre-commit autoupdate; pre-commit run -a to update the available pre-commit hooks and code changes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to do it in a separate PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#12650 created

- 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]
Gauravtalreja1 marked this conversation as resolved.
Show resolved Hide resolved
- 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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe one day....


[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 @@ -316,7 +316,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)',
Gauravtalreja1 marked this conversation as resolved.
Show resolved Hide resolved
}

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 @@ -141,7 +141,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 @@ -159,7 +159,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
Loading