Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/danielhrisca/asammdf
Browse files Browse the repository at this point in the history
…into development
  • Loading branch information
danielhrisca committed Nov 21, 2023
2 parents 3323b95 + bcc12ef commit f9b7419
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 50 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
repos:
- repo: https://github.com/ambv/black
rev: 23.10.0
rev: 23.11.0
hooks:
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: v0.1.2
rev: v0.1.6
hooks:
- id: ruff
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ skip = "pp* *_ppc64le *-musllinux* *_s390x" # skip pypy and irrelevant archite

[tool.ruff]
select = [
"B", # flake8-bugbear
"F", # pyflakes
"UP", # pyupgrade
"I", # isort
]
ignore = [
"B007", # unused-loop-control-variable
"F401", # unused-import
"F841", # unused-variable
]
Expand Down
1 change: 1 addition & 0 deletions run_black_and_ruff.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pip install -U black ruff && ^
ruff check --fix ./src && ^
ruff check --fix ./test && ^
ruff check --fix ./setup.py && ^
black --config pyproject.toml . && ^
black --config pyproject.toml asammdf.spec && ^
Expand Down
4 changes: 2 additions & 2 deletions src/asammdf/blocks/mdf_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ def _validate_channel_selection(
try:
grp = self.groups[gp_nr]
except IndexError:
raise MdfException("Group index out of range")
raise MdfException("Group index out of range") from None

try:
grp.channels[ch_nr]
except IndexError:
raise MdfException(f"Channel index out of range: {(name, group, index)}")
raise MdfException(f"Channel index out of range: {(name, group, index)}") from None
else:
if name not in self.channels_db:
raise MdfException(f'Channel "{name}" not found')
Expand Down
6 changes: 4 additions & 2 deletions src/asammdf/blocks/mdf_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ def __init__(
if not kwargs.get("__internal__", False):
raise MdfException("Always use the MDF class; do not use the class MDF3 directly")

# bind cache to instance to avoid memory leaks
self.determine_max_vlsd_sample_size = lru_cache(maxsize=1024 * 1024)(self._determine_max_vlsd_sample_size)

self._kwargs = kwargs
self._password = kwargs.get("password", None)
self.original_name = kwargs["original_name"]
Expand Down Expand Up @@ -3889,8 +3892,7 @@ def _yield_selected_signals(
def reload_header(self):
self.header = HeaderBlock(address=0x40, stream=self._file)

@lru_cache(maxsize=1024 * 1024)
def determine_max_vlsd_sample_size(self, group, index):
def _determine_max_vlsd_sample_size(self, group, index):
return 0


Expand Down
10 changes: 6 additions & 4 deletions src/asammdf/blocks/mdf_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ def __init__(
if not kwargs.get("__internal__", False):
raise MdfException("Always use the MDF class; do not use the class MDF4 directly")

# bind cache to instance to avoid memory leaks
self.determine_max_vlsd_sample_size = lru_cache(maxsize=1024 * 1024)(self._determine_max_vlsd_sample_size)
self.extract_attachment = lru_cache(maxsize=128)(self._extract_attachment)

self._kwargs = kwargs
self.original_name = kwargs["original_name"]
self.groups = []
Expand Down Expand Up @@ -6180,8 +6184,7 @@ def close(self) -> None:
self._dbc_cache.clear()
self.virtual_groups.clear()

@lru_cache(maxsize=128)
def extract_attachment(
def _extract_attachment(
self,
index: int | None = None,
password: str | bytes | None = None,
Expand Down Expand Up @@ -7765,8 +7768,7 @@ def _get_not_byte_aligned_data(self, data: bytes, group: Group, ch_nr: int) -> N
else:
return vals

@lru_cache(maxsize=1024 * 1024)
def determine_max_vlsd_sample_size(self, group, index):
def _determine_max_vlsd_sample_size(self, group, index):
group_index = group
channel_index = index
group = self.groups[group]
Expand Down
2 changes: 1 addition & 1 deletion src/asammdf/blocks/v4_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2325,7 +2325,7 @@ def __init__(self, **kwargs) -> None:
if self.id != b"##CC":
message = f'Expected "##CC" block @{hex(address)} but found "{self.id}"'
logger.exception(message)
raise MdfException(message)
raise MdfException(message) from None

block = stream.read(self.block_len - COMMON_SIZE)

Expand Down
8 changes: 4 additions & 4 deletions src/asammdf/gui/widgets/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,14 @@ def __init__(
self.mdf.append(df, units=units)
self.mdf.uuid = self.uuid
self.mdf.original_name = file_name
except:
except Exception as exc:
if progress:
progress.cancel()
print(format_exc())
raise Exception(
"Could not load CSV. The first line must contain the channel names. The seconds line "
"can optionally contain the channel units. The first column must be the time"
)
) from exc

else:
original_name = file_name
Expand Down Expand Up @@ -1795,7 +1795,7 @@ def extract_bus_logging(self, event):

file_name, _ = QtWidgets.QFileDialog.getSaveFileName(
self,
"Select output measurement file",
"Save as measurement file",
"",
f"{filter};;All files (*.*)",
filter,
Expand Down Expand Up @@ -2716,7 +2716,7 @@ def apply_processing(self, event):

file_name, _ = QtWidgets.QFileDialog.getSaveFileName(
self,
"Select output measurement file",
"Save as measurement file",
"",
f"{filter};;All files (*.*)",
default,
Expand Down
7 changes: 0 additions & 7 deletions src/asammdf/gui/widgets/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,13 +475,6 @@ def __init__(self, files=None, *args, **kwargs):
action.setShortcut(QtGui.QKeySequence("Ctrl+Shift+S"))
plot_actions.addAction(action)

icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(":/save.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
action = QtGui.QAction(icon, "{: <20}\tCtrl+Shift+S".format("Save all subplot channels"), menu)
action.triggered.connect(self.save_all_subplots)
action.setShortcut(QtGui.QKeySequence("Ctrl+Shift+S"))
plot_actions.addAction(action)

# channel shifting

channel_shift_actions = QtGui.QActionGroup(self)
Expand Down
6 changes: 4 additions & 2 deletions src/asammdf/gui/widgets/mdi_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ def get_origin_uuid(item):
def build_mime_from_config(
items,
mdf=None,
computed_origin_uuid=os.urandom(6).hex(),
computed_origin_uuid=None,
default_index=NOT_FOUND,
top=True,
has_flags=None,
):
if computed_origin_uuid is None:
computed_origin_uuid = os.urandom(6).hex()
if top:
rename_origin_uuid(items)

Expand Down Expand Up @@ -3872,7 +3874,7 @@ def remove_region(self, widget):

def save_all_subplots(self):
file_name, _ = QtWidgets.QFileDialog.getSaveFileName(
self, "Select output measurement file", "", "MDF version 4 files (*.mf4)"
self, "Save as measurement file", "", "MDF version 4 files (*.mf4)"
)

if file_name:
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 @@ -1604,7 +1604,7 @@ def keyPressEvent(self, event):
):
file_name, _ = QtWidgets.QFileDialog.getSaveFileName(
self,
"Select output measurement file",
"Save as measurement file",
"",
"MDF version 4 files (*.mf4)",
)
Expand Down
2 changes: 1 addition & 1 deletion src/asammdf/gui/widgets/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4622,7 +4622,7 @@ def keyPressEvent(self, event):
elif key == QtCore.Qt.Key.Key_S and modifier == QtCore.Qt.KeyboardModifier.ControlModifier:
file_name, _ = QtWidgets.QFileDialog.getSaveFileName(
self,
"Select output measurement file",
"Save as measurement file",
"",
"MDF version 4 files (*.mf4 *.mf4z)",
)
Expand Down
2 changes: 1 addition & 1 deletion src/asammdf/gui/widgets/tabular_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1696,7 +1696,7 @@ def keyPressEvent(self, event):
elif key == QtCore.Qt.Key.Key_S and modifiers == QtCore.Qt.KeyboardModifier.ControlModifier:
file_name, _ = QtWidgets.QFileDialog.getSaveFileName(
self,
"Select output measurement file",
"Save as measurement file",
"",
"MDF version 4 files (*.mf4)",
)
Expand Down
6 changes: 4 additions & 2 deletions src/asammdf/gui/widgets/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,9 @@ def __init__(
self.resolved_ranges = None
self.ranges = []

# bind cache to instance to avoid memory leaks
self.get_color_using_ranges = lru_cache(maxsize=1024)(self._get_color_using_ranges)

self._name = ""
self._count = 0
self._background_color = background_color
Expand Down Expand Up @@ -1893,8 +1896,7 @@ def format(self, format):
child = self.child(row)
child.set_fmt(format)

@lru_cache(maxsize=1024)
def get_color_using_ranges(self, value, pen=False):
def _get_color_using_ranges(self, value, pen=False):
return get_color_using_ranges(value, self.get_ranges(), self.signal.color, pen=pen)

def get_display_properties(self):
Expand Down
10 changes: 6 additions & 4 deletions src/asammdf/mdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,13 +445,13 @@ def get_scopes(event, events):
try:
dg_cntr, ch_cntr = ref
try:
(self.groups[dg_cntr].channels[ch_cntr])
self.groups[dg_cntr].channels[ch_cntr]
except:
event_valid = False
except TypeError:
dg_cntr = ref
try:
(self.groups[dg_cntr].channel_group)
self.groups[dg_cntr]
except:
event_valid = False
# ignore attachments for now
Expand Down Expand Up @@ -4660,12 +4660,14 @@ def extract_bus_logging(
"""
if ignore_invalid_signals is not None:
warn(
"The argument `ignore_invalid_signals` from the method `extract_bus_logging` is no longer used and will be removed in the future"
"The argument `ignore_invalid_signals` from the method `extract_bus_logging` is no longer used and will be removed in the future",
stacklevel=1,
)

if consolidated_j1939 is not None:
warn(
"The argument `consolidated_j1939` from the method `extract_bus_logging` is no longer used and will be removed in the future"
"The argument `consolidated_j1939` from the method `extract_bus_logging` is no longer used and will be removed in the future",
stacklevel=1,
)

if version is None:
Expand Down
3 changes: 3 additions & 0 deletions test/asammdf/gui/resources/functions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import numpy as np


def Function1(t=0):
sequence = range(10)
filtered = list(filter(lambda i: i % 2, sequence))
Expand Down
4 changes: 2 additions & 2 deletions test/asammdf/gui/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def mouseClick_WidgetItem(self, qitem):
elif isinstance(qitem, QtWidgets.QListWidgetItem):
widget = qitem.listWidget()
else:
raise "Not Implemented"
raise NotImplementedError
QtTest.QTest.mouseClick(
widget.viewport(),
QtCore.Qt.MouseButton.LeftButton,
Expand All @@ -135,7 +135,7 @@ def mouseDClick_WidgetItem(self, qitem):
elif isinstance(qitem, QtWidgets.QListWidgetItem):
widget = qitem.listWidget()
else:
raise "Not Implemented"
raise NotImplementedError
QtTest.QTest.mouseDClick(
widget.viewport(),
QtCore.Qt.MouseButton.LeftButton,
Expand Down
Loading

0 comments on commit f9b7419

Please sign in to comment.