Skip to content

Commit 1a74330

Browse files
authored
Documentation update (#486)
* Add try except around importing curses to support windows * Update docstrings for MultiRateCyclicSendTask * Move some internal stuff into own internal api page. * More doc updates - trying to reduce sphinx warnings
1 parent 0b9d240 commit 1a74330

File tree

13 files changed

+113
-73
lines changed

13 files changed

+113
-73
lines changed

can/broadcastmanager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ def modify_data(self, message):
8585

8686

8787
class MultiRateCyclicSendTaskABC(CyclicSendTaskABC):
88-
"""Exposes more of the full power of the TX_SETUP opcode.
88+
"""A Cyclic send task that supports switches send frequency after a set time.
8989
"""
9090

9191
def __init__(self, channel, message, count, initial_period, subsequent_period):
9292
"""
9393
Transmits a message `count` times at `initial_period` then continues to
9494
transmit message at `subsequent_period`.
9595
96-
:param can.interface.Bus channel:
96+
:param channel: See interface specific documentation.
9797
:param can.Message message:
9898
:param int count:
9999
:param float initial_period:

can/bus.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ def send_periodic(self, msg, period, duration=None, store_task=True):
167167
- the (optional) duration expires
168168
- the Bus instance goes out of scope
169169
- the Bus instance is shutdown
170-
- :meth:`Bus.stop_all_periodic_tasks()` is called
171-
- the task's :meth:`Task.stop()` method is called.
170+
- :meth:`BusABC.stop_all_periodic_tasks()` is called
171+
- the task's :meth:`CyclicTask.stop()` method is called.
172172
173173
:param can.Message msg:
174174
Message to transmit

can/interface.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# coding: utf-8
22

33
"""
4-
This module contains the base implementation of `can.Bus` as well
5-
as a list of all avalibale backends and some implemented
4+
This module contains the base implementation of :class:`can.BusABC` as well
5+
as a list of all available backends and some implemented
66
CyclicSendTasks.
77
"""
88

@@ -11,7 +11,6 @@
1111
import sys
1212
import importlib
1313
import logging
14-
import re
1514

1615
import can
1716
from .bus import BusABC
@@ -145,7 +144,7 @@ def detect_available_configs(interfaces=None):
145144
- `None` to search in all known interfaces.
146145
:rtype: list[dict]
147146
:return: an iterable of dicts, each suitable for usage in
148-
the constructor of :class:`can.interface.Bus`.
147+
the constructor of :class:`can.BusABC`.
149148
"""
150149

151150
# Figure out where to search

can/interfaces/socketcan/socketcan.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,7 @@ def start(self):
303303
class MultiRateCyclicSendTask(CyclicSendTask):
304304
"""Exposes more of the full power of the TX_SETUP opcode.
305305
306-
Transmits a message `count` times at `initial_period` then
307-
continues to transmit message at `subsequent_period`.
306+
308307
"""
309308

310309
def __init__(self, channel, message, count, initial_period, subsequent_period):

can/io/generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __init__(self, file, mode='rt'):
2626
:param file: a path-like object to open a file, a file-like object
2727
to be used as a file or `None` to not use a file at all
2828
:param str mode: the mode that should be used to open the file, see
29-
:func:`builtin.open`, ignored if *file* is `None`
29+
:func:`open`, ignored if *file* is `None`
3030
"""
3131
if file is None or (hasattr(file, 'read') and hasattr(file, 'write')):
3232
# file is None or some file-like object

can/viewer.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,26 @@
2525
from __future__ import absolute_import, print_function
2626

2727
import argparse
28-
import can
29-
import curses
3028
import os
3129
import struct
3230
import sys
3331
import time
34-
35-
from curses.ascii import ESC as KEY_ESC, SP as KEY_SPACE
32+
import logging
3633
from typing import Dict, List, Tuple, Union
37-
34+
import can
3835
from can import __version__
3936

37+
logger = logging.getLogger('can.serial')
38+
39+
try:
40+
import curses
41+
from curses.ascii import ESC as KEY_ESC, SP as KEY_SPACE
42+
except ImportError:
43+
# Probably on windows
44+
logger.warning("You won't be able to use the viewer program without "
45+
"curses installed!")
46+
curses = None
47+
4048

4149
class CanViewer:
4250

doc/api.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,16 @@ A form of CAN interface is also required.
1717
listeners
1818
asyncio
1919
bcm
20+
internal-api
2021

2122

2223
Utilities
2324
---------
2425

25-
.. automodule:: can.util
26-
:members:
2726

2827
.. automethod:: can.detect_available_configs
2928

3029

31-
32-
3330
.. _notifier:
3431

3532
Notifier

doc/bus.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ API
3030
:members:
3131
:undoc-members:
3232

33+
.. automethod:: __iter__
3334

3435
Transmitting
3536
''''''''''''

doc/development.rst

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ These steps are a guideline on how to add a new backend to python-can.
3535
- Create a module (either a ``*.py`` or an entire subdirectory depending
3636
on the complexity) inside ``can.interfaces``
3737
- Implement the central part of the backend: the bus class that extends
38-
:class:`can.BusABC`. See below for more info on this one!
38+
:class:`can.BusABC`. See :ref:`businternals` for more info on this one!
3939
- Register your backend bus class in ``can.interface.BACKENDS`` and
4040
``can.interfaces.VALID_INTERFACES`` in ``can.interfaces.__init__.py``.
4141
- Add docs where appropriate. At a minimum add to ``doc/interfaces.rst`` and add
@@ -44,53 +44,6 @@ These steps are a guideline on how to add a new backend to python-can.
4444
- Add tests in ``test/*`` where appropriate.
4545

4646

47-
About the ``BusABC`` class
48-
--------------------------
49-
50-
Concrete implementations *have to* implement the following:
51-
* :meth:`~can.BusABC.send` to send individual messages
52-
* :meth:`~can.BusABC._recv_internal` to receive individual messages
53-
(see note below!)
54-
* set the :attr:`~can.BusABC.channel_info` attribute to a string describing
55-
the underlying bus and/or channel
56-
57-
They *might* implement the following:
58-
* :meth:`~can.BusABC.flush_tx_buffer` to allow discarding any
59-
messages yet to be sent
60-
* :meth:`~can.BusABC.shutdown` to override how the bus should
61-
shut down
62-
* :meth:`~can.BusABC._send_periodic_internal` to override the software based
63-
periodic sending and push it down to the kernel or hardware.
64-
* :meth:`~can.BusABC._apply_filters` to apply efficient filters
65-
to lower level systems like the OS kernel or hardware.
66-
* :meth:`~can.BusABC._detect_available_configs` to allow the interface
67-
to report which configurations are currently available for new
68-
connections.
69-
* :meth:`~can.BusABC.state` property to allow reading and/or changing
70-
the bus state.
71-
72-
.. note::
73-
74-
*TL;DR*: Only override :meth:`~can.BusABC._recv_internal`,
75-
never :meth:`~can.BusABC.recv` directly.
76-
77-
Previously, concrete bus classes had to override :meth:`~can.BusABC.recv`
78-
directly instead of :meth:`~can.BusABC._recv_internal`, but that has
79-
changed to allow the abstract base class to handle in-software message
80-
filtering as a fallback. All internal interfaces now implement that new
81-
behaviour. Older (custom) interfaces might still be implemented like that
82-
and thus might not provide message filtering:
83-
84-
This is the entire ABC bus class with all internal methods:
85-
86-
.. autoclass:: can.BusABC
87-
:private-members:
88-
:special-members:
89-
:noindex:
90-
91-
92-
Concrete instances are created by :class:`can.Bus`.
93-
9447

9548
Code Structure
9649
--------------

doc/history.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ The CAN viewer terminal script was contributed by Kristian Sloth Lauszus in 2018
4646

4747
The CANalyst-II interface was contributed by Shaoyu Meng in 2018.
4848

49-
The SYSTEC interface was contributed by @idaniel86
50-
5149
Support for CAN within Python
5250
-----------------------------
5351

doc/interfaces/canalystii.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
CANalyst-II
22
===========
33

4-
CANalyst-II(+) is a USB to CAN Analyzer. The controlcan library is originally developed by `ZLG ZHIYUAN Electronics`_.
4+
CANalyst-II(+) is a USB to CAN Analyzer. The controlcan library is originally developed by
5+
`ZLG ZHIYUAN Electronics`_.
56

67

78
Bus

doc/internal-api.rst

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
Internal API
2+
============
3+
4+
Here we document the odds and ends that are more helpful for creating your own interfaces
5+
or listeners but generally shouldn't be required to interact with python-can.
6+
7+
8+
.. _businternals:
9+
10+
11+
Extending the ``BusABC`` class
12+
------------------------------
13+
14+
Concrete implementations **must** implement the following:
15+
* :meth:`~can.BusABC.send` to send individual messages
16+
* :meth:`~can.BusABC._recv_internal` to receive individual messages
17+
(see note below!)
18+
* set the :attr:`~can.BusABC.channel_info` attribute to a string describing
19+
the underlying bus and/or channel
20+
21+
They **might** implement the following:
22+
* :meth:`~can.BusABC.flush_tx_buffer` to allow discarding any
23+
messages yet to be sent
24+
* :meth:`~can.BusABC.shutdown` to override how the bus should
25+
shut down
26+
* :meth:`~can.BusABC._send_periodic_internal` to override the software based
27+
periodic sending and push it down to the kernel or hardware.
28+
* :meth:`~can.BusABC._apply_filters` to apply efficient filters
29+
to lower level systems like the OS kernel or hardware.
30+
* :meth:`~can.BusABC._detect_available_configs` to allow the interface
31+
to report which configurations are currently available for new
32+
connections.
33+
* :meth:`~can.BusABC.state` property to allow reading and/or changing
34+
the bus state.
35+
36+
.. note::
37+
38+
*TL;DR*: Only override :meth:`~can.BusABC._recv_internal`,
39+
never :meth:`~can.BusABC.recv` directly.
40+
41+
Previously, concrete bus classes had to override :meth:`~can.BusABC.recv`
42+
directly instead of :meth:`~can.BusABC._recv_internal`, but that has
43+
changed to allow the abstract base class to handle in-software message
44+
filtering as a fallback. All internal interfaces now implement that new
45+
behaviour. Older (custom) interfaces might still be implemented like that
46+
and thus might not provide message filtering:
47+
48+
49+
50+
Concrete instances are usually created by :class:`can.Bus` which takes the users
51+
configuration into account.
52+
53+
54+
Bus Internals
55+
~~~~~~~~~~~~~
56+
57+
Several methods are not documented in the main :class:`can.BusABC`
58+
as they are primarily useful for library developers as opposed to
59+
library users. This is the entire ABC bus class with all internal
60+
methods:
61+
62+
.. autoclass:: can.BusABC
63+
:private-members:
64+
:special-members:
65+
:noindex:
66+
67+
68+
69+
IO Utilities
70+
------------
71+
72+
73+
.. automodule:: can.io.generic
74+
:members:
75+
76+
77+
78+
Other Util
79+
----------
80+
81+
82+
.. automodule:: can.util
83+
:members:
84+

doc/message.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Message
113113

114114
.. note::
115115

116-
The :meth:`Message.__init__` argument ``extended_id`` has been deprecated in favor of
116+
The initializer argument and attribute ``extended_id`` has been deprecated in favor of
117117
``is_extended_id``, but will continue to work for the ``3.x`` release series.
118118

119119

@@ -129,7 +129,7 @@ Message
129129

130130
.. attribute:: is_remote_frame
131131

132-
:type: boolean
132+
:type: bool
133133

134134
This boolean attribute indicates if the message is a remote frame or a data frame, and
135135
modifies the bit in the CAN message's flags field indicating this.

0 commit comments

Comments
 (0)