Skip to content

Commit 6058ab9

Browse files
authored
Use dependency groups for docs/lint/test (#1945)
* use dependency groups for docs/lint/test --------- Co-authored-by: zariiii9003 <[email protected]>
1 parent c46d3ea commit 6058ab9

File tree

12 files changed

+94
-46
lines changed

12 files changed

+94
-46
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ jobs:
7979
- name: Install dependencies
8080
run: |
8181
python -m pip install --upgrade pip
82-
pip install -e .[lint]
82+
pip install --group lint -e .
8383
- name: mypy 3.9
8484
run: |
8585
mypy --python-version 3.9 .
@@ -92,6 +92,9 @@ jobs:
9292
- name: mypy 3.12
9393
run: |
9494
mypy --python-version 3.12 .
95+
- name: mypy 3.13
96+
run: |
97+
mypy --python-version 3.13 .
9598
- name: ruff
9699
run: |
97100
ruff check can
@@ -115,7 +118,7 @@ jobs:
115118
- name: Install dependencies
116119
run: |
117120
python -m pip install --upgrade pip
118-
pip install -e .[lint]
121+
pip install --group lint
119122
- name: Code Format Check with Black
120123
run: |
121124
black --check --verbose .

.readthedocs.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ build:
1010
os: ubuntu-22.04
1111
tools:
1212
python: "3.12"
13+
jobs:
14+
post_install:
15+
- pip install --group docs
1316

1417
# Build documentation in the docs/ directory with Sphinx
1518
sphinx:
@@ -23,10 +26,11 @@ formats:
2326
# Optionally declare the Python requirements required to build your docs
2427
python:
2528
install:
26-
- requirements: doc/doc-requirements.txt
2729
- method: pip
2830
path: .
2931
extra_requirements:
3032
- canalystii
31-
- gs_usb
33+
- gs-usb
3234
- mf4
35+
- remote
36+
- serial

can/interfaces/udp_multicast/bus.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from can import BusABC, CanProtocol
1212
from can.typechecking import AutoDetectedConfig
1313

14-
from .utils import check_msgpack_installed, pack_message, unpack_message
14+
from .utils import is_msgpack_installed, pack_message, unpack_message
1515

1616
ioctl_supported = True
1717

@@ -104,7 +104,7 @@ def __init__(
104104
fd: bool = True,
105105
**kwargs,
106106
) -> None:
107-
check_msgpack_installed()
107+
is_msgpack_installed()
108108

109109
if receive_own_messages:
110110
raise can.CanInterfaceNotImplementedError(

can/interfaces/udp_multicast/utils.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,22 @@
1313
msgpack = None
1414

1515

16-
def check_msgpack_installed() -> None:
17-
"""Raises a :class:`can.CanInterfaceNotImplementedError` if `msgpack` is not installed."""
16+
def is_msgpack_installed(raise_exception: bool = True) -> bool:
17+
"""Check whether the ``msgpack`` module is installed.
18+
19+
:param raise_exception:
20+
If True, raise a :class:`can.CanInterfaceNotImplementedError` when ``msgpack`` is not installed.
21+
If False, return False instead.
22+
:return:
23+
True if ``msgpack`` is installed, False otherwise.
24+
:raises can.CanInterfaceNotImplementedError:
25+
If ``msgpack`` is not installed and ``raise_exception`` is True.
26+
"""
1827
if msgpack is None:
19-
raise CanInterfaceNotImplementedError("msgpack not installed")
28+
if raise_exception:
29+
raise CanInterfaceNotImplementedError("msgpack not installed")
30+
return False
31+
return True
2032

2133

2234
def pack_message(message: Message) -> bytes:
@@ -25,7 +37,7 @@ def pack_message(message: Message) -> bytes:
2537
2638
:param message: the message to be packed
2739
"""
28-
check_msgpack_installed()
40+
is_msgpack_installed()
2941
as_dict = {
3042
"timestamp": message.timestamp,
3143
"arbitration_id": message.arbitration_id,
@@ -58,7 +70,7 @@ def unpack_message(
5870
:raise ValueError: if `check` is true and the message metadata is invalid in some way
5971
:raise Exception: if there was another problem while unpacking
6072
"""
61-
check_msgpack_installed()
73+
is_msgpack_installed()
6274
as_dict = msgpack.unpackb(data, raw=False)
6375
if replace is not None:
6476
as_dict.update(replace)

can/listener.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ class AsyncBufferedReader(
136136
"""
137137

138138
def __init__(self, **kwargs: Any) -> None:
139+
self._is_stopped: bool = False
139140
self.buffer: asyncio.Queue[Message]
140141

141142
if "loop" in kwargs:
@@ -150,7 +151,6 @@ def __init__(self, **kwargs: Any) -> None:
150151
return
151152

152153
self.buffer = asyncio.Queue()
153-
self._is_stopped: bool = False
154154

155155
def on_message_received(self, msg: Message) -> None:
156156
"""Append a message to the buffer.

doc/development.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ The documentation can be built with::
5252

5353
The linters can be run with::
5454

55-
pip install -e .[lint]
55+
pip install --group lint -e .
5656
black --check can
5757
mypy can
5858
ruff check can

doc/doc-requirements.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

doc/interfaces/udp_multicast.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ sufficiently reliable for this interface to function properly.
2222
Please refer to the `Bus class documentation`_ below for configuration options and useful resources
2323
for specifying multicast IP addresses.
2424

25+
Installation
26+
-------------------
27+
28+
The Multicast IP Interface depends on the **msgpack** python library,
29+
which is automatically installed with the `multicast` extra keyword::
30+
31+
$ pip install python-can[multicast]
32+
33+
2534
Supported Platforms
2635
-------------------
2736

pyproject.toml

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ dependencies = [
1111
"wrapt~=1.10",
1212
"packaging >= 23.1",
1313
"typing_extensions>=3.10.0.0",
14-
"msgpack~=1.1.0",
1514
]
1615
requires-python = ">=3.9"
1716
license = { text = "LGPL v3" }
@@ -58,20 +57,14 @@ repository = "https://github.com/hardbyte/python-can"
5857
changelog = "https://github.com/hardbyte/python-can/blob/develop/CHANGELOG.md"
5958

6059
[project.optional-dependencies]
61-
lint = [
62-
"pylint==3.2.*",
63-
"ruff==0.11.12",
64-
"black==25.1.*",
65-
"mypy==1.16.*",
66-
]
6760
pywin32 = ["pywin32>=305; platform_system == 'Windows' and platform_python_implementation == 'CPython'"]
6861
seeedstudio = ["pyserial>=3.0"]
6962
serial = ["pyserial~=3.0"]
7063
neovi = ["filelock", "python-ics>=2.12"]
7164
canalystii = ["canalystii>=0.1.0"]
7265
cantact = ["cantact>=0.0.7"]
7366
cvector = ["python-can-cvector"]
74-
gs_usb = ["gs_usb>=0.2.1"]
67+
gs-usb = ["gs-usb>=0.2.1"]
7568
nixnet = ["nixnet>=0.3.2"]
7669
pcan = ["uptime~=3.0.1"]
7770
remote = ["python-can-remote"]
@@ -82,6 +75,32 @@ viewer = [
8275
"windows-curses; platform_system == 'Windows' and platform_python_implementation=='CPython'"
8376
]
8477
mf4 = ["asammdf>=6.0.0"]
78+
multicast = ["msgpack~=1.1.0"]
79+
80+
[dependency-groups]
81+
docs = [
82+
"sphinx>=5.2.3",
83+
"sphinxcontrib-programoutput",
84+
"sphinx-inline-tabs",
85+
"sphinx-copybutton",
86+
"furo",
87+
]
88+
lint = [
89+
"pylint==3.2.*",
90+
"ruff==0.11.12",
91+
"black==25.1.*",
92+
"mypy==1.16.*",
93+
]
94+
test = [
95+
"pytest==8.3.*",
96+
"pytest-timeout==2.1.*",
97+
"coveralls==3.3.1",
98+
"pytest-cov==4.0.0",
99+
"coverage==6.5.0",
100+
"hypothesis~=6.35.0",
101+
"pyserial~=3.5",
102+
"parameterized~=0.8",
103+
]
85104

86105
[tool.setuptools.dynamic]
87106
readme = { file = "README.rst" }

test/back2back_test.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414
import can
1515
from can import CanInterfaceNotImplementedError
1616
from can.interfaces.udp_multicast import UdpMulticastBus
17+
from can.interfaces.udp_multicast.utils import is_msgpack_installed
1718

1819
from .config import (
1920
IS_CI,
2021
IS_OSX,
2122
IS_PYPY,
22-
IS_TRAVIS,
23-
IS_UNIX,
24-
IS_WINDOWS,
2523
TEST_CAN_FD,
2624
TEST_INTERFACE_SOCKETCAN,
2725
)
@@ -307,6 +305,10 @@ class BasicTestSocketCan(Back2BackTestCase):
307305
IS_CI and IS_OSX,
308306
"not supported for macOS CI",
309307
)
308+
@unittest.skipUnless(
309+
is_msgpack_installed(raise_exception=False),
310+
"msgpack not installed",
311+
)
310312
class BasicTestUdpMulticastBusIPv4(Back2BackTestCase):
311313
INTERFACE_1 = "udp_multicast"
312314
CHANNEL_1 = UdpMulticastBus.DEFAULT_GROUP_IPv4
@@ -324,6 +326,10 @@ def test_unique_message_instances(self):
324326
IS_CI and IS_OSX,
325327
"not supported for macOS CI",
326328
)
329+
@unittest.skipUnless(
330+
is_msgpack_installed(raise_exception=False),
331+
"msgpack not installed",
332+
)
327333
class BasicTestUdpMulticastBusIPv6(Back2BackTestCase):
328334
HOST_LOCAL_MCAST_GROUP_IPv6 = "ff11:7079:7468:6f6e:6465:6d6f:6d63:6173"
329335

0 commit comments

Comments
 (0)