Skip to content

Commit

Permalink
Raised Sphinx version to 6.1 + ran autopep8 and enforces it with vscode
Browse files Browse the repository at this point in the history
  • Loading branch information
pylessard committed Mar 20, 2023
1 parent 820d878 commit a5b1df2
Show file tree
Hide file tree
Showing 21 changed files with 562 additions and 407 deletions.
29 changes: 29 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# .readthedocs.yaml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the version of Python and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.10"
# You can also specify other tool versions:
# nodejs: "19"
# rust: "1.64"
# golang: "1.19"

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: doc/source/conf.py

# If using Sphinx, optionally build your docs in additional formats such as PDF
# formats:
# - pdf

# Optionally declare the Python requirements required to build your docs
python:
install:
- requirements: doc/requirements.txt
17 changes: 17 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"files.insertFinalNewline": true,
"editor.detectIndentation": false,
"editor.tabSize": 4,
"editor.insertSpaces": true,
"python.analysis.autoImportCompletions": false,
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8",
"editor.formatOnSave": true
},
"autopep8.args": [
"--max-line-length",
"150",
"--select",
"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 "
]
}
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ python-can-isotp

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>`_).

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>`_
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>`__

Documentation
-------------
Expand Down
4 changes: 2 additions & 2 deletions doc/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sphinx_rtd_theme>=0.3.1
sphinx==1.7.9
sphinx_rtd_theme>=1.2
sphinx==6.1.3
15 changes: 10 additions & 5 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'sphinx.ext.autodoc',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode',
"sphinxcontrib.jquery"
]

# Add any paths that contain templates here, relative to this directory.
Expand Down Expand Up @@ -61,14 +62,14 @@
# The short X.Y version.
version = u'1.8'
# The full version, including alpha/beta/rc tags.
release = u'0'
release = version

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

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


primary_domain = 'py'
# -- Options for HTML output ----------------------------------------------

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

toc_object_entries = False

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
html_theme_options = {
'sticky_navigation' : False,
'collapse_navigation' : True
'sticky_navigation': True,
'collapse_navigation': True,
'navigation_depth': 3,
}

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

def setup(app):
app.add_stylesheet('theme_overrides.css')
app.add_css_file('theme_overrides.css')
3 changes: 1 addition & 2 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ Python support for IsoTP Transport protocol (ISO-15765)
=======================================================

.. toctree::
:maxdepth: 2
:hidden:

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

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>`_).

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>`_
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>`__
2 changes: 1 addition & 1 deletion isotp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from isotp.tpsock import socket
from isotp.protocol import TransportLayer, CanStack, CanMessage
from isotp.address import *
from isotp.errors import *
from isotp.errors import *
43 changes: 23 additions & 20 deletions isotp/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ def get_name(cls, num):

return 'Unknown'


class TargetAddressType:
Physical = 0 # 1 to 1 communication
Functional = 1 # 1 to n communication


class Address:
"""
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.
Expand Down Expand Up @@ -63,32 +65,33 @@ class Address:
:type address_extension: int or None
"""

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):
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):

self.addressing_mode = addressing_mode
self.target_address = target_address
self.source_address = source_address
self.address_extension = address_extension
self.txid = txid
self.rxid = rxid
self.is_29bits = True if self.addressing_mode in [ AddressingMode.Normal_29bits, AddressingMode.NormalFixed_29bits, AddressingMode.Extended_29bits, AddressingMode.Mixed_29bits] else False
self.addressing_mode = addressing_mode
self.target_address = target_address
self.source_address = source_address
self.address_extension = address_extension
self.txid = txid
self.rxid = rxid
self.is_29bits = True if self.addressing_mode in [
AddressingMode.Normal_29bits, AddressingMode.NormalFixed_29bits, AddressingMode.Extended_29bits, AddressingMode.Mixed_29bits] else False

if self.addressing_mode == AddressingMode.NormalFixed_29bits:
self.physical_id = 0x18DA0000 if physical_id is None else physical_id & 0x1FFF0000
self.physical_id = 0x18DA0000 if physical_id is None else physical_id & 0x1FFF0000
self.functional_id = 0x18DB0000 if functional_id is None else functional_id & 0x1FFF0000

if self.addressing_mode == AddressingMode.Mixed_29bits:
self.physical_id = 0x18CE0000 if physical_id is None else physical_id & 0x1FFF0000
self.physical_id = 0x18CE0000 if physical_id is None else physical_id & 0x1FFF0000
self.functional_id = 0x18CD0000 if functional_id is None else functional_id & 0x1FFF0000

self.validate()

# From here, input is good. Do some precomputing for speed optimization without bothering about types or values
self.tx_arbitration_id_physical = self._get_tx_arbitraton_id(TargetAddressType.Physical)
self.tx_arbitration_id_functional = self._get_tx_arbitraton_id(TargetAddressType.Functional)
self.tx_arbitration_id_physical = self._get_tx_arbitraton_id(TargetAddressType.Physical)
self.tx_arbitration_id_functional = self._get_tx_arbitraton_id(TargetAddressType.Functional)

self.rx_arbitration_id_physical = self._get_rx_arbitration_id(TargetAddressType.Physical)
self.rx_arbitration_id_functional = self._get_rx_arbitration_id(TargetAddressType.Functional)
self.rx_arbitration_id_physical = self._get_rx_arbitration_id(TargetAddressType.Physical)
self.rx_arbitration_id_functional = self._get_rx_arbitration_id(TargetAddressType.Functional)

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

def validate(self):
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]:
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]:
raise ValueError('Addressing mode is not valid')

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

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

def _is_for_me_normal(self, msg):
Expand Down Expand Up @@ -253,7 +256,7 @@ def requires_extension_byte(self):
def get_tx_extension_byte(self):
if self.addressing_mode in [AddressingMode.Extended_11bits, AddressingMode.Extended_29bits]:
return self.target_address
if self.addressing_mode in [ AddressingMode.Mixed_11bits, AddressingMode.Mixed_29bits]:
if self.addressing_mode in [AddressingMode.Mixed_11bits, AddressingMode.Mixed_29bits]:
return self.address_extension

def get_rx_extension_byte(self):
Expand All @@ -264,12 +267,12 @@ def get_rx_extension_byte(self):

def get_content_str(self):
val_dict = {}
keys = ['target_address', 'source_address', 'address_extension', 'txid', 'rxid']
keys = ['target_address', 'source_address', 'address_extension', 'txid', 'rxid']
for key in keys:
val = getattr(self, key)
if val is not None:
val_dict[key] = val
vals_str = ', '.join(['%s:0x%02x' % (k,val_dict[k]) for k in val_dict])
vals_str = ', '.join(['%s:0x%02x' % (k, val_dict[k]) for k in val_dict])
return '[%s - %s]' % (AddressingMode.get_name(self.addressing_mode), vals_str)

def __repr__(self):
Expand Down
13 changes: 10 additions & 3 deletions isotp/address.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ class AddressingMode:
Extended_29bits: int
Mixed_11bits: int
Mixed_29bits: int

@classmethod
def get_name(cls,
num: int) -> str: ...


class TargetAddressType:
Physical: int
Functional: int


class Address:
addressing_mode: int
target_address: Optional[int]
Expand All @@ -32,19 +35,23 @@ class Address:
tx_payload_prefix: bytearray
rx_prefix_size: int
is_for_me: bool

def __init__(self,
addressing_mode: int=...,
addressing_mode: int = ...,
txid: Optional[int] = ...,
rxid: Optional[int] = ...,
target_address: Optional[int] = ...,
source_address: Optional[int] = ...,
address_extension: Optional[int] = ...,
**kwargs: Dict[Any, Any]) -> None: ...

def validate(self) -> None: ...

def get_tx_arbitraton_id(self,
address_type:TargetAddressType=...) -> Optional[int]: ...
address_type: TargetAddressType = ...) -> Optional[int]: ...
def get_rx_arbitraton_id(self,
address_type:TargetAddressType=...) -> Optional[int]: ...
address_type: TargetAddressType = ...) -> Optional[int]: ...

def requires_extension_byte(self) -> bool: ...
def get_tx_extension_byte(self) -> Optional[int]: ...
def get_rx_extension_byte(self) -> Optional[int]: ...
Expand Down
Loading

0 comments on commit a5b1df2

Please sign in to comment.