Skip to content

Commit afb1204

Browse files
authored
Update contribution guide, move all checks to tox (#1960)
* docs: remove unused extras, use py3.13 * move all checks to tox, use uv in CI * update contribution guidelines * minor type annotation fixes * add missing `install` cmd * disable free-threaded tests, TestThreadSafeBus::test_send_periodic_duration is flaky * update docs as requested by review --------- Co-authored-by: zariiii9003 <[email protected]>
1 parent 5547413 commit afb1204

File tree

14 files changed

+309
-217
lines changed

14 files changed

+309
-217
lines changed

.github/workflows/ci.yml

Lines changed: 33 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,28 @@ env:
1212
jobs:
1313
test:
1414
runs-on: ${{ matrix.os }}
15-
continue-on-error: ${{ matrix.experimental }} # See: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idcontinue-on-error
1615
strategy:
1716
matrix:
1817
os: [ubuntu-latest, macos-latest, windows-latest]
19-
experimental: [false]
20-
python-version: [
21-
"3.9",
22-
"3.10",
23-
"3.11",
24-
"3.12",
25-
"3.13",
26-
"pypy-3.9",
27-
"pypy-3.10",
18+
env: [
19+
"py39",
20+
"py310",
21+
"py311",
22+
"py312",
23+
"py313",
24+
"py314",
25+
# "py313t",
26+
# "py314t",
27+
"pypy310",
28+
"pypy311",
2829
]
2930
fail-fast: false
3031
steps:
3132
- uses: actions/checkout@v4
32-
- name: Set up Python ${{ matrix.python-version }}
33-
uses: actions/setup-python@v5
34-
with:
35-
python-version: ${{ matrix.python-version }}
36-
allow-prereleases: true
37-
- name: Install dependencies
38-
run: |
39-
python -m pip install --upgrade pip
40-
pip install tox
33+
- name: Install uv
34+
uses: astral-sh/setup-uv@v6
35+
- name: Install tox
36+
run: uv tool install tox --with tox-uv
4137
- name: Setup SocketCAN
4238
if: ${{ matrix.os == 'ubuntu-latest' }}
4339
run: |
@@ -46,11 +42,11 @@ jobs:
4642
sudo ./test/open_vcan.sh
4743
- name: Test with pytest via tox
4844
run: |
49-
tox -e gh
45+
tox -e ${{ matrix.env }}
5046
env:
5147
# SocketCAN tests currently fail with PyPy because it does not support raw CAN sockets
5248
# See: https://foss.heptapod.net/pypy/pypy/-/issues/3809
53-
TEST_SOCKETCAN: "${{ matrix.os == 'ubuntu-latest' && ! startsWith(matrix.python-version, 'pypy' ) }}"
49+
TEST_SOCKETCAN: "${{ matrix.os == 'ubuntu-latest' && ! startsWith(matrix.env, 'pypy' ) }}"
5450
- name: Coveralls Parallel
5551
uses: coverallsapp/github-action@v2
5652
with:
@@ -73,69 +69,25 @@ jobs:
7369
runs-on: ubuntu-latest
7470
steps:
7571
- uses: actions/checkout@v4
76-
- name: Set up Python
77-
uses: actions/setup-python@v5
78-
with:
79-
python-version: "3.13"
80-
- name: Install dependencies
81-
run: |
82-
python -m pip install --upgrade pip
83-
pip install --group lint -e .
84-
- name: mypy 3.9
85-
run: |
86-
mypy --python-version 3.9 .
87-
- name: mypy 3.10
72+
- name: Install uv
73+
uses: astral-sh/setup-uv@v6
74+
- name: Install tox
75+
run: uv tool install tox --with tox-uv
76+
- name: Run linters
8877
run: |
89-
mypy --python-version 3.10 .
90-
- name: mypy 3.11
78+
tox -e lint
79+
- name: Run type checker
9180
run: |
92-
mypy --python-version 3.11 .
93-
- name: mypy 3.12
94-
run: |
95-
mypy --python-version 3.12 .
96-
- name: mypy 3.13
97-
run: |
98-
mypy --python-version 3.13 .
99-
- name: ruff
100-
run: |
101-
ruff check can
102-
- name: pylint
103-
run: |
104-
pylint \
105-
can/**.py \
106-
can/io \
107-
doc/conf.py \
108-
examples/**.py \
109-
can/interfaces/socketcan
110-
111-
format:
112-
runs-on: ubuntu-latest
113-
steps:
114-
- uses: actions/checkout@v4
115-
- name: Set up Python
116-
uses: actions/setup-python@v5
117-
with:
118-
python-version: "3.10"
119-
- name: Install dependencies
120-
run: |
121-
python -m pip install --upgrade pip
122-
pip install --group lint
123-
- name: Code Format Check with Black
124-
run: |
125-
black --check --verbose .
81+
tox -e type
12682
12783
docs:
12884
runs-on: ubuntu-latest
12985
steps:
13086
- uses: actions/checkout@v4
131-
- name: Set up Python
132-
uses: actions/setup-python@v5
133-
with:
134-
python-version: "3.12"
135-
- name: Install dependencies
136-
run: |
137-
python -m pip install --upgrade pip
138-
pip install tox
87+
- name: Install uv
88+
uses: astral-sh/setup-uv@v6
89+
- name: Install tox
90+
run: uv tool install tox --with tox-uv
13991
- name: Build documentation
14092
run: |
14193
tox -e docs
@@ -147,14 +99,12 @@ jobs:
14799
- uses: actions/checkout@v4
148100
with:
149101
fetch-depth: 0 # fetch tags for setuptools-scm
150-
- name: Set up Python
151-
uses: actions/setup-python@v5
152-
with:
153-
python-version: "3.10"
102+
- name: Install uv
103+
uses: astral-sh/setup-uv@v6
154104
- name: Build wheel and sdist
155-
run: pipx run build
105+
run: uvx --from build pyproject-build --installer uv
156106
- name: Check build artifacts
157-
run: pipx run twine check --strict dist/*
107+
run: uvx twine check --strict dist/*
158108
- name: Save artifacts
159109
uses: actions/upload-artifact@v4
160110
with:

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ __pycache__/
1818
# Distribution / packaging
1919
.Python
2020
env/
21-
venv/
21+
.venv*/
22+
venv*/
2223
build/
2324
develop-eggs/
2425
dist/

.readthedocs.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ version: 2
99
build:
1010
os: ubuntu-22.04
1111
tools:
12-
python: "3.12"
12+
python: "3.13"
1313
jobs:
1414
post_install:
1515
- pip install --group docs
@@ -31,6 +31,3 @@ python:
3131
extra_requirements:
3232
- canalystii
3333
- gs-usb
34-
- mf4
35-
- remote
36-
- serial

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Please read the [Development - Contributing](https://python-can.readthedocs.io/en/stable/development.html#contributing) guidelines in the documentation site.
1+
Please read the [Development - Contributing](https://python-can.readthedocs.io/en/main/development.html#contributing) guidelines in the documentation site.

can/bus.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from time import time
1212
from types import TracebackType
1313
from typing import (
14-
Any,
1514
Callable,
1615
Optional,
1716
Union,
@@ -69,7 +68,7 @@ class BusABC(metaclass=ABCMeta):
6968
@abstractmethod
7069
def __init__(
7170
self,
72-
channel: Any,
71+
channel: Optional[can.typechecking.Channel],
7372
can_filters: Optional[can.typechecking.CanFilters] = None,
7473
**kwargs: object,
7574
):

can/interfaces/virtual.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,18 @@
1212
from copy import deepcopy
1313
from random import randint
1414
from threading import RLock
15-
from typing import TYPE_CHECKING, Any, Optional
15+
from typing import Any, Optional
1616

1717
from can import CanOperationError
1818
from can.bus import BusABC, CanProtocol
1919
from can.message import Message
20-
from can.typechecking import AutoDetectedConfig
20+
from can.typechecking import AutoDetectedConfig, Channel
2121

2222
logger = logging.getLogger(__name__)
2323

2424

2525
# Channels are lists of queues, one for each connection
26-
if TYPE_CHECKING:
27-
# https://mypy.readthedocs.io/en/stable/runtime_troubles.html#using-classes-that-are-generic-in-stubs-but-not-at-runtime
28-
channels: dict[Optional[Any], list[queue.Queue[Message]]] = {}
29-
else:
30-
channels = {}
26+
channels: dict[Optional[Channel], list[queue.Queue[Message]]] = {}
3127
channels_lock = RLock()
3228

3329

@@ -58,7 +54,7 @@ class VirtualBus(BusABC):
5854

5955
def __init__(
6056
self,
61-
channel: Any = None,
57+
channel: Optional[Channel] = None,
6258
receive_own_messages: bool = False,
6359
rx_queue_size: int = 0,
6460
preserve_timestamps: bool = False,

can/io/mf4.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ def file_size(self) -> int:
186186
"""Return an estimate of the current file size in bytes."""
187187
# TODO: find solution without accessing private attributes of asammdf
188188
return cast(
189-
"int", self._mdf._tempfile.tell() # pylint: disable=protected-access
189+
"int",
190+
self._mdf._tempfile.tell(), # pylint: disable=protected-access,no-member
190191
)
191192

192193
def stop(self) -> None:

doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
("py:class", "~P1"),
139139
# intersphinx fails to reference some builtins
140140
("py:class", "asyncio.events.AbstractEventLoop"),
141-
("py:class", "_thread.allocate_lock"),
141+
("py:class", "_thread.lock"),
142142
]
143143

144144
# mock windows specific attributes

0 commit comments

Comments
 (0)