Skip to content

Commit 11197ce

Browse files
committed
Switch isort/flake8 to ruff
1 parent 085bdbf commit 11197ce

22 files changed

+34
-73
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,11 @@ repos:
1111
args: ['--maxkb=200']
1212
- id: check-yaml
1313

14-
# Automatically sort imports
15-
- repo: https://github.com/PyCQA/isort
16-
rev: 5.12.0
14+
- repo: https://github.com/charliermarsh/ruff-pre-commit
15+
rev: v0.0.272
1716
hooks:
18-
- id: isort
19-
args: [
20-
'-a', 'from __future__ import annotations', # 3.7-3.11
21-
'--rm', 'from __future__ import absolute_import', # -3.0
22-
'--rm', 'from __future__ import division', # -3.0
23-
'--rm', 'from __future__ import generator_stop', # -3.7
24-
'--rm', 'from __future__ import generators', # -2.3
25-
'--rm', 'from __future__ import nested_scopes', # -2.2
26-
'--rm', 'from __future__ import print_function', # -3.0
27-
'--rm', 'from __future__ import unicode_literals', # -3.0
28-
'--rm', 'from __future__ import with_statement', # -2.6
29-
]
17+
- id: ruff
18+
args: [--fix, --show-fixes, --exit-non-zero-on-fix]
3019

3120
# Automatic source code formatting
3221
- repo: https://github.com/psf/black
@@ -35,13 +24,6 @@ repos:
3524
- id: black
3625
args: [--safe, --quiet]
3726

38-
# Linting
39-
- repo: https://github.com/PyCQA/flake8
40-
rev: 6.1.0
41-
hooks:
42-
- id: flake8
43-
additional_dependencies: ['flake8-comprehensions==3.14.0', 'flake8-pyproject>=1.2.3']
44-
4527
# Type checking
4628
- repo: https://github.com/pre-commit/mirrors-mypy
4729
rev: v0.910

pyproject.toml

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,17 @@ storage = "zocalo.configuration.plugin_storage:Storage"
8383
"zocalo.shutdown" = "zocalo.cli.shutdown:run"
8484
"zocalo.wrap" = "zocalo.cli.wrap:run"
8585

86-
[tool.flake8]
87-
# Black disagrees with flake8 on a few points. Ignore those.
88-
ignore = "E203, E266, E501, W503"
89-
# E203 whitespace before ':'
90-
# E266 too many leading '#' for block comment
91-
# E501 line too long
92-
# W503 line break before binary operator
93-
max-line-length = "88"
94-
select = """
95-
E401,E711,E712,E713,E714,E721,E722,E901,
96-
F401,F402,F403,F405,F541,F631,F632,F633,F811,F812,F821,F822,F841,F901,
97-
W191,W291,W292,W293,W602,W603,W604,W605,W606,
98-
# flake8-comprehensions, https://github.com/adamchainz/flake8-comprehensions
99-
C4,"""
100-
10186
[tool.isort]
10287
profile = "black"
10388

10489
[tool.pytest.ini_options]
10590
required_plugins = "pytest-mock requests-mock"
91+
92+
[tool.ruff]
93+
line-length = 88
94+
ignore = ["E501", "E741"]
95+
select = ["C4", "E", "F", "W", "I"]
96+
unfixable = ["F841"]
97+
98+
[tool.ruff.isort]
99+
required-imports = ["from __future__ import annotations"]

src/zocalo/cli/configure_rabbitmq.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
PermissionSpec,
2020
PolicySpec,
2121
QueueSpec,
22+
UserSpec,
23+
VHostSpec,
24+
hash_password,
2225
)
2326
from zocalo.util.rabbitmq import RabbitMQAPI as _RabbitMQAPI
24-
from zocalo.util.rabbitmq import UserSpec, VHostSpec, hash_password
2527

2628
logger = logging.getLogger("zocalo.cli.configure_rabbitmq")
2729

src/zocalo/service/schlockmeister.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ def update_subscriptions(self):
179179
if self.known_queues[destination].get("subscription"):
180180
continue
181181
real_subscriber_count = sum(
182-
map(
183-
lambda k: k not in self.known_instances,
184-
self.known_queues[destination]["subscribers"],
182+
(
183+
k not in self.known_instances
184+
for k in self.known_queues[destination]["subscribers"]
185185
)
186186
)
187187
if real_subscriber_count:
@@ -205,9 +205,9 @@ def garbage_collect(self):
205205
for destination in queues:
206206
if self.known_queues[destination].get("subscription"):
207207
real_subscriber_count = sum(
208-
map(
209-
lambda k: k not in self.known_instances,
210-
self.known_queues[destination]["subscribers"],
208+
(
209+
k not in self.known_instances
210+
for k in self.known_queues[destination]["subscribers"]
211211
)
212212
)
213213
if not real_subscriber_count:

src/zocalo/util/rabbitmq.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -759,9 +759,10 @@ def bindings(
759759
if destination_type is not None:
760760
endpoint = f"{endpoint}/e/{source}/{destination_type}/{destination}"
761761
dest_map = {"queue": "q", "exchange": "e"}
762-
conv = (
763-
lambda key, value: dest_map[value] if key == "destination_type" else value
764-
)
762+
763+
def conv(key, value):
764+
return dest_map[value] if key == "destination_type" else value
765+
765766
return [
766767
BindingInfo(**{_r[0]: conv(_r[0], _r[1]) for _r in r.items()})
767768
for r in self.get(endpoint).json()
@@ -791,11 +792,10 @@ def bindings_delete(
791792
endpoint = f"bindings/{vhost}/e/{source}/{destination_type}/{destination}"
792793
if properties_key is None:
793794
dest_map = {"queue": "q", "exchange": "e"}
794-
conv = (
795-
lambda key, value: dest_map[value]
796-
if key == "destination_type"
797-
else value
798-
)
795+
796+
def conv(key, value):
797+
return dest_map[value] if key == "destination_type" else value
798+
799799
props = [
800800
BindingInfo(
801801
**{_r[0]: conv(_r[0], _r[1]) for _r in r.items()}

tests/cli/test_dlq_purge.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
from unittest import mock
66

77
import workflows.transport
8-
from workflows.transport.common_transport import CommonTransport
9-
108
import zocalo.cli.dlq_purge as dlq_purge
9+
from workflows.transport.common_transport import CommonTransport
1110

1211

1312
def gen_header_activemq(i):

tests/cli/test_dlq_reinject.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import workflows.transport
1010
from workflows.transport.common_transport import CommonTransport
11-
1211
from zocalo.cli.dlq_reinject import run
1312

1413

tests/cli/test_pickup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88

99
import pytest
1010
import workflows.transport
11-
from workflows.transport.common_transport import CommonTransport
12-
1311
import zocalo.configuration
12+
from workflows.transport.common_transport import CommonTransport
1413
from zocalo.cli import pickup
1514

1615

tests/cli/test_queue_drain.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import workflows.transport
66
from workflows.transport.common_transport import CommonTransport
7-
87
from zocalo.cli.queue_drain import run
98

109

tests/cli/test_shutdown.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import workflows.transport
77
from workflows.transport.common_transport import CommonTransport
88
from workflows.util import generate_unique_host_id
9-
109
from zocalo.cli.shutdown import run
1110

1211

0 commit comments

Comments
 (0)