Skip to content

Commit d27d6d7

Browse files
Replace black with ruff (#1083)
* Use ruff code formatter. * Reformat & fix. * Fix amazon-kinesis-video-streams-consumer dependencies.
1 parent 0cc6a7b commit d27d6d7

File tree

63 files changed

+182
-217
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+182
-217
lines changed

Makefile

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -178,25 +178,9 @@ run-dev:
178178
clean:
179179
find . -type d -name __pycache__ -exec rm -rf {} \+
180180

181-
check-black:
182-
black --check .
181+
check:
182+
ruff check .
183183

184-
check-unify:
185-
unify --check-only --recursive savant | grep -- '--- before' | sed 's#--- before/##'
186-
unify --check-only --recursive savant > /dev/null
187-
188-
check-isort:
189-
isort savant adapters gst_plugins samples scripts tests utils -c
190-
191-
check: check-black check-unify check-isort
192-
193-
run-unify:
194-
unify --in-place --recursive savant adapters gst_plugins samples scripts tests utils services
195-
196-
run-black:
197-
black .
198-
199-
run-isort:
200-
isort savant adapters gst_plugins samples scripts tests utils services
201-
202-
reformat: run-unify run-black run-isort
184+
reformat:
185+
ruff check . --fix
186+
ruff format .

adapters/ds/gst_plugins/python/always_on_rtsp_frame_processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class AlwaysOnRtspFrameProcessor(LoggerMixin, GstBase.BaseTransform):
7272
'mode': (
7373
str,
7474
'Transfer mode.',
75-
'Transfer mode (allowed: ' f'{", ".join([mode.value for mode in Mode])}).',
75+
f'Transfer mode (allowed: {", ".join([mode.value for mode in Mode])}).',
7676
DEFAULT_MODE.value,
7777
GObject.ParamFlags.READWRITE,
7878
),

adapters/ds/gst_plugins/python/savant_rs_video_player.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ def __init__(self, *args, **kwargs):
181181
self.add(self._decoder)
182182
self._decoder.connect('pad-added', self.on_pad_added)
183183

184-
assert self._source.link(self._queue), f'Failed to link source to queue'
185-
assert self._queue.link(self._decoder), f'Failed to link queue to decoder'
184+
assert self._source.link(self._queue), 'Failed to link source to queue'
185+
assert self._queue.link(self._decoder), 'Failed to link queue to decoder'
186186

187187
def do_get_property(self, prop):
188188
"""Gst plugin get property function.

adapters/ds/sinks/always_on_rtsp/__main__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ def main():
5353
]
5454
)
5555
logger.info('Started MediaMTX, PID: %s', mediamtx_process.pid)
56-
assert (
57-
mediamtx_process.returncode is None
58-
), f'Failed to start MediaMTX. Exit code: {mediamtx_process.returncode}.'
56+
assert mediamtx_process.returncode is None, (
57+
f'Failed to start MediaMTX. Exit code: {mediamtx_process.returncode}.'
58+
)
5959
else:
6060
mediamtx_process = None
6161

adapters/ds/sinks/always_on_rtsp/app_config.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ def __init__(self):
2020

2121
self.rtsp_uri = opt_config('RTSP_URI')
2222
if self.dev_mode:
23-
assert (
24-
self.rtsp_uri is None
25-
), '"RTSP_URI" cannot be set when "DEV_MODE=True"'
23+
assert self.rtsp_uri is None, (
24+
'"RTSP_URI" cannot be set when "DEV_MODE=True"'
25+
)
2626
self.rtsp_uri = 'rtsp://localhost:554/stream'
2727
else:
28-
assert (
29-
self.rtsp_uri is not None
30-
), '"RTSP_URI" must be set when "DEV_MODE=False"'
28+
assert self.rtsp_uri is not None, (
29+
'"RTSP_URI" must be set when "DEV_MODE=False"'
30+
)
3131

3232
self.api_port = opt_config('API_PORT', 13000, int)
3333
assert 1 <= self.api_port <= 65535, 'Invalid value for "API_PORT".'
3434

3535
self.status_poll_interval_ms = opt_config('STATUS_POLL_INTERVAL_MS', 1000, int)
36-
assert (
37-
self.status_poll_interval_ms > 0
38-
), 'Invalid value for "STATUS_POLL_INTERVAL_MS".'
36+
assert self.status_poll_interval_ms > 0, (
37+
'Invalid value for "STATUS_POLL_INTERVAL_MS".'
38+
)
3939
self.status_poll_interval = self.status_poll_interval_ms / 1000
4040

4141
self.fail_on_stream_error = opt_config('FAIL_ON_STREAM_ERROR', True, strtobool)

adapters/ds/sinks/always_on_rtsp/pipeline.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ def add_elements(
2323
assert gst_element is not None, f'Failed to create {element}'
2424
pipeline.add(gst_element)
2525
if gst_elements:
26-
assert gst_elements[-1].link(
27-
gst_element
28-
), f'Failed to link {gst_elements[-1].name} to {gst_element.name}'
26+
assert gst_elements[-1].link(gst_element), (
27+
f'Failed to link {gst_elements[-1].name} to {gst_element.name}'
28+
)
2929
gst_elements.append(gst_element)
3030
return gst_elements
3131

adapters/gst/gst_plugins/python/media_files_src_bin.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,14 @@ def validate_properties(self):
185185
assert self.file_type is not None, '"file-type" property is required'
186186
if not self.loop_file:
187187
return
188-
assert (
189-
self.file_type == FileType.VIDEO
190-
), f'Only "file-type={FileType.VIDEO.value}" is allowed when "loop-file" is enabled'
188+
assert self.file_type == FileType.VIDEO, (
189+
f'Only "file-type={FileType.VIDEO.value}" is allowed when "loop-file" is enabled'
190+
)
191191
if not isinstance(self.location, Path):
192192
return
193-
assert (
194-
self.download_path is not None
195-
), '"download-path" property is required when "loop-file" is enabled'
193+
assert self.download_path is not None, (
194+
'"download-path" property is required when "loop-file" is enabled'
195+
)
196196
if self.download_path.exists():
197197
assert self.download_path.is_dir(), '"download-path" must be a directory'
198198

@@ -210,9 +210,9 @@ def download_report(self, blocks: int, block_size: int, total: Optional[int]):
210210
def list_files(self):
211211
assert self.location.exists(), f'No such file or directory "{self.location}"'
212212
if self.location.is_dir():
213-
assert (
214-
not self.loop_file
215-
), f'Specifying directory as location is not allowed when "loop-file" is enabled'
213+
assert not self.loop_file, (
214+
'Specifying directory as location is not allowed when "loop-file" is enabled'
215+
)
216216
all_files = sorted(
217217
(f for f in self.location.iterdir() if f.is_file()),
218218
key=(

adapters/gst/sinks/multistream_kvs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class BufferConfig:
6161
def __init__(self):
6262
self.low_threshold = opt_config('BUFFER_LOW_THRESHOLD', 30, int)
6363
self.high_threshold = opt_config('BUFFER_HIGH_THRESHOLD', 40, int)
64-
assert (
65-
self.low_threshold < self.high_threshold
66-
), 'BUFFER_LOW_THRESHOLD must be less than BUFFER_HIGH_THRESHOLD'
64+
assert self.low_threshold < self.high_threshold, (
65+
'BUFFER_LOW_THRESHOLD must be less than BUFFER_HIGH_THRESHOLD'
66+
)
6767

6868

6969
class FpsMeterConfig:

adapters/gst/sinks/video_files.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,6 @@ def _write_video_frame(
384384
) or (None, None)
385385

386386
if writer is None:
387-
388387
video_writer = VideoFilesWriter(
389388
location,
390389
video_frame.source_id,

adapters/gst/sources/kvs/pipeline.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def workload(self):
6666
try:
6767
self.process_fragment()
6868
except Exception as e:
69-
self.logger.error(f'Error processing fragment: %s', e, exc_info=True)
69+
self.logger.error('Error processing fragment: %s', e, exc_info=True)
7070
break
7171

7272
self.is_running = False
@@ -142,7 +142,7 @@ def on_caps(self, pad: Gst.Pad, event: Gst.Event):
142142
def add_sink(self, pad: Gst.Pad, caps: Gst.Caps):
143143
"""Add sink elements to the pipeline."""
144144

145-
self.logger.debug(f'Try to find codec for %r', caps[0].get_name())
145+
self.logger.debug('Try to find codec for %r', caps[0].get_name())
146146
try:
147147
codec = caps_to_codec(caps)
148148
except ValueError:
@@ -212,9 +212,9 @@ def add_sink(self, pad: Gst.Pad, caps: Gst.Caps):
212212
last_element.get_name(),
213213
element.get_name(),
214214
)
215-
assert last_element.link(
216-
element
217-
), f'Failed to link {last_element.get_name()} to {element.get_name()}'
215+
assert last_element.link(element), (
216+
f'Failed to link {last_element.get_name()} to {element.get_name()}'
217+
)
218218
last_element = element
219219

220220
parser_pad: Gst.Pad = parser.get_static_pad('sink')
@@ -225,9 +225,9 @@ def add_sink(self, pad: Gst.Pad, caps: Gst.Caps):
225225
element.sync_state_with_parent()
226226

227227
parser_pad.send_event(self.build_stream_name_event())
228-
assert (
229-
pad.link(parser_pad) == Gst.PadLinkReturn.OK
230-
), f'Failed to link {pad.get_name()} to {parser_pad.get_name()}'
228+
assert pad.link(parser_pad) == Gst.PadLinkReturn.OK, (
229+
f'Failed to link {pad.get_name()} to {parser_pad.get_name()}'
230+
)
231231

232232
def build_stream_name_event(self) -> Gst.Event:
233233
tag_list: Gst.TagList = Gst.TagList.new_empty()

0 commit comments

Comments
 (0)