Skip to content

Commit

Permalink
activate ruff-specific rules
Browse files Browse the repository at this point in the history
  • Loading branch information
zariiii9003 committed Nov 18, 2023
1 parent bcc12ef commit 3cd531a
Show file tree
Hide file tree
Showing 20 changed files with 42 additions and 40 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ select = [
"F", # pyflakes
"UP", # pyupgrade
"I", # isort
"RUF", # ruff-specific rules
]
ignore = [
"B007", # unused-loop-control-variable
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def _get_ext_modules():
include_package_data=True,
# Although 'package_data' is the preferred approach, in some case you may
# need to place data files outside of your packages. See:
# http://docs.python.org/3.4/distutils/setupscript.html#installing-additional-files # noqa
# http://docs.python.org/3.4/distutils/setupscript.html#installing-additional-files
# In this case, 'data_file' will be installed into '<sys.prefix>/my_data'
# data_files=[('my_data', ['data/data_file'])],
# To provide executable scripts, use entry points in preference to the
Expand Down
4 changes: 2 additions & 2 deletions src/asammdf/blocks/mdf_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -4441,7 +4441,7 @@ def _append_dataframe(
acq_name: str | None = None,
acq_source: Source | None = None,
comment: str | None = None,
units: dict[str, str | bytes] = None,
units: dict[str, str | bytes] | None = None,
) -> None:
"""
Appends a new data group from a Pandas data frame.
Expand Down Expand Up @@ -6925,7 +6925,7 @@ def _get_array(
shape = (shape[0],) + shape[1:][::-1]
vals = vals.reshape(shape)

axes = (0,) + tuple(range(len(shape) - 1, 0, -1))
axes = (0, *tuple(range(len(shape) - 1, 0, -1)))
vals = transpose(vals, axes=axes)

cycles_nr = len(vals)
Expand Down
4 changes: 2 additions & 2 deletions src/asammdf/blocks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1799,7 +1799,7 @@ def load_can_database(path: StrPathType, contents: bytes | str | None = None, **
can_matrix.merge(rest)

else:
first_bus = list(dbs)[0]
first_bus = next(iter(dbs))
can_matrix = dbs[first_bus]
else:
can_matrix = None
Expand Down Expand Up @@ -2337,7 +2337,7 @@ def load_channel_names_from_file(file_name, lab_section=""):
if len(info) > 1 and lab_section:
channels = info[lab_section]
else:
channels = list(info.values())[0]
channels = next(iter(info.values()))

channels = [name.split(";")[0] for name in channels]

Expand Down
2 changes: 1 addition & 1 deletion src/asammdf/blocks/v2_v3_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ def to_blocks(
self.short_name = text.encode("latin-1", "backslashreplace")[:31]

key = "display_name_addr"
text = list(self.display_names)[0] if self.display_names else ""
text = next(iter(self.display_names)) if self.display_names else ""
if self.block_len >= v23c.CN_DISPLAYNAME_BLOCK_SIZE:
if text:
if text in defined_texts:
Expand Down
2 changes: 1 addition & 1 deletion src/asammdf/blocks/v2_v3_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@
"max_raw_value",
"sampling_rate",
)
KEYS_CHANNEL_LONGNAME = KEYS_CHANNEL_SHORT + ("long_name_addr",)
KEYS_CHANNEL_LONGNAME = (*KEYS_CHANNEL_SHORT, "long_name_addr")

FMT_CHANNEL_GROUP = "<2sH3I3HI"
KEYS_CHANNEL_GROUP = (
Expand Down
4 changes: 2 additions & 2 deletions src/asammdf/blocks/v4_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@

FMT_CONVERSION_LINEAR = FMT_CONVERSION_NONE + "2d"
CONVERSION_LINEAR_PACK = struct.Struct(FMT_CONVERSION_LINEAR).pack
KEYS_CONVERSION_LINEAR = KEYS_CONVERSION_NONE + ("b", "a")
KEYS_CONVERSION_LINEAR = (*KEYS_CONVERSION_NONE, "b", "a")
FMT_CONVERSION_LINEAR_INIT = "<4Q2B3H4d"
CONVERSION_LINEAR_INIT_u = struct.Struct(FMT_CONVERSION_LINEAR_INIT).unpack
CONVERSION_LINEAR_INIT_uf = struct.Struct(FMT_CONVERSION_LINEAR_INIT).unpack_from
Expand Down Expand Up @@ -686,7 +686,7 @@

FMT_CONVERSION_RAT = FMT_CONVERSION_NONE + "6d"
CONVERSION_RAT_PACK = struct.Struct(FMT_CONVERSION_RAT).pack
KEYS_CONVERSION_RAT = KEYS_CONVERSION_NONE + ("P1", "P2", "P3", "P4", "P5", "P6")
KEYS_CONVERSION_RAT = (*KEYS_CONVERSION_NONE, "P1", "P2", "P3", "P4", "P5", "P6")

FMT_CONVERSION_RAT_INIT = "<4Q2B3H8d"

Expand Down
2 changes: 1 addition & 1 deletion src/asammdf/gui/dialogs/define_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def search(self, *args, text_widget=None):
result, pattern_window = dlg.result, dlg.pattern_window

if result:
self.trigger_channel.setText(list(result)[0])
self.trigger_channel.setText(next(iter(result)))

def show_definition(self, *args):
function = self.functions.currentText()
Expand Down
4 changes: 2 additions & 2 deletions src/asammdf/gui/dialogs/gps_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def search_latitude(self, *args):
result, pattern_window = dlg.result, dlg.pattern_window

if result:
self.latitude.setText(list(result)[0])
self.latitude.setText(next(iter(result)))

def search_longitude(self, *args):
dlg = AdvancedSearch(
Expand All @@ -70,4 +70,4 @@ def search_longitude(self, *args):
result, pattern_window = dlg.result, dlg.pattern_window

if result:
self.longitude.setText(list(result)[0])
self.longitude.setText(next(iter(result)))
2 changes: 1 addition & 1 deletion src/asammdf/gui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def compute_signal(
if found_numeric:
break

names = found_args + ["t"]
names = [*found_args, "t"]

triggering = description.get("triggering", "triggering_on_all")
if triggering == "triggering_on_all":
Expand Down
4 changes: 2 additions & 2 deletions src/asammdf/gui/widgets/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ def raster_search(self, event):
dlg.exec_()
result = dlg.result
if result:
name = list(result)[0]
name = next(iter(result))
self.raster_channel.setCurrentText(name)

def filter_changed(self, item, column):
Expand Down Expand Up @@ -1780,7 +1780,7 @@ def load_filter_list(self, event=None, file_name=None):
else:
return
else:
channels = list(info.values())[0]
channels = next(iter(info.values()))

channels = [name.split(";")[0] for name in channels]

Expand Down
4 changes: 2 additions & 2 deletions src/asammdf/gui/widgets/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@ def load_filter_list(self, event=None, file_name=None):
else:
return
else:
channels = list(info.values())[0]
channels = next(iter(info.values()))

channels = [name.split(";")[0] for name in channels]

Expand Down Expand Up @@ -3009,7 +3009,7 @@ def raster_search(self, event):
dlg.exec_()
result = dlg.result
if result:
name = list(result)[0]
name = next(iter(result))
self.raster_channel.setCurrentText(name)

def filter_changed(self, item, column):
Expand Down
2 changes: 1 addition & 1 deletion src/asammdf/gui/widgets/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def open_menu(self, position):
widget = self.itemWidget(item)
if item in selected_items:
uuids.append(widget.uuid)
self.set_time_offset.emit([absolute, offset] + uuids)
self.set_time_offset.emit([absolute, offset, *uuids])

elif action.text() == "Delete (Del)":
event = QtGui.QKeyEvent(
Expand Down
2 changes: 1 addition & 1 deletion src/asammdf/gui/widgets/mdi_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -3535,7 +3535,7 @@ def _load_tabular_window(self, window_info):
w.setWindowTitle(generate_window_title(w, window_info["type"], window_info["title"]))

filter_count = 0
available_columns = [signals.index.name] + list(signals.columns)
available_columns = [signals.index.name, *list(signals.columns)]
for filter_info in window_info["configuration"]["filters"]:
if filter_info["column"] in available_columns:
tabular.add_filter()
Expand Down
2 changes: 1 addition & 1 deletion src/asammdf/gui/widgets/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ def keyPressEvent(self, event):
if not selected_items:
return
else:
row = list(selected_items)[0]
row = next(iter(selected_items))
signal = self.backend.signals[row]

info = {
Expand Down
8 changes: 4 additions & 4 deletions src/asammdf/gui/widgets/python_highlighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class PythonHighlighter(QtGui.QSyntaxHighlighter):
builtins = dir(builtins)

# Python operators
operators = [
operators = (
"=",
# Comparison
"==",
Expand Down Expand Up @@ -82,17 +82,17 @@ class PythonHighlighter(QtGui.QSyntaxHighlighter):
"\~",
">>",
"<<",
]
)

# Python braces
braces = [
braces = (
"\{",
"\}",
"\(",
"\)",
"\[",
"\]",
]
)

def __init__(self, parent: QtGui.QTextDocument) -> None:
super().__init__(parent)
Expand Down
2 changes: 1 addition & 1 deletion src/asammdf/gui/widgets/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,7 @@ def open_menu(self):
if item.type() == ChannelsTreeItem.Channel:
uuids.append(item.uuid)

self.set_time_offset.emit([absolute, offset] + uuids)
self.set_time_offset.emit([absolute, offset, *uuids])

elif action_text == "Delete [Del]":
event = QtGui.QKeyEvent(
Expand Down
16 changes: 8 additions & 8 deletions src/asammdf/mdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,7 @@ def export(

for ch in grp.channels:
if use_display_names:
channel_name = list(ch.display_names)[0] if ch.display_names else ch.name
channel_name = next(iter(ch.display_names)) if ch.display_names else ch.name
else:
channel_name = ch.name

Expand Down Expand Up @@ -1498,7 +1498,7 @@ def export(

for j, sig in enumerate(channels):
if use_display_names:
name = list(sig.display_names)[0] if sig.display_names else sig.name
name = next(iter(sig.display_names)) if sig.display_names else sig.name
else:
name = sig.name
name = name.replace("\\", "_").replace("/", "_")
Expand Down Expand Up @@ -1689,7 +1689,7 @@ def export(
ch = self.groups[gp_index].channels[ch_index]

if use_display_names:
channel_name = list(ch.display_names)[0] if ch.display_names else ch.name
channel_name = next(iter(ch.display_names)) if ch.display_names else ch.name
else:
channel_name = ch.name

Expand Down Expand Up @@ -1837,7 +1837,7 @@ def decompose(samples):
channel_name = master_name_template.format(i, "timestamps")
else:
if use_display_names:
channel_name = list(sig.display_names)[0] if sig.display_names else sig.name
channel_name = next(iter(sig.display_names)) if sig.display_names else sig.name
else:
channel_name = sig.name
channel_name = channel_name_template.format(i, channel_name)
Expand Down Expand Up @@ -4111,7 +4111,7 @@ def iter_to_dataframe(
# byte arrays
if len(sig.samples.shape) > 1:
if use_display_names:
channel_name = list(sig.display_names)[0] if sig.display_names else sig.name
channel_name = next(iter(sig.display_names)) if sig.display_names else sig.name
else:
channel_name = sig.name

Expand Down Expand Up @@ -4139,7 +4139,7 @@ def iter_to_dataframe(
# scalars
else:
if use_display_names:
channel_name = list(sig.display_names)[0] if sig.display_names else sig.name
channel_name = next(iter(sig.display_names)) if sig.display_names else sig.name
else:
channel_name = sig.name

Expand Down Expand Up @@ -4494,7 +4494,7 @@ def to_dataframe(
# byte arrays
if len(sig.samples.shape) > 1:
if use_display_names:
channel_name = list(sig.display_names)[0] if sig.display_names else sig.name
channel_name = next(iter(sig.display_names)) if sig.display_names else sig.name
else:
channel_name = sig.name

Expand Down Expand Up @@ -4522,7 +4522,7 @@ def to_dataframe(
# scalars
else:
if use_display_names:
channel_name = list(sig.display_names)[0] if sig.display_names else sig.name
channel_name = next(iter(sig.display_names)) if sig.display_names else sig.name
else:
channel_name = sig.name

Expand Down
3 changes: 2 additions & 1 deletion test/asammdf/gui/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class DragAndDrop
import shutil
import sys
import time
from typing import ClassVar
import unittest
from unittest import mock

Expand Down Expand Up @@ -52,7 +53,7 @@ class TestBase(unittest.TestCase):

resource = os.path.normpath(os.path.join(os.path.dirname(__file__), "resources"))
test_workspace = os.path.join(os.path.join(os.path.dirname(__file__), "test_workspace"))
patchers = []
patchers: ClassVar = []
# MockClass ErrorDialog
mc_ErrorDialog = None

Expand Down
12 changes: 6 additions & 6 deletions test/test_CAN_bus_loogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def test_obd_extract(self):
for file in temp_dir.iterdir():
print(file)

mdf = [input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".mf4"][0]
mdf = next(input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".mf4")

mdf = MDF(mdf)

dbc = [input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".dbc"][0]
dbc = next(input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".dbc")

signals = [input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".npy"]

Expand All @@ -60,11 +60,11 @@ def test_j1939_extract(self):

temp_dir = Path(TestCANBusLogging.tempdir_j1939.name)

mdf = [input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".mf4"][0]
mdf = next(input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".mf4")

mdf = MDF(mdf)

dbc = [input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".dbc"][0]
dbc = next(input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".dbc")

signals = [input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".npy"]

Expand All @@ -83,11 +83,11 @@ def test_j1939_get_can_signal(self):

temp_dir = Path(TestCANBusLogging.tempdir_j1939.name)

mdf = [input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".mf4"][0]
mdf = next(input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".mf4")

mdf = MDF(mdf)

dbc = [input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".dbc"][0]
dbc = next(input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".dbc")

signals = [input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".npy"]

Expand Down

0 comments on commit 3cd531a

Please sign in to comment.