Skip to content

Commit a5b1df2

Browse files
committed
Raised Sphinx version to 6.1 + ran autopep8 and enforces it with vscode
1 parent 820d878 commit a5b1df2

21 files changed

+562
-407
lines changed

.readthedocs.yaml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
# You can also specify other tool versions:
14+
# nodejs: "19"
15+
# rust: "1.64"
16+
# golang: "1.19"
17+
18+
# Build documentation in the docs/ directory with Sphinx
19+
sphinx:
20+
configuration: doc/source/conf.py
21+
22+
# If using Sphinx, optionally build your docs in additional formats such as PDF
23+
# formats:
24+
# - pdf
25+
26+
# Optionally declare the Python requirements required to build your docs
27+
python:
28+
install:
29+
- requirements: doc/requirements.txt

.vscode/settings.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"files.insertFinalNewline": true,
3+
"editor.detectIndentation": false,
4+
"editor.tabSize": 4,
5+
"editor.insertSpaces": true,
6+
"python.analysis.autoImportCompletions": false,
7+
"[python]": {
8+
"editor.defaultFormatter": "ms-python.autopep8",
9+
"editor.formatOnSave": true
10+
},
11+
"autopep8.args": [
12+
"--max-line-length",
13+
"150",
14+
"--select",
15+
"E101,E11,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E133,E20,E211,E22,E224,E225,E226,E227,E228,E231,E241,E242,E251,E252,E26,E265,E27,E301,E302,E303,E304,E305,E306,E401,E501,E502,W291,W292,W293,W391,W503,W504,W603 "
16+
]
17+
}

README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ python-can-isotp
55

66
This project is a Python package meant to provide support for IsoTP (ISO-15765) protocol written in Python 3. The code is published under MIT license on GitHub (`pylessard/python-can-isotp <https://github.com/pylessard/python-can-isotp>`_).
77

8-
This package contains a Python implementation of the protocol that works in the user space that may or may not be coupled with `python-can <https://python-can.readthedocs.io>`_. It also contains a wrapper for a simplified usage of the `Linux SocketCAN IsoTP kernel module <https://github.com/hartkopp/can-isotp>`_
8+
This package contains a Python implementation of the protocol that works in the user space that may or may not be coupled with `python-can <https://python-can.readthedocs.io>`_. It also contains a wrapper for a simplified usage of the `Linux SocketCAN IsoTP kernel module <https://github.com/hartkopp/can-isotp>`__
99

1010
Documentation
1111
-------------

doc/requirements.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
sphinx_rtd_theme>=0.3.1
2-
sphinx==1.7.9
1+
sphinx_rtd_theme>=1.2
2+
sphinx==6.1.3

doc/source/conf.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
'sphinx.ext.autodoc',
3434
'sphinx.ext.mathjax',
3535
'sphinx.ext.viewcode',
36+
"sphinxcontrib.jquery"
3637
]
3738

3839
# Add any paths that contain templates here, relative to this directory.
@@ -61,14 +62,14 @@
6162
# The short X.Y version.
6263
version = u'1.8'
6364
# The full version, including alpha/beta/rc tags.
64-
release = u'0'
65+
release = version
6566

6667
# The language for content autogenerated by Sphinx. Refer to documentation
6768
# for a list of supported languages.
6869
#
6970
# This is also used if you do content translation via gettext catalogs.
7071
# Usually you set "language" from the command line for these cases.
71-
language = None
72+
language = 'en'
7273

7374
# There are two options for replacing |today|: either, you set today to some
7475
# non-false value, then it is used:
@@ -108,18 +109,22 @@
108109
todo_include_todos = False
109110

110111

112+
primary_domain = 'py'
111113
# -- Options for HTML output ----------------------------------------------
112114

113115
# The theme to use for HTML and HTML Help pages. See the documentation for
114116
# a list of builtin themes.
115117
html_theme = 'sphinx_rtd_theme'
116118

119+
toc_object_entries = False
120+
117121
# Theme options are theme-specific and customize the look and feel of a theme
118122
# further. For a list of options available for each theme, see the
119123
# documentation.
120124
html_theme_options = {
121-
'sticky_navigation' : False,
122-
'collapse_navigation' : True
125+
'sticky_navigation': True,
126+
'collapse_navigation': True,
127+
'navigation_depth': 3,
123128
}
124129

125130
# Add any paths that contain custom themes here, relative to this directory.
@@ -298,4 +303,4 @@
298303
#texinfo_no_detailmenu = False
299304

300305
def setup(app):
301-
app.add_stylesheet('theme_overrides.css')
306+
app.add_css_file('theme_overrides.css')

doc/source/index.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ Python support for IsoTP Transport protocol (ISO-15765)
22
=======================================================
33

44
.. toctree::
5-
:maxdepth: 2
65
:hidden:
76

87
Home <self>
@@ -13,4 +12,4 @@ Python support for IsoTP Transport protocol (ISO-15765)
1312

1413
This project is a Python package meant to provide support for IsoTP (ISO-15765) protocol written in Python 3. The code is published under MIT license on GitHub (`pylessard/python-can-isotp <https://github.com/pylessard/python-can-isotp>`_).
1514

16-
This package contains a Python implementation of the protocol that works in the user space that may or may not be coupled with `python-can <https://python-can.readthedocs.io>`_. It also contains a wrapper for a simplified usage of the `Linux SocketCAN IsoTP kernel module <https://github.com/hartkopp/can-isotp>`_
15+
This package contains a Python implementation of the protocol that works in the user space that may or may not be coupled with `python-can <https://python-can.readthedocs.io>`_. It also contains a wrapper for a simplified usage of the `Linux SocketCAN IsoTP kernel module <https://github.com/hartkopp/can-isotp>`__

isotp/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from isotp.tpsock import socket
22
from isotp.protocol import TransportLayer, CanStack, CanMessage
33
from isotp.address import *
4-
from isotp.errors import *
4+
from isotp.errors import *

isotp/address.py

+23-20
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ def get_name(cls, num):
2626

2727
return 'Unknown'
2828

29+
2930
class TargetAddressType:
3031
Physical = 0 # 1 to 1 communication
3132
Functional = 1 # 1 to n communication
3233

34+
3335
class Address:
3436
"""
3537
Represents the addressing information (N_AI) of the IsoTP layer. Will define what messages will be received and how to craft transmitted message to reach a specific party.
@@ -63,32 +65,33 @@ class Address:
6365
:type address_extension: int or None
6466
"""
6567

66-
def __init__(self, addressing_mode = AddressingMode.Normal_11bits, txid=None, rxid=None, target_address=None, source_address=None, physical_id=None, functional_id=None, address_extension=None, **kwargs):
68+
def __init__(self, addressing_mode=AddressingMode.Normal_11bits, txid=None, rxid=None, target_address=None, source_address=None, physical_id=None, functional_id=None, address_extension=None, **kwargs):
6769

68-
self.addressing_mode = addressing_mode
69-
self.target_address = target_address
70-
self.source_address = source_address
71-
self.address_extension = address_extension
72-
self.txid = txid
73-
self.rxid = rxid
74-
self.is_29bits = True if self.addressing_mode in [ AddressingMode.Normal_29bits, AddressingMode.NormalFixed_29bits, AddressingMode.Extended_29bits, AddressingMode.Mixed_29bits] else False
70+
self.addressing_mode = addressing_mode
71+
self.target_address = target_address
72+
self.source_address = source_address
73+
self.address_extension = address_extension
74+
self.txid = txid
75+
self.rxid = rxid
76+
self.is_29bits = True if self.addressing_mode in [
77+
AddressingMode.Normal_29bits, AddressingMode.NormalFixed_29bits, AddressingMode.Extended_29bits, AddressingMode.Mixed_29bits] else False
7578

7679
if self.addressing_mode == AddressingMode.NormalFixed_29bits:
77-
self.physical_id = 0x18DA0000 if physical_id is None else physical_id & 0x1FFF0000
80+
self.physical_id = 0x18DA0000 if physical_id is None else physical_id & 0x1FFF0000
7881
self.functional_id = 0x18DB0000 if functional_id is None else functional_id & 0x1FFF0000
7982

8083
if self.addressing_mode == AddressingMode.Mixed_29bits:
81-
self.physical_id = 0x18CE0000 if physical_id is None else physical_id & 0x1FFF0000
84+
self.physical_id = 0x18CE0000 if physical_id is None else physical_id & 0x1FFF0000
8285
self.functional_id = 0x18CD0000 if functional_id is None else functional_id & 0x1FFF0000
8386

8487
self.validate()
8588

8689
# From here, input is good. Do some precomputing for speed optimization without bothering about types or values
87-
self.tx_arbitration_id_physical = self._get_tx_arbitraton_id(TargetAddressType.Physical)
88-
self.tx_arbitration_id_functional = self._get_tx_arbitraton_id(TargetAddressType.Functional)
90+
self.tx_arbitration_id_physical = self._get_tx_arbitraton_id(TargetAddressType.Physical)
91+
self.tx_arbitration_id_functional = self._get_tx_arbitraton_id(TargetAddressType.Functional)
8992

90-
self.rx_arbitration_id_physical = self._get_rx_arbitration_id(TargetAddressType.Physical)
91-
self.rx_arbitration_id_functional = self._get_rx_arbitration_id(TargetAddressType.Functional)
93+
self.rx_arbitration_id_physical = self._get_rx_arbitration_id(TargetAddressType.Physical)
94+
self.rx_arbitration_id_functional = self._get_rx_arbitration_id(TargetAddressType.Functional)
9295

9396
self.tx_payload_prefix = bytearray()
9497
self.rx_prefix_size = 0
@@ -114,7 +117,7 @@ def __init__(self, addressing_mode = AddressingMode.Normal_11bits, txid=None, rx
114117
raise RuntimeError('This exception should never be raised.')
115118

116119
def validate(self):
117-
if self.addressing_mode not in [AddressingMode.Normal_11bits,AddressingMode.Normal_29bits,AddressingMode.NormalFixed_29bits,AddressingMode.Extended_11bits,AddressingMode.Extended_29bits,AddressingMode.Mixed_11bits,AddressingMode.Mixed_29bits]:
120+
if self.addressing_mode not in [AddressingMode.Normal_11bits, AddressingMode.Normal_29bits, AddressingMode.NormalFixed_29bits, AddressingMode.Extended_11bits, AddressingMode.Extended_29bits, AddressingMode.Mixed_11bits, AddressingMode.Mixed_29bits]:
118121
raise ValueError('Addressing mode is not valid')
119122

120123
if self.addressing_mode in [AddressingMode.Normal_11bits, AddressingMode.Normal_29bits]:
@@ -201,7 +204,7 @@ def _get_tx_arbitraton_id(self, address_type):
201204
elif self.addressing_mode == AddressingMode.Mixed_11bits:
202205
return self.txid
203206
elif self.addressing_mode in [AddressingMode.Mixed_29bits, AddressingMode.NormalFixed_29bits]:
204-
bits28_16 = self.physical_id if address_type==TargetAddressType.Physical else self.functional_id
207+
bits28_16 = self.physical_id if address_type == TargetAddressType.Physical else self.functional_id
205208
return bits28_16 | (self.target_address << 8) | self.source_address
206209

207210
def _get_rx_arbitration_id(self, address_type=TargetAddressType.Physical):
@@ -216,7 +219,7 @@ def _get_rx_arbitration_id(self, address_type=TargetAddressType.Physical):
216219
elif self.addressing_mode == AddressingMode.Mixed_11bits:
217220
return self.rxid
218221
elif self.addressing_mode in [AddressingMode.Mixed_29bits, AddressingMode.NormalFixed_29bits]:
219-
bits28_16 = self.physical_id if address_type==TargetAddressType.Physical else self.functional_id
222+
bits28_16 = self.physical_id if address_type == TargetAddressType.Physical else self.functional_id
220223
return bits28_16 | (self.source_address << 8) | self.target_address
221224

222225
def _is_for_me_normal(self, msg):
@@ -253,7 +256,7 @@ def requires_extension_byte(self):
253256
def get_tx_extension_byte(self):
254257
if self.addressing_mode in [AddressingMode.Extended_11bits, AddressingMode.Extended_29bits]:
255258
return self.target_address
256-
if self.addressing_mode in [ AddressingMode.Mixed_11bits, AddressingMode.Mixed_29bits]:
259+
if self.addressing_mode in [AddressingMode.Mixed_11bits, AddressingMode.Mixed_29bits]:
257260
return self.address_extension
258261

259262
def get_rx_extension_byte(self):
@@ -264,12 +267,12 @@ def get_rx_extension_byte(self):
264267

265268
def get_content_str(self):
266269
val_dict = {}
267-
keys = ['target_address', 'source_address', 'address_extension', 'txid', 'rxid']
270+
keys = ['target_address', 'source_address', 'address_extension', 'txid', 'rxid']
268271
for key in keys:
269272
val = getattr(self, key)
270273
if val is not None:
271274
val_dict[key] = val
272-
vals_str = ', '.join(['%s:0x%02x' % (k,val_dict[k]) for k in val_dict])
275+
vals_str = ', '.join(['%s:0x%02x' % (k, val_dict[k]) for k in val_dict])
273276
return '[%s - %s]' % (AddressingMode.get_name(self.addressing_mode), vals_str)
274277

275278
def __repr__(self):

isotp/address.pyi

+10-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ class AddressingMode:
99
Extended_29bits: int
1010
Mixed_11bits: int
1111
Mixed_29bits: int
12+
1213
@classmethod
1314
def get_name(cls,
1415
num: int) -> str: ...
1516

17+
1618
class TargetAddressType:
1719
Physical: int
1820
Functional: int
1921

22+
2023
class Address:
2124
addressing_mode: int
2225
target_address: Optional[int]
@@ -32,19 +35,23 @@ class Address:
3235
tx_payload_prefix: bytearray
3336
rx_prefix_size: int
3437
is_for_me: bool
38+
3539
def __init__(self,
36-
addressing_mode: int=...,
40+
addressing_mode: int = ...,
3741
txid: Optional[int] = ...,
3842
rxid: Optional[int] = ...,
3943
target_address: Optional[int] = ...,
4044
source_address: Optional[int] = ...,
4145
address_extension: Optional[int] = ...,
4246
**kwargs: Dict[Any, Any]) -> None: ...
47+
4348
def validate(self) -> None: ...
49+
4450
def get_tx_arbitraton_id(self,
45-
address_type:TargetAddressType=...) -> Optional[int]: ...
51+
address_type: TargetAddressType = ...) -> Optional[int]: ...
4652
def get_rx_arbitraton_id(self,
47-
address_type:TargetAddressType=...) -> Optional[int]: ...
53+
address_type: TargetAddressType = ...) -> Optional[int]: ...
54+
4855
def requires_extension_byte(self) -> bool: ...
4956
def get_tx_extension_byte(self) -> Optional[int]: ...
5057
def get_rx_extension_byte(self) -> Optional[int]: ...

0 commit comments

Comments
 (0)