Skip to content

Commit 88a0dbf

Browse files
authored
activate ruff pycodestyle checks (#1602)
1 parent b291f80 commit 88a0dbf

File tree

6 files changed

+39
-51
lines changed

6 files changed

+39
-51
lines changed

can/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@
7676
"viewer",
7777
]
7878

79-
log = logging.getLogger("can")
80-
81-
rc: Dict[str, Any] = {}
82-
8379
from . import typechecking # isort:skip
8480
from . import util # isort:skip
8581
from . import broadcastmanager, interface
@@ -127,3 +123,7 @@
127123
from .notifier import Notifier
128124
from .thread_safe_bus import ThreadSafeBus
129125
from .util import set_logging_level
126+
127+
log = logging.getLogger("can")
128+
129+
rc: Dict[str, Any] = {}

can/interfaces/ixxat/canlib_vcinpl2.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import functools
1414
import logging
1515
import sys
16+
import time
1617
import warnings
1718
from typing import Callable, Optional, Sequence, Tuple, Union
1819

@@ -43,8 +44,6 @@
4344

4445
log = logging.getLogger("can.ixxat")
4546

46-
from time import perf_counter
47-
4847
# Hack to have vciFormatError as a free function, see below
4948
vciFormatError = None
5049

@@ -144,7 +143,7 @@ def __check_status(result, function, args):
144143
_canlib.map_symbol(
145144
"vciFormatError", None, (ctypes_HRESULT, ctypes.c_char_p, ctypes.c_uint32)
146145
)
147-
except:
146+
except ImportError:
148147
_canlib.map_symbol(
149148
"vciFormatErrorA", None, (ctypes_HRESULT, ctypes.c_char_p, ctypes.c_uint32)
150149
)
@@ -812,7 +811,7 @@ def _recv_internal(self, timeout):
812811
else:
813812
timeout_ms = int(timeout * 1000)
814813
remaining_ms = timeout_ms
815-
t0 = perf_counter()
814+
t0 = time.perf_counter()
816815

817816
while True:
818817
try:
@@ -861,7 +860,7 @@ def _recv_internal(self, timeout):
861860
log.warning("Unexpected message info type")
862861

863862
if t0 is not None:
864-
remaining_ms = timeout_ms - int((perf_counter() - t0) * 1000)
863+
remaining_ms = timeout_ms - int((time.perf_counter() - t0) * 1000)
865864
if remaining_ms < 0:
866865
break
867866

can/interfaces/socketcan/socketcan.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@
1717
import warnings
1818
from typing import Callable, Dict, List, Optional, Sequence, Tuple, Type, Union
1919

20+
import can
21+
from can import BusABC, CanProtocol, Message
22+
from can.broadcastmanager import (
23+
LimitedDurationCyclicSendTaskABC,
24+
ModifiableCyclicTaskABC,
25+
RestartableCyclicTaskABC,
26+
)
27+
from can.interfaces.socketcan import constants
28+
from can.interfaces.socketcan.utils import find_available_interfaces, pack_filters
29+
from can.typechecking import CanFilters
30+
2031
log = logging.getLogger(__name__)
2132
log_tx = log.getChild("tx")
2233
log_rx = log.getChild("rx")
@@ -30,18 +41,6 @@
3041
log.error("socket.CMSG_SPACE not available on this platform")
3142

3243

33-
import can
34-
from can import BusABC, CanProtocol, Message
35-
from can.broadcastmanager import (
36-
LimitedDurationCyclicSendTaskABC,
37-
ModifiableCyclicTaskABC,
38-
RestartableCyclicTaskABC,
39-
)
40-
from can.interfaces.socketcan import constants
41-
from can.interfaces.socketcan.utils import find_available_interfaces, pack_filters
42-
from can.typechecking import CanFilters
43-
44-
4544
# Setup BCM struct
4645
def bcm_header_factory(
4746
fields: List[Tuple[str, Union[Type[ctypes.c_uint32], Type[ctypes.c_long]]]],

can/interfaces/vector/canlib.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
Authors: Julien Grave <[email protected]>, Christian Sandberg
55
"""
66

7-
# Import Standard Python Modules
8-
# ==============================
97
import contextlib
108
import ctypes
119
import logging
@@ -26,19 +24,6 @@
2624
cast,
2725
)
2826

29-
WaitForSingleObject: Optional[Callable[[int, int], int]]
30-
INFINITE: Optional[int]
31-
try:
32-
# Try builtin Python 3 Windows API
33-
from _winapi import INFINITE, WaitForSingleObject # type: ignore
34-
35-
HAS_EVENTS = True
36-
except ImportError:
37-
WaitForSingleObject, INFINITE = None, None
38-
HAS_EVENTS = False
39-
40-
# Import Modules
41-
# ==============
4227
from can import (
4328
BitTiming,
4429
BitTimingFd,
@@ -57,22 +42,29 @@
5742
time_perfcounter_correlation,
5843
)
5944

60-
# Define Module Logger
61-
# ====================
62-
LOG = logging.getLogger(__name__)
63-
64-
# Import Vector API modules
65-
# =========================
6645
from . import xlclass, xldefine
6746
from .exceptions import VectorError, VectorInitializationError, VectorOperationError
6847

48+
LOG = logging.getLogger(__name__)
49+
6950
# Import safely Vector API module for Travis tests
7051
xldriver: Optional[ModuleType] = None
7152
try:
7253
from . import xldriver
7354
except Exception as exc:
7455
LOG.warning("Could not import vxlapi: %s", exc)
7556

57+
WaitForSingleObject: Optional[Callable[[int, int], int]]
58+
INFINITE: Optional[int]
59+
try:
60+
# Try builtin Python 3 Windows API
61+
from _winapi import INFINITE, WaitForSingleObject # type: ignore
62+
63+
HAS_EVENTS = True
64+
except ImportError:
65+
WaitForSingleObject, INFINITE = None, None
66+
HAS_EVENTS = False
67+
7668

7769
class VectorBus(BusABC):
7870
"""The CAN Bus implemented for the Vector interface."""

can/interfaces/vector/xldriver.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,15 @@
55
Authors: Julien Grave <[email protected]>, Christian Sandberg
66
"""
77

8-
# Import Standard Python Modules
9-
# ==============================
108
import ctypes
119
import logging
1210
import platform
1311

12+
from . import xlclass
1413
from .exceptions import VectorInitializationError, VectorOperationError
1514

16-
# Define Module Logger
17-
# ====================
1815
LOG = logging.getLogger(__name__)
1916

20-
# Vector XL API Definitions
21-
# =========================
22-
from . import xlclass
23-
2417
# Load Windows DLL
2518
DLL_NAME = "vxlapi64" if platform.architecture()[0] == "64bit" else "vxlapi"
2619
_xlapi_dll = ctypes.windll.LoadLibrary(DLL_NAME)

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ changelog = "https://github.com/hardbyte/python-can/blob/develop/CHANGELOG.md"
5959
[project.optional-dependencies]
6060
lint = [
6161
"pylint==2.17.*",
62-
"ruff==0.0.267",
62+
"ruff==0.0.269",
6363
"black==23.3.*",
6464
"mypy==1.3.*",
6565
]
@@ -131,6 +131,11 @@ select = [
131131
"F401", # unused-imports
132132
"UP", # pyupgrade
133133
"I", # isort
134+
"E", # pycodestyle errors
135+
"W", # pycodestyle warnings
136+
]
137+
ignore = [
138+
"E501", # Line too long
134139
]
135140

136141
[tool.ruff.isort]

0 commit comments

Comments
 (0)