Skip to content

Commit 451ce48

Browse files
authored
Fix Sphinx warnings (hardbyte#1405)
* fix most sphinx warnings * build docs in CI * install package * fix extlink caption string deprecation warning * add Seeed Studio to title * update readthedocs configuration * add mocks for windows specifics * mypy should ignore conf.py * upload sphinx artifact * set retention to 5 days * set type annotation location
1 parent b639560 commit 451ce48

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+267
-136
lines changed

.github/workflows/build.yml

+22
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,25 @@ jobs:
8787
- name: Code Format Check with Black
8888
run: |
8989
black --check --verbose .
90+
91+
docs:
92+
runs-on: ubuntu-latest
93+
steps:
94+
- uses: actions/checkout@v2
95+
- name: Set up Python
96+
uses: actions/setup-python@v3
97+
with:
98+
python-version: "3.10"
99+
- name: Install dependencies
100+
run: |
101+
python -m pip install --upgrade pip
102+
pip install -e .[canalystii,gs_usb]
103+
pip install -r doc/doc-requirements.txt
104+
- name: Build documentation
105+
run: |
106+
python -m sphinx -an doc build
107+
- uses: actions/upload-artifact@v3
108+
with:
109+
name: sphinx-out
110+
path: ./build/
111+
retention-days: 5

.readthedocs.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# .readthedocs.yaml
2+
# Read the Docs configuration file
3+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
4+
5+
# Required
6+
version: 2
7+
8+
# Set the version of Python and other tools you might need
9+
build:
10+
os: ubuntu-22.04
11+
tools:
12+
python: "3.10"
13+
14+
# Build documentation in the docs/ directory with Sphinx
15+
sphinx:
16+
configuration: doc/conf.py
17+
18+
# If using Sphinx, optionally build your docs in additional formats such as PDF
19+
formats:
20+
- pdf
21+
- epub
22+
23+
# Optionally declare the Python requirements required to build your docs
24+
python:
25+
install:
26+
- requirements: doc/doc-requirements.txt
27+
- method: pip
28+
path: .
29+
extra_requirements:
30+
- canalystii
31+
- gs_usb

can/broadcastmanager.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CyclicTask(abc.ABC):
3939
def stop(self) -> None:
4040
"""Cancel this periodic task.
4141
42-
:raises can.CanError:
42+
:raises ~can.exceptions.CanError:
4343
If stop is called on an already stopped task.
4444
"""
4545

can/bus.py

+19-12
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ def __init__(
6666
Any backend dependent configurations are passed in this dictionary
6767
6868
:raises ValueError: If parameters are out of range
69-
:raises can.CanInterfaceNotImplementedError: If the driver cannot be accessed
70-
:raises can.CanInitializationError: If the bus cannot be initialized
69+
:raises ~can.exceptions.CanInterfaceNotImplementedError:
70+
If the driver cannot be accessed
71+
:raises ~can.exceptions.CanInitializationError:
72+
If the bus cannot be initialized
7173
"""
7274
self._periodic_tasks: List[_SelfRemovingCyclicTask] = []
7375
self.set_filters(can_filters)
@@ -81,9 +83,11 @@ def recv(self, timeout: Optional[float] = None) -> Optional[Message]:
8183
:param timeout:
8284
seconds to wait for a message or None to wait indefinitely
8385
84-
:return: ``None`` on timeout or a :class:`Message` object.
86+
:return:
87+
:obj:`None` on timeout or a :class:`~can.Message` object.
8588
86-
:raises can.CanOperationError: If an error occurred while reading
89+
:raises ~can.exceptions.CanOperationError:
90+
If an error occurred while reading
8791
"""
8892
start = time()
8993
time_left = timeout
@@ -148,7 +152,8 @@ def _recv_internal(
148152
2. a bool that is True if message filtering has already
149153
been done and else False
150154
151-
:raises can.CanOperationError: If an error occurred while reading
155+
:raises ~can.exceptions.CanOperationError:
156+
If an error occurred while reading
152157
:raises NotImplementedError:
153158
if the bus provides it's own :meth:`~can.BusABC.recv`
154159
implementation (legacy implementation)
@@ -171,7 +176,8 @@ def send(self, msg: Message, timeout: Optional[float] = None) -> None:
171176
Might not be supported by all interfaces.
172177
None blocks indefinitely.
173178
174-
:raises can.CanOperationError: If an error occurred while sending
179+
:raises ~can.exceptions.CanOperationError:
180+
If an error occurred while sending
175181
"""
176182
raise NotImplementedError("Trying to write to a readonly bus?")
177183

@@ -189,8 +195,8 @@ def send_periodic(
189195
- the (optional) duration expires
190196
- the Bus instance goes out of scope
191197
- the Bus instance is shutdown
192-
- :meth:`BusABC.stop_all_periodic_tasks()` is called
193-
- the task's :meth:`CyclicTask.stop()` method is called.
198+
- :meth:`stop_all_periodic_tasks` is called
199+
- the task's :meth:`~can.broadcastmanager.CyclicTask.stop` method is called.
194200
195201
:param msgs:
196202
Message(s) to transmit
@@ -204,7 +210,8 @@ def send_periodic(
204210
Disable to instead manage tasks manually.
205211
:return:
206212
A started task instance. Note the task can be stopped (and depending on
207-
the backend modified) by calling the task's :meth:`stop` method.
213+
the backend modified) by calling the task's
214+
:meth:`~can.broadcastmanager.CyclicTask.stop` method.
208215
209216
.. note::
210217
@@ -274,8 +281,8 @@ def _send_periodic_internal(
274281
no duration is provided, the task will continue indefinitely.
275282
:return:
276283
A started task instance. Note the task can be stopped (and
277-
depending on the backend modified) by calling the :meth:`stop`
278-
method.
284+
depending on the backend modified) by calling the
285+
:meth:`~can.broadcastmanager.CyclicTask.stop` method.
279286
"""
280287
if not hasattr(self, "_lock_send_periodic"):
281288
# Create a send lock for this bus, but not for buses which override this method
@@ -288,7 +295,7 @@ def _send_periodic_internal(
288295
return task
289296

290297
def stop_all_periodic_tasks(self, remove_tasks: bool = True) -> None:
291-
"""Stop sending any messages that were started using **bus.send_periodic**.
298+
"""Stop sending any messages that were started using :meth:`send_periodic`.
292299
293300
.. note::
294301
The result is undefined if a single task throws an exception while being stopped.

can/exceptions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class CanInitializationError(CanError):
7474
"""Indicates an error the occurred while initializing a :class:`can.BusABC`.
7575
7676
If initialization fails due to a driver or platform missing/being unsupported,
77-
a :class:`can.CanInterfaceNotImplementedError` is raised instead.
77+
a :exc:`~can.exceptions.CanInterfaceNotImplementedError` is raised instead.
7878
If initialization fails due to a value being out of range, a :class:`ValueError`
7979
is raised.
8080

can/interfaces/ixxat/canlib_vcinpl.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,8 @@ class IXXATBus(BusABC):
372372
.. warning::
373373
374374
This interface does implement efficient filtering of messages, but
375-
the filters have to be set in :meth:`~can.interfaces.ixxat.IXXATBus.__init__`
376-
using the ``can_filters`` parameter. Using :meth:`~can.interfaces.ixxat.IXXATBus.set_filters`
377-
does not work.
378-
375+
the filters have to be set in ``__init__`` using the ``can_filters`` parameter.
376+
Using :meth:`~can.BusABC.set_filters` does not work.
379377
"""
380378

381379
CHANNEL_BITRATES = {

can/interfaces/ixxat/canlib_vcinpl2.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,8 @@ class IXXATBus(BusABC):
411411
.. warning::
412412
413413
This interface does implement efficient filtering of messages, but
414-
the filters have to be set in :meth:`~can.interfaces.ixxat.IXXATBus.__init__`
415-
using the ``can_filters`` parameter. Using :meth:`~can.interfaces.ixxat.IXXATBus.set_filters`
416-
does not work.
414+
the filters have to be set in ``__init__`` using the ``can_filters`` parameter.
415+
Using :meth:`~can.BusABC.set_filters` does not work.
417416
418417
"""
419418

can/interfaces/kvaser/canlib.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ def shutdown(self):
657657
canBusOff(self._write_handle)
658658
canClose(self._write_handle)
659659

660-
def get_stats(self):
660+
def get_stats(self) -> structures.BusStatistics:
661661
"""Retrieves the bus statistics.
662662
663663
Use like so:
@@ -667,7 +667,6 @@ def get_stats(self):
667667
std_data: 0, std_remote: 0, ext_data: 0, ext_remote: 0, err_frame: 0, bus_load: 0.0%, overruns: 0
668668
669669
:returns: bus statistics.
670-
:rtype: can.interfaces.kvaser.structures.BusStatistics
671670
"""
672671
canRequestBusStatistics(self._write_handle)
673672
stats = structures.BusStatistics()

can/interfaces/kvaser/structures.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@
77

88

99
class BusStatistics(ctypes.Structure):
10-
"""
11-
This structure is used with the method :meth:`KvaserBus.get_stats`.
12-
13-
.. seealso:: :meth:`KvaserBus.get_stats`
14-
10+
"""This structure is used with the method
11+
:meth:`~can.interfaces.kvaser.canlib.KvaserBus.get_stats`.
1512
"""
1613

1714
_fields_ = [

can/interfaces/nican.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,8 @@ class NicanBus(BusABC):
179179
.. warning::
180180
181181
This interface does implement efficient filtering of messages, but
182-
the filters have to be set in :meth:`~can.interfaces.nican.NicanBus.__init__`
183-
using the ``can_filters`` parameter. Using :meth:`~can.interfaces.nican.NicanBus.set_filters`
184-
does not work.
185-
182+
the filters have to be set in ``__init__`` using the ``can_filters`` parameter.
183+
Using :meth:`~can.BusABC.set_filters` does not work.
186184
"""
187185

188186
def __init__(
@@ -208,9 +206,9 @@ def __init__(
208206
``is_error_frame`` set to True and ``arbitration_id`` will identify
209207
the error (default True)
210208
211-
:raise can.CanInterfaceNotImplementedError:
209+
:raise ~can.exceptions.CanInterfaceNotImplementedError:
212210
If the current operating system is not supported or the driver could not be loaded.
213-
:raise can.interfaces.nican.NicanInitializationError:
211+
:raise ~can.interfaces.nican.NicanInitializationError:
214212
If the bus could not be set up.
215213
"""
216214
if nican is None:

can/interfaces/pcan/pcan.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ def __init__(
113113
"""A PCAN USB interface to CAN.
114114
115115
On top of the usual :class:`~can.Bus` methods provided,
116-
the PCAN interface includes the :meth:`~can.interface.pcan.PcanBus.flash`
117-
and :meth:`~can.interface.pcan.PcanBus.status` methods.
116+
the PCAN interface includes the :meth:`flash`
117+
and :meth:`status` methods.
118118
119119
:param str channel:
120120
The can interface name. An example would be 'PCAN_USBBUS1'.

can/interfaces/robotell.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
import io
66
import time
77
import logging
8+
from typing import Optional
89

910
from can import BusABC, Message
10-
from ..exceptions import CanInterfaceNotImplementedError
11+
from ..exceptions import CanInterfaceNotImplementedError, CanOperationError
1112

1213
logger = logging.getLogger(__name__)
1314

@@ -377,12 +378,11 @@ def fileno(self):
377378
except Exception as exception:
378379
raise CanOperationError("Cannot fetch fileno") from exception
379380

380-
def get_serial_number(self, timeout):
381+
def get_serial_number(self, timeout: Optional[int]) -> Optional[str]:
381382
"""Get serial number of the slcan interface.
382-
:type timeout: int or None
383+
383384
:param timeout:
384385
seconds to wait for serial number or None to wait indefinitely
385-
:rtype str or None
386386
:return:
387387
None on timeout or a str object.
388388
"""

can/interfaces/serial/serial_can.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ def __init__(
7474
:param rtscts:
7575
turn hardware handshake (RTS/CTS) on and off
7676
77-
:raises can.CanInitializationError: If the given parameters are invalid.
78-
:raises can.CanInterfaceNotImplementedError: If the serial module is not installed.
77+
:raises ~can.exceptions.CanInitializationError:
78+
If the given parameters are invalid.
79+
:raises ~can.exceptions.CanInterfaceNotImplementedError:
80+
If the serial module is not installed.
7981
"""
8082

8183
if not serial:
@@ -163,10 +165,10 @@ def _recv_internal(
163165
This parameter will be ignored. The timeout value of the channel is used.
164166
165167
:returns:
166-
Received message and `False` (because no filtering as taken place).
168+
Received message and :obj:`False` (because no filtering as taken place).
167169
168170
.. warning::
169-
Flags like is_extended_id, is_remote_frame and is_error_frame
171+
Flags like ``is_extended_id``, ``is_remote_frame`` and ``is_error_frame``
170172
will not be set over this function, the flags in the return
171173
message are the default values.
172174
"""

can/interfaces/slcan.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,10 @@ def get_serial_number(self, timeout: Optional[float]) -> Optional[str]:
323323
"""Get serial number of the slcan interface.
324324
325325
:param timeout:
326-
seconds to wait for serial number or ``None`` to wait indefinitely
326+
seconds to wait for serial number or :obj:`None` to wait indefinitely
327327
328328
:return:
329-
``None`` on timeout or a :class:`~builtin.str` object.
329+
:obj:`None` on timeout or a :class:`str` object.
330330
"""
331331
cmd = "N"
332332
self._write(cmd)

can/interfaces/socketcan/socketcan.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def stop(self) -> None:
402402
"""Stop a task by sending TX_DELETE message to Linux kernel.
403403
404404
This will delete the entry for the transmission of the CAN-message
405-
with the specified :attr:`~task_id` identifier. The message length
405+
with the specified ``task_id`` identifier. The message length
406406
for the command TX_DELETE is {[bcm_msg_head]} (only the header).
407407
"""
408408
log.debug("Stopping periodic task")
@@ -444,7 +444,7 @@ def start(self) -> None:
444444
message to Linux kernel prior to scheduling.
445445
446446
:raises ValueError:
447-
If the task referenced by :attr:`~task_id` is already running.
447+
If the task referenced by ``task_id`` is already running.
448448
"""
449449
self._tx_setup(self.messages)
450450

@@ -617,9 +617,10 @@ def __init__(
617617
618618
If setting some socket options fails, an error will be printed but no exception will be thrown.
619619
This includes enabling:
620-
- that own messages should be received,
621-
- CAN-FD frames and
622-
- error frames.
620+
621+
- that own messages should be received,
622+
- CAN-FD frames and
623+
- error frames.
623624
624625
:param channel:
625626
The can interface name with which to create this bus.
@@ -739,7 +740,7 @@ def send(self, msg: Message, timeout: Optional[float] = None) -> None:
739740
Wait up to this many seconds for the transmit queue to be ready.
740741
If not given, the call may fail immediately.
741742
742-
:raises can.CanError:
743+
:raises ~can.exceptions.CanError:
743744
if the message could not be written.
744745
"""
745746
log.debug("We've been asked to write a message to the bus")

can/interfaces/systec/ucanbus.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ def __init__(self, channel, can_filters=None, **kwargs):
8888
:raises ValueError:
8989
If invalid input parameter were passed.
9090
91-
:raises can.CanInterfaceNotImplementedError:
91+
:raises ~can.exceptions.CanInterfaceNotImplementedError:
9292
If the platform is not supported.
9393
94-
:raises can.CanInitializationError:
94+
:raises ~can.exceptions.CanInitializationError:
9595
If hardware or CAN interface initialization failed.
9696
"""
9797
try:
@@ -181,7 +181,7 @@ def send(self, msg, timeout=None):
181181
:param float timeout:
182182
Transmit timeout in seconds (value 0 switches off the "auto delete")
183183
184-
:raises can.CanOperationError:
184+
:raises ~can.exceptions.CanOperationError:
185185
If the message could not be sent.
186186
"""
187187
try:
@@ -243,7 +243,7 @@ def flush_tx_buffer(self):
243243
"""
244244
Flushes the transmit buffer.
245245
246-
:raises can.CanError:
246+
:raises ~can.exceptions.CanError:
247247
If flushing of the transmit buffer failed.
248248
"""
249249
log.info("Flushing transmit buffer")

0 commit comments

Comments
 (0)