From afcf92c351d381608960b4026baf1d8a5f8c9225 Mon Sep 17 00:00:00 2001 From: MattWoodhead Date: Thu, 1 Jun 2023 22:57:04 +0100 Subject: [PATCH 1/5] Update mf4.py --- can/io/mf4.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/can/io/mf4.py b/can/io/mf4.py index 215543e9f..f8e370dd1 100644 --- a/can/io/mf4.py +++ b/can/io/mf4.py @@ -113,8 +113,7 @@ def __init__( if kwargs.get("append", False): raise ValueError( - f"{self.__class__.__name__} is currently not equipped to " - f"append messages to an existing file." + f"{self.__class__.__name__} is currently not equipped to " f"append messages to an existing file." ) super().__init__(file, mode="w+b") @@ -135,9 +134,7 @@ def __init__( else: attachment = None - acquisition_source = SourceInformation( - source_type=SOURCE_BUS, bus_type=BUS_TYPE_CAN - ) + acquisition_source = SourceInformation(source_type=SOURCE_BUS, bus_type=BUS_TYPE_CAN) # standard frames group self._mdf.append( @@ -272,7 +269,11 @@ class MF4Reader(BinaryIOMessageReader): The MF4Reader only supports MF4 files that were recorded with python-can. """ - def __init__(self, file: Union[StringPathLike, BinaryIO]) -> None: + def __init__( + self, + file: Union[StringPathLike, BinaryIO], + **kwargs: Any, + ) -> None: """ :param file: a path-like object or as file-like object to read from If this is a file-like object, is has to be opened in @@ -296,10 +297,7 @@ def __init__(self, file: Union[StringPathLike, BinaryIO]) -> None: masters = [self._mdf.get_master(i) for i in range(3)] - masters = [ - np.core.records.fromarrays((master, np.ones(len(master)) * i)) - for i, master in enumerate(masters) - ] + masters = [np.core.records.fromarrays((master, np.ones(len(master)) * i)) for i, master in enumerate(masters)] self.masters = np.sort(np.concatenate(masters)) From 8dbe8631db89f2cf7e701f060e4bfadebb917f29 Mon Sep 17 00:00:00 2001 From: MattWoodhead Date: Thu, 1 Jun 2023 21:57:36 +0000 Subject: [PATCH 2/5] Format code with black --- can/io/mf4.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/can/io/mf4.py b/can/io/mf4.py index f8e370dd1..c7e71e816 100644 --- a/can/io/mf4.py +++ b/can/io/mf4.py @@ -113,7 +113,8 @@ def __init__( if kwargs.get("append", False): raise ValueError( - f"{self.__class__.__name__} is currently not equipped to " f"append messages to an existing file." + f"{self.__class__.__name__} is currently not equipped to " + f"append messages to an existing file." ) super().__init__(file, mode="w+b") @@ -134,7 +135,9 @@ def __init__( else: attachment = None - acquisition_source = SourceInformation(source_type=SOURCE_BUS, bus_type=BUS_TYPE_CAN) + acquisition_source = SourceInformation( + source_type=SOURCE_BUS, bus_type=BUS_TYPE_CAN + ) # standard frames group self._mdf.append( @@ -297,7 +300,10 @@ def __init__( masters = [self._mdf.get_master(i) for i in range(3)] - masters = [np.core.records.fromarrays((master, np.ones(len(master)) * i)) for i, master in enumerate(masters)] + masters = [ + np.core.records.fromarrays((master, np.ones(len(master)) * i)) + for i, master in enumerate(masters) + ] self.masters = np.sort(np.concatenate(masters)) From acfa56972eacef450267960c7b3ae25d726836d1 Mon Sep 17 00:00:00 2001 From: MattWoodhead Date: Thu, 1 Jun 2023 23:03:32 +0100 Subject: [PATCH 3/5] Update trc.py --- can/io/trc.py | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/can/io/trc.py b/can/io/trc.py index f116bdc04..9eca3287d 100644 --- a/can/io/trc.py +++ b/can/io/trc.py @@ -11,7 +11,7 @@ import os from datetime import datetime, timedelta, timezone from enum import Enum -from typing import Callable, Dict, Generator, List, Optional, TextIO, Union +from typing import Any, Callable, Dict, Generator, List, Optional, TextIO, Union from ..message import Message from ..typechecking import StringPathLike @@ -49,6 +49,7 @@ class TRCReader(TextIOMessageReader): def __init__( self, file: Union[StringPathLike, TextIO], + **kwargs: Any, ) -> None: """ :param file: a path-like object or as file-like object to read from @@ -86,9 +87,9 @@ def _extract_header(self): elif line.startswith(";$STARTTIME"): logger.debug("TRCReader: Found start time '%s'", line) try: - self.start_time = datetime( - 1899, 12, 30, tzinfo=timezone.utc - ) + timedelta(days=float(line.split("=")[1])) + self.start_time = datetime(1899, 12, 30, tzinfo=timezone.utc) + timedelta( + days=float(line.split("=")[1]) + ) except IndexError: logger.debug("TRCReader: Failed to parse start time") elif line.startswith(";$COLUMNS"): @@ -112,9 +113,7 @@ def _extract_header(self): raise ValueError("File has no column information") if self.file_version == TRCFileVersion.UNKNOWN: - logger.info( - "TRCReader: No file version was found, so version 1.0 is assumed" - ) + logger.info("TRCReader: No file version was found, so version 1.0 is assumed") self._parse_cols = self._parse_msg_V1_0 elif self.file_version == TRCFileVersion.V1_0: self._parse_cols = self._parse_msg_V1_0 @@ -147,9 +146,7 @@ def _parse_msg_V1_1(self, cols: List[str]) -> Optional[Message]: msg = Message() if isinstance(self.start_time, datetime): - msg.timestamp = ( - self.start_time + timedelta(milliseconds=float(cols[1])) - ).timestamp() + msg.timestamp = (self.start_time + timedelta(milliseconds=float(cols[1]))).timestamp() else: msg.timestamp = float(cols[1]) / 1000 msg.arbitration_id = int(arbit_id, 16) @@ -175,18 +172,14 @@ def _parse_msg_V2_x(self, cols: List[str]) -> Optional[Message]: msg = Message() if isinstance(self.start_time, datetime): - msg.timestamp = ( - self.start_time + timedelta(milliseconds=float(cols[self.columns["O"]])) - ).timestamp() + msg.timestamp = (self.start_time + timedelta(milliseconds=float(cols[self.columns["O"]]))).timestamp() else: msg.timestamp = float(cols[1]) / 1000 msg.arbitration_id = int(cols[self.columns["I"]], 16) msg.is_extended_id = len(cols[self.columns["I"]]) > 4 msg.channel = int(cols[bus]) if bus is not None else 1 msg.dlc = dlc - msg.data = bytearray( - [int(cols[i + self.columns["D"]], 16) for i in range(length)] - ) + msg.data = bytearray([int(cols[i + self.columns["D"]], 16) for i in range(length)]) msg.is_rx = cols[self.columns["d"]] == "Rx" msg.is_fd = type_ in ["FD", "FB", "FE", "BI"] msg.bitrate_switch = type_ in ["FB", " FE"] @@ -256,15 +249,14 @@ class TRCWriter(TextIOMessageWriter): file: TextIO first_timestamp: Optional[float] - FORMAT_MESSAGE = ( - "{msgnr:>7} {time:13.3f} DT {channel:>2} {id:>8} {dir:>2} - {dlc:<4} {data}" - ) + FORMAT_MESSAGE = "{msgnr:>7} {time:13.3f} DT {channel:>2} {id:>8} {dir:>2} - {dlc:<4} {data}" FORMAT_MESSAGE_V1_0 = "{msgnr:>6}) {time:7.0f} {id:>8} {dlc:<1} {data}" def __init__( self, file: Union[StringPathLike, TextIO], channel: int = 1, + **kwargs: Any, ) -> None: """ :param file: a path-like object or as file-like object to write to From 4726eb6c2f35f8bb8a03680727e1744170a5eb7b Mon Sep 17 00:00:00 2001 From: MattWoodhead Date: Thu, 1 Jun 2023 22:05:02 +0000 Subject: [PATCH 4/5] Format code with black --- can/io/trc.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/can/io/trc.py b/can/io/trc.py index 9eca3287d..ccf122d57 100644 --- a/can/io/trc.py +++ b/can/io/trc.py @@ -87,9 +87,9 @@ def _extract_header(self): elif line.startswith(";$STARTTIME"): logger.debug("TRCReader: Found start time '%s'", line) try: - self.start_time = datetime(1899, 12, 30, tzinfo=timezone.utc) + timedelta( - days=float(line.split("=")[1]) - ) + self.start_time = datetime( + 1899, 12, 30, tzinfo=timezone.utc + ) + timedelta(days=float(line.split("=")[1])) except IndexError: logger.debug("TRCReader: Failed to parse start time") elif line.startswith(";$COLUMNS"): @@ -113,7 +113,9 @@ def _extract_header(self): raise ValueError("File has no column information") if self.file_version == TRCFileVersion.UNKNOWN: - logger.info("TRCReader: No file version was found, so version 1.0 is assumed") + logger.info( + "TRCReader: No file version was found, so version 1.0 is assumed" + ) self._parse_cols = self._parse_msg_V1_0 elif self.file_version == TRCFileVersion.V1_0: self._parse_cols = self._parse_msg_V1_0 @@ -146,7 +148,9 @@ def _parse_msg_V1_1(self, cols: List[str]) -> Optional[Message]: msg = Message() if isinstance(self.start_time, datetime): - msg.timestamp = (self.start_time + timedelta(milliseconds=float(cols[1]))).timestamp() + msg.timestamp = ( + self.start_time + timedelta(milliseconds=float(cols[1])) + ).timestamp() else: msg.timestamp = float(cols[1]) / 1000 msg.arbitration_id = int(arbit_id, 16) @@ -172,14 +176,18 @@ def _parse_msg_V2_x(self, cols: List[str]) -> Optional[Message]: msg = Message() if isinstance(self.start_time, datetime): - msg.timestamp = (self.start_time + timedelta(milliseconds=float(cols[self.columns["O"]]))).timestamp() + msg.timestamp = ( + self.start_time + timedelta(milliseconds=float(cols[self.columns["O"]])) + ).timestamp() else: msg.timestamp = float(cols[1]) / 1000 msg.arbitration_id = int(cols[self.columns["I"]], 16) msg.is_extended_id = len(cols[self.columns["I"]]) > 4 msg.channel = int(cols[bus]) if bus is not None else 1 msg.dlc = dlc - msg.data = bytearray([int(cols[i + self.columns["D"]], 16) for i in range(length)]) + msg.data = bytearray( + [int(cols[i + self.columns["D"]], 16) for i in range(length)] + ) msg.is_rx = cols[self.columns["d"]] == "Rx" msg.is_fd = type_ in ["FD", "FB", "FE", "BI"] msg.bitrate_switch = type_ in ["FB", " FE"] @@ -249,7 +257,9 @@ class TRCWriter(TextIOMessageWriter): file: TextIO first_timestamp: Optional[float] - FORMAT_MESSAGE = "{msgnr:>7} {time:13.3f} DT {channel:>2} {id:>8} {dir:>2} - {dlc:<4} {data}" + FORMAT_MESSAGE = ( + "{msgnr:>7} {time:13.3f} DT {channel:>2} {id:>8} {dir:>2} - {dlc:<4} {data}" + ) FORMAT_MESSAGE_V1_0 = "{msgnr:>6}) {time:7.0f} {id:>8} {dlc:<1} {data}" def __init__( From 4acb22a241c113f6fa39990f085efca23744b883 Mon Sep 17 00:00:00 2001 From: MattWoodhead Date: Thu, 1 Jun 2023 23:19:45 +0100 Subject: [PATCH 5/5] Update ci.yml Remove pylint specs for directories and files that no longer exist. --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9633398e3..686a5d77b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -103,9 +103,7 @@ jobs: pylint --rcfile=.pylintrc \ can/**.py \ can/io \ - setup.py \ doc/conf.py \ - scripts/**.py \ examples/**.py \ can/interfaces/socketcan