Skip to content

Commit 2c43ed8

Browse files
authored
Merge pull request #338 from mulkieran/replace-linters-and-formatters-with-ruff
Replace linters and formatters with ruff
2 parents 4136e93 + 0ebda4b commit 2c43ed8

12 files changed

Lines changed: 83 additions & 126 deletions

File tree

‎.github/workflows/main.yml‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,15 @@ jobs:
2626
include:
2727
# MANDATORY CHECKS USING CURRENT DEVELOPMENT INTERPRETER
2828
- dependencies: >
29-
pylint
3029
python3-dbus
3130
python3-dbus-python-client-gen
3231
python3-justbytes
3332
python3-gobject
3433
python3-psutil
34+
ruff
3535
image: fedora:43 # CURRENT DEVELOPMENT ENVIRONMENT
36-
task: PYTHONPATH=./src make -f Makefile lint
37-
- dependencies: >
38-
black
39-
python3-isort
36+
task: make -f Makefile lint
37+
- dependencies: ruff
4038
image: fedora:43 # CURRENT DEVELOPMENT ENVIRONMENT
4139
task: make -f Makefile fmt-travis
4240
# VERIFICATION OF TEST INFRASTRUCTURE

‎.isort.cfg‎

Lines changed: 0 additions & 16 deletions
This file was deleted.

‎Makefile‎

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,16 @@
11
.PHONY: lint
22
lint:
3-
pylint test_harness.py
4-
pylint stratis_cli_cert.py
5-
pylint stratisd_cert.py
6-
pylint testlib
7-
pylint scripts --disable=duplicate-code
3+
ruff check
84

95
.PHONY: fmt
106
fmt:
11-
isort \
12-
test_harness.py \
13-
stratis_cli_cert.py \
14-
stratisd_cert.py \
15-
testlib scripts
16-
black .
7+
ruff check --fix --select I
8+
ruff format
179

1810
.PHONY: fmt-travis
1911
fmt-travis:
20-
isort --diff --check-only \
21-
test_harness.py \
22-
stratis_cli_cert.py \
23-
stratisd_cert.py \
24-
testlib scripts
25-
black . --check
12+
ruff check --select I
13+
ruff format --check
2614

2715
.PHONY: yamllint
2816
yamllint:

‎pyproject.toml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[tool.ruff]
2+
target-version = "py312"
3+
line-length = 88
4+
5+
[tool.ruff.lint]
6+
select = ["PL"]
7+
8+
[tool.ruff.lint.isort]
9+
known-first-party = ["dbus_python_client_gen"]
10+
split-on-trailing-comma = false

‎scripts/monitor_dbus_signals.py‎

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@
4747
_EMITS_CHANGED_PROP = "org.freedesktop.DBus.Property.EmitsChangedSignal"
4848

4949

50-
class Diff: # pylint: disable=too-few-public-methods
50+
class Diff:
5151
"""
5252
Diff between two different managed object results.
5353
"""
5454

5555

56-
class AddedProperty(Diff): # pylint: disable=too-few-public-methods
56+
class AddedProperty(Diff):
5757
"""
5858
Property appears in new result but not in recorded result.
5959
"""
@@ -71,7 +71,7 @@ def __repr__(self):
7171
)
7272

7373

74-
class RemovedProperty(Diff): # pylint: disable=too-few-public-methods
74+
class RemovedProperty(Diff):
7575
"""
7676
Property appears in recorded result but not in new result.
7777
"""
@@ -89,14 +89,12 @@ def __repr__(self):
8989
)
9090

9191

92-
class DifferentProperty(Diff): # pylint: disable=too-few-public-methods
92+
class DifferentProperty(Diff):
9393
"""
9494
Difference between two properties.
9595
"""
9696

97-
def __init__(
98-
self, object_path, interface_name, key, old_value, new_value
99-
): # pylint: disable=too-many-positional-arguments,too-many-arguments
97+
def __init__(self, object_path, interface_name, key, old_value, new_value):
10098
self.object_path = object_path
10199
self.interface_name = interface_name
102100
self.key = key
@@ -110,7 +108,7 @@ def __repr__(self):
110108
)
111109

112110

113-
class DifferentVariantLevel(Diff): # pylint: disable=too-few-public-methods
111+
class DifferentVariantLevel(Diff):
114112
"""
115113
Represents a case where the property value is correct but the variant
116114
level does not match. The variant levels among the GetManagedObjects
@@ -120,9 +118,7 @@ class DifferentVariantLevel(Diff): # pylint: disable=too-few-public-methods
120118
they must be heterogeneous.
121119
"""
122120

123-
def __init__(
124-
self, object_path, interface_name, key, old_value, new_value
125-
): # pylint: disable=too-many-positional-arguments,too-many-arguments
121+
def __init__(self, object_path, interface_name, key, old_value, new_value):
126122
self.object_path = object_path
127123
self.interface_name = interface_name
128124
self.key = key
@@ -137,15 +133,13 @@ def __repr__(self):
137133
)
138134

139135

140-
class NotInvalidatedProperty(Diff): # pylint: disable=too-few-public-methods
136+
class NotInvalidatedProperty(Diff):
141137
"""
142138
Represents a case where the property should have been invalidated but
143139
was updated instead.
144140
"""
145141

146-
def __init__(
147-
self, object_path, interface_name, key, old_value, new_value
148-
): # pylint: disable=too-many-positional-arguments,too-many-arguments
142+
def __init__(self, object_path, interface_name, key, old_value, new_value):
149143
self.object_path = object_path
150144
self.interface_name = interface_name
151145
self.key = key
@@ -160,15 +154,13 @@ def __repr__(self):
160154
)
161155

162156

163-
class ChangedProperty(Diff): # pylint: disable=too-few-public-methods
157+
class ChangedProperty(Diff):
164158
"""
165159
Represents a case where the property should have been constant but
166160
seems to have changed.
167161
"""
168162

169-
def __init__(
170-
self, object_path, interface_name, key, old_value, new_value
171-
): # pylint: disable=too-many-positional-arguments,too-many-arguments
163+
def __init__(self, object_path, interface_name, key, old_value, new_value):
172164
self.object_path = object_path
173165
self.interface_name = interface_name
174166
self.key = key
@@ -183,7 +175,7 @@ def __repr__(self):
183175
)
184176

185177

186-
class RemovedObjectPath(Diff): # pylint: disable=too-few-public-methods
178+
class RemovedObjectPath(Diff):
187179
"""
188180
Object path appears in recorded result but not in new result.
189181
"""
@@ -196,7 +188,7 @@ def __repr__(self):
196188
return f"RemovedObjectPath({self.object_path!r}, {self.old_value!r})"
197189

198190

199-
class AddedInterface(Diff): # pylint: disable=too-few-public-methods
191+
class AddedInterface(Diff):
200192
"""
201193
Interface appears in new result but not in recorded result.
202194
"""
@@ -213,7 +205,7 @@ def __repr__(self):
213205
)
214206

215207

216-
class AddedObjectPath(Diff): # pylint: disable=too-few-public-methods
208+
class AddedObjectPath(Diff):
217209
"""
218210
Object path appears in new result but not in recorded result.
219211
"""
@@ -226,7 +218,7 @@ def __repr__(self):
226218
return f"AddedObjectPath({self.object_path!r}, {self.new_value!r})"
227219

228220

229-
class RemovedInterface(Diff): # pylint: disable=too-few-public-methods
221+
class RemovedInterface(Diff):
230222
"""
231223
Interface appears in recorded result but not in new result.
232224
"""
@@ -243,7 +235,7 @@ def __repr__(self):
243235
)
244236

245237

246-
class MissingInterface(Diff): # pylint: disable=too-few-public-methods
238+
class MissingInterface(Diff):
247239
"""
248240
Attempted to update a property on this interface, but the interface
249241
itself was missing when that happened.
@@ -295,7 +287,7 @@ def from_str(code_str):
295287
return item
296288
return None
297289

298-
class Invalidated: # pylint: disable=too-few-public-methods
290+
class Invalidated:
299291
"""
300292
Used to record in the updated GetManagedObjects value that a value has
301293
been invalidated.
@@ -306,7 +298,7 @@ def __repr__(self):
306298

307299
INVALIDATED = Invalidated()
308300

309-
class InterfaceMissing: # pylint: disable=too-few-public-methods
301+
class InterfaceMissing:
310302
"""
311303
Used to record in the updated GetManagedObjects value that when a
312304
property changed signal was received, the interface for that property
@@ -424,7 +416,7 @@ def _interfaces_added(object_path, interfaces_added):
424416
_MO[object_path][interface] = props
425417
else:
426418
_MO[object_path] = interfaces_added
427-
except Exception as exc: # pylint: disable=broad-except
419+
except Exception as exc:
428420
_CALLBACK_ERRORS.append(exc)
429421

430422
def _interfaces_removed(object_path, interfaces):
@@ -457,7 +449,7 @@ def _interfaces_removed(object_path, interfaces):
457449
# that the object itself has been removed.
458450
if _MO[object_path] == {}:
459451
del _MO[object_path]
460-
except Exception as exc: # pylint: disable=broad-except
452+
except Exception as exc:
461453
_CALLBACK_ERRORS.append(exc)
462454

463455
def _properties_changed(*props_changed, object_path=None):
@@ -524,7 +516,7 @@ def _properties_changed(*props_changed, object_path=None):
524516
data[interface_name][prop] = value
525517
for prop in properties_invalidated:
526518
data[interface_name][prop] = INVALIDATED
527-
except Exception as exc: # pylint: disable=broad-except
519+
except Exception as exc:
528520
_CALLBACK_ERRORS.append(exc)
529521

530522
def _monitor(
@@ -544,7 +536,7 @@ def _monitor(
544536
:type interface_re: re.Pattern
545537
"""
546538

547-
global _TOP_OBJECT, _TOP_OBJECT_PATH, _TOP_OBJECT_INTERFACES, _SERVICE, _MO, _INTERFACE_RE # pylint: disable=global-statement
539+
global _TOP_OBJECT, _TOP_OBJECT_PATH, _TOP_OBJECT_INTERFACES, _SERVICE, _MO, _INTERFACE_RE # noqa: PLW0603
548540

549541
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
550542
bus = dbus.SystemBus()
@@ -556,7 +548,7 @@ def _monitor(
556548
while True:
557549
try:
558550
_TOP_OBJECT = bus.get_object(service, _TOP_OBJECT_PATH)
559-
except Exception as err: # pylint: disable=broad-exception-caught
551+
except Exception as err:
560552
print(
561553
f'Failed to get top object "{_TOP_OBJECT_PATH}" for '
562554
f'service "{_SERVICE}". Error: {err}. Retrying.'
@@ -588,7 +580,7 @@ def _monitor(
588580
while True:
589581
try:
590582
_MO = _MAKE_MO()
591-
except Exception as err: # pylint: disable=broad-exception-caught
583+
except Exception as err:
592584
print(
593585
"Failed to get initial GetManagedObjects result for "
594586
f'service "{_SERVICE}" and top object '
@@ -747,24 +739,21 @@ def _check():
747739
if _MO is None:
748740
return []
749741

750-
mos = _MAKE_MO() # pylint: disable=not-callable
742+
mos = _MAKE_MO()
751743

752744
diffs = []
753745

754746
old_object_paths = frozenset(_MO.keys())
755747
new_object_paths = frozenset(mos.keys())
756748

757749
for object_path in old_object_paths - new_object_paths:
758-
diffs.append(
759-
# pylint: disable=unsubscriptable-object
760-
RemovedObjectPath(object_path, _MO[object_path])
761-
)
750+
diffs.append(RemovedObjectPath(object_path, _MO[object_path]))
762751

763752
for object_path in new_object_paths - old_object_paths:
764753
diffs.append(AddedObjectPath(object_path, mos[object_path]))
765754

766755
for object_path in new_object_paths & old_object_paths:
767-
old_data = _MO[object_path] # pylint: disable=unsubscriptable-object
756+
old_data = _MO[object_path]
768757
new_data = mos[object_path]
769758

770759
old_ifns = frozenset(old_data.keys())
@@ -792,7 +781,7 @@ def _check():
792781

793782
try:
794783
result = _check()
795-
except Exception as exco: # pylint: disable=broad-except
784+
except Exception as exco:
796785
print(f"{exco}")
797786
sys.exit(4)
798787

‎scripts/monitor_metadata.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def run(namespace):
8989
with open(
9090
os.path.join(
9191
namespace.output_dir,
92-
f'{datetime.datetime.now().strftime("%Y_%m_%d-%I_%M_%S_%p")}.json',
92+
f"{datetime.datetime.now().strftime('%Y_%m_%d-%I_%M_%S_%p')}.json",
9393
),
9494
mode="w",
9595
encoding="utf-8",

‎stratis_cli_cert.py‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"""
1515
Tests of the stratis CLI.
1616
"""
17-
# pylint: disable=too-many-lines
1817

1918
# isort: STDLIB
2019
import argparse
@@ -169,9 +168,7 @@ def test_access_stratis_man_page(self):
169168
self._unittest_command(["man", "--where", "stratis"], 0, True, False)
170169

171170

172-
class StratisCliCertify(
173-
StratisdSystemdStart, StratisCertify
174-
): # pylint: disable=too-many-public-methods
171+
class StratisCliCertify(StratisdSystemdStart, StratisCertify):
175172
"""
176173
Unit tests for the stratis-cli package.
177174
"""
@@ -1516,7 +1513,7 @@ def test_filesystem_mount_and_write(self):
15161513
[
15171514
"dd",
15181515
"if=/dev/urandom",
1519-
f'of={os.path.join(mountpoints[0], "file1")}',
1516+
f"of={os.path.join(mountpoints[0], 'file1')}",
15201517
"bs=4096",
15211518
"count=256",
15221519
"conv=fsync",

0 commit comments

Comments
 (0)