Skip to content

Update contribution guide, move all checks to tox #1960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 33 additions & 83 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,28 @@ env:
jobs:
test:
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }} # See: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idcontinue-on-error
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
experimental: [false]
python-version: [
"3.9",
"3.10",
"3.11",
"3.12",
"3.13",
"pypy-3.9",
"pypy-3.10",
env: [
"py39",
"py310",
"py311",
"py312",
"py313",
"py314",
# "py313t",
# "py314t",
"pypy310",
"pypy311",
]
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox
- name: Install uv
uses: astral-sh/setup-uv@v6
- name: Install tox
run: uv tool install tox --with tox-uv
- name: Setup SocketCAN
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
Expand All @@ -46,11 +42,11 @@ jobs:
sudo ./test/open_vcan.sh
- name: Test with pytest via tox
run: |
tox -e gh
tox -e ${{ matrix.env }}
env:
# SocketCAN tests currently fail with PyPy because it does not support raw CAN sockets
# See: https://foss.heptapod.net/pypy/pypy/-/issues/3809
TEST_SOCKETCAN: "${{ matrix.os == 'ubuntu-latest' && ! startsWith(matrix.python-version, 'pypy' ) }}"
TEST_SOCKETCAN: "${{ matrix.os == 'ubuntu-latest' && ! startsWith(matrix.env, 'pypy' ) }}"
- name: Coveralls Parallel
uses: coverallsapp/github-action@v2
with:
Expand All @@ -73,69 +69,25 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --group lint -e .
- name: mypy 3.9
run: |
mypy --python-version 3.9 .
- name: mypy 3.10
- name: Install uv
uses: astral-sh/setup-uv@v6
- name: Install tox
run: uv tool install tox --with tox-uv
- name: Run linters
run: |
mypy --python-version 3.10 .
- name: mypy 3.11
tox -e lint
- name: Run type checker
run: |
mypy --python-version 3.11 .
- name: mypy 3.12
run: |
mypy --python-version 3.12 .
- name: mypy 3.13
run: |
mypy --python-version 3.13 .
- name: ruff
run: |
ruff check can
- name: pylint
run: |
pylint \
can/**.py \
can/io \
doc/conf.py \
examples/**.py \
can/interfaces/socketcan

format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --group lint
- name: Code Format Check with Black
run: |
black --check --verbose .
tox -e type

docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox
- name: Install uv
uses: astral-sh/setup-uv@v6
- name: Install tox
run: uv tool install tox --with tox-uv
- name: Build documentation
run: |
tox -e docs
Expand All @@ -147,14 +99,12 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # fetch tags for setuptools-scm
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install uv
uses: astral-sh/setup-uv@v6
- name: Build wheel and sdist
run: pipx run build
run: uvx --from build pyproject-build --installer uv
- name: Check build artifacts
run: pipx run twine check --strict dist/*
run: uvx twine check --strict dist/*
- name: Save artifacts
uses: actions/upload-artifact@v4
with:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ __pycache__/
# Distribution / packaging
.Python
env/
venv/
.venv*/
venv*/
build/
develop-eggs/
dist/
Expand Down
5 changes: 1 addition & 4 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ version: 2
build:
os: ubuntu-22.04
tools:
python: "3.12"
python: "3.13"
jobs:
post_install:
- pip install --group docs
Expand All @@ -31,6 +31,3 @@ python:
extra_requirements:
- canalystii
- gs-usb
- mf4
- remote
- serial
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Please read the [Development - Contributing](https://python-can.readthedocs.io/en/stable/development.html#contributing) guidelines in the documentation site.
Please read the [Development - Contributing](https://python-can.readthedocs.io/en/main/development.html#contributing) guidelines in the documentation site.
3 changes: 1 addition & 2 deletions can/bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from time import time
from types import TracebackType
from typing import (
Any,
Callable,
Optional,
Union,
Expand Down Expand Up @@ -69,7 +68,7 @@ class BusABC(metaclass=ABCMeta):
@abstractmethod
def __init__(
self,
channel: Any,
channel: Optional[can.typechecking.Channel],
can_filters: Optional[can.typechecking.CanFilters] = None,
**kwargs: object,
):
Expand Down
12 changes: 4 additions & 8 deletions can/interfaces/virtual.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,18 @@
from copy import deepcopy
from random import randint
from threading import RLock
from typing import TYPE_CHECKING, Any, Optional
from typing import Any, Optional

from can import CanOperationError
from can.bus import BusABC, CanProtocol
from can.message import Message
from can.typechecking import AutoDetectedConfig
from can.typechecking import AutoDetectedConfig, Channel

logger = logging.getLogger(__name__)


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


Expand Down Expand Up @@ -58,7 +54,7 @@ class VirtualBus(BusABC):

def __init__(
self,
channel: Any = None,
channel: Optional[Channel] = None,
receive_own_messages: bool = False,
rx_queue_size: int = 0,
preserve_timestamps: bool = False,
Expand Down
3 changes: 2 additions & 1 deletion can/io/mf4.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ def file_size(self) -> int:
"""Return an estimate of the current file size in bytes."""
# TODO: find solution without accessing private attributes of asammdf
return cast(
"int", self._mdf._tempfile.tell() # pylint: disable=protected-access
"int",
self._mdf._tempfile.tell(), # pylint: disable=protected-access,no-member
)

def stop(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
("py:class", "~P1"),
# intersphinx fails to reference some builtins
("py:class", "asyncio.events.AbstractEventLoop"),
("py:class", "_thread.allocate_lock"),
("py:class", "_thread.lock"),
]

# mock windows specific attributes
Expand Down
Loading
Loading