Skip to content

Commit

Permalink
unify imports (ebroecker#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
Funth0mas committed Sep 18, 2019
1 parent d11c0d3 commit fcd156a
Show file tree
Hide file tree
Showing 25 changed files with 92 additions and 98 deletions.
3 changes: 2 additions & 1 deletion src/canmatrix/cancluster.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import absolute_import, division, print_function

import typing

import canmatrix
Expand Down
10 changes: 5 additions & 5 deletions src/canmatrix/canmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@

# TODO: Definitions should be disassembled

from __future__ import division, absolute_import
from __future__ import absolute_import, division, print_function

import decimal
import fnmatch
import itertools
import logging
import math
import struct
import typing
from itertools import chain

try:
from itertools import zip_longest as zip_longest
except ImportError:
from itertools import izip_longest as zip_longest # type: ignore

from past.builtins import basestring
import attr
from past.builtins import basestring

import canmatrix.copy
import canmatrix.types
Expand Down Expand Up @@ -1057,7 +1057,7 @@ def get_frame_layout(self):
big_bit_signals.append(signal)

little_bits_iter = reversed(tuple(grouper(little_bits, 8)))
little_bits = list(chain(*little_bits_iter))
little_bits = list(itertools.chain(*little_bits_iter))

return_list = [
little + big
Expand Down Expand Up @@ -1119,7 +1119,7 @@ def signals_to_bytes(self, data):

big_bits[most:least] = bits
little_bits_iter = reversed(tuple(grouper(little_bits, 8)))
little_bits = list(chain(*little_bits_iter))
little_bits = list(itertools.chain(*little_bits_iter))
bitstring = ''.join(
next(x for x in (l, b, '0') if x is not None)
# l if l != ' ' else (b if b != ' ' else '0')
Expand Down
3 changes: 1 addition & 2 deletions src/canmatrix/cli/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

from __future__ import absolute_import
from __future__ import print_function
from __future__ import absolute_import, division, print_function

import logging
import sys
Expand Down
3 changes: 1 addition & 2 deletions src/canmatrix/cli/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

from __future__ import absolute_import
from __future__ import print_function
from __future__ import absolute_import, division, print_function

import logging
import sys
Expand Down
4 changes: 1 addition & 3 deletions src/canmatrix/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

from __future__ import absolute_import
from __future__ import print_function
from __future__ import absolute_import, division, print_function

import logging
import optparse
import sys
import typing

Expand Down
3 changes: 1 addition & 2 deletions src/canmatrix/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

from __future__ import absolute_import
from __future__ import print_function
from __future__ import absolute_import, division, print_function

import logging
import sys
Expand Down
2 changes: 1 addition & 1 deletion src/canmatrix/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

from __future__ import absolute_import
from __future__ import absolute_import, division, print_function

import copy
import logging
Expand Down
7 changes: 4 additions & 3 deletions src/canmatrix/formats/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# -*- coding: utf-8 -*-
from importlib import import_module
import sys
import importlib
import logging
import os
import sys
import typing

import canmatrix
import canmatrix.cancluster

if sys.version_info > (3, 0):
import io
else:
Expand All @@ -21,7 +22,7 @@

for module in moduleList:
try:
import_module("canmatrix.formats." + module)
importlib.import_module("canmatrix.formats." + module)
loadedFormats.append(module)
except ImportError:
logger.info("%s is not supported", module)
Expand Down
36 changes: 18 additions & 18 deletions src/canmatrix/formats/arxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@
# arxml-files are the can-matrix-definitions and a lot more in AUTOSAR-Context
# currently Support for Autosar 3.2 and 4.0-4.3 is planned

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import, division, print_function

import decimal
import logging
import typing
from builtins import *

from lxml import etree
import lxml.etree

import canmatrix
import canmatrix.types
Expand All @@ -47,7 +45,7 @@


class ArTree(object):
def __init__(self, name="", ref=None): # type: (str, etree._Element) -> None
def __init__(self, name="", ref=None): # type: (str, lxml.etree._Element) -> None
self._name = name
self._ref = ref
self._array = [] # type: typing.List[ArTree]
Expand All @@ -65,20 +63,20 @@ def get_child_by_name(self, name): # type: (str) -> typing.Union[ArTree, None]
return None

@property
def ref(self): # type: () -> etree._Element
def ref(self): # type: () -> lxml.etree._Element
return self._ref


# for typing only
_Element = etree._Element
_Element = lxml.etree._Element
_DocRoot = typing.Union[_Element, ArTree]
_MultiplexId = typing.Union[str, int, None]
_FloatFactory = typing.Callable[[typing.Any], typing.Any]


def create_sub_element(parent, element_name, text=None):
# type: (_Element, str, typing.Optional[str]) -> _Element
sn = etree.SubElement(parent, element_name)
sn = lxml.etree.SubElement(parent, element_name)
if text is not None:
sn.text = str(text)
return sn
Expand Down Expand Up @@ -135,7 +133,7 @@ def dump(dbs, f, **options):

if ar_version[0] == "3":
xsi = 'http://www.w3.org/2001/XMLSchema-instance'
root = etree.Element(
root = lxml.etree.Element(
'AUTOSAR',
nsmap={
None: 'http://autosar.org/' + ar_version,
Expand All @@ -145,7 +143,7 @@ def dump(dbs, f, **options):
top_level_packages = create_sub_element(root, 'TOP-LEVEL-PACKAGES')
else:
xsi = 'http://www.w3.org/2001/XMLSchema-instance'
root = etree.Element(
root = lxml.etree.Element(
'AUTOSAR',
nsmap={
None: "http://autosar.org/schema/r4.0",
Expand Down Expand Up @@ -760,7 +758,7 @@ def dump(dbs, f, **options):
ipdu_ref.set('DEST', "I-SIGNAL-I-PDU")
ipdu_ref.text = "/PDU/PDU_" + frame_name

f.write(etree.tostring(root, pretty_print=True, xml_declaration=True))
f.write(lxml.etree.tostring(root, pretty_print=True, xml_declaration=True))


###################################
Expand Down Expand Up @@ -1000,7 +998,7 @@ def get_signals(signal_array, frame, root_or_cache, ns, multiplex_id, float_fact

base_type = get_child(isignal, "BASE-TYPE", root_or_cache, ns)
try:
type_encoding = get_child(base_type,"BASE-TYPE-ENCODING", root_or_cache, ns).text
type_encoding = get_child(base_type, "BASE-TYPE-ENCODING", root_or_cache, ns).text
except AttributeError:
type_encoding = "None"
signal_name = None # type: typing.Optional[str]
Expand Down Expand Up @@ -1192,6 +1190,7 @@ def get_signals(signal_array, frame, root_or_cache, ns, multiplex_id, float_fact
new_signal.add_attribute("LongName", signal_name)
frame.add_signal(new_signal)


def get_frame_from_multiplexed_ipdu(pdu, target_frame, multiplex_translation, root_or_cache, ns, float_factory):
selector_byte_order = get_child(pdu, "SELECTOR-FIELD-BYTE-ORDER", root_or_cache, ns)
selector_len = get_child(pdu, "SELECTOR-FIELD-LENGTH", root_or_cache, ns)
Expand Down Expand Up @@ -1244,8 +1243,8 @@ def get_frame_from_container_ipdu(pdu, target_frame, root_or_cache, ns, float_fa
header_type = get_child(pdu, "HEADER-TYPE", root_or_cache, ns).text
if header_type == "SHORT-HEADER":
header_length = 32
target_frame.add_signal(canmatrix.Signal(start_bit=0, size=24, name="Header_ID", multiplex ="Multiplexor", is_little_endian = True))
target_frame.add_signal(canmatrix.Signal(start_bit=24, size= 8, name="Header_DLC", is_little_endian = True))
target_frame.add_signal(canmatrix.Signal(start_bit=0, size=24, name="Header_ID", multiplex="Multiplexor", is_little_endian=True))
target_frame.add_signal(canmatrix.Signal(start_bit=24, size=8, name="Header_DLC", is_little_endian=True))
elif header_type == "LONG-HEADER":
header_length = 64
target_frame.add_signal(canmatrix.Signal(start_bit=0, size=32, name="Header_ID", multiplex="Multiplexor",
Expand All @@ -1254,7 +1253,7 @@ def get_frame_from_container_ipdu(pdu, target_frame, root_or_cache, ns, float_fa
else:
raise("header " + header_type + " not supported for containers yet")
# none type
#TODO
# TODO

for cpdu in pdus:
ipdu = get_child(cpdu, "I-PDU", root_or_cache, ns)
Expand All @@ -1264,7 +1263,7 @@ def get_frame_from_container_ipdu(pdu, target_frame, root_or_cache, ns, float_fa
elif header_type == "LONG-HEADER":
header_id = get_child(ipdu, "HEADER-ID-LONG-HEADER", root_or_cache, ns).text
else:
#none type
# none type
pass
except AttributeError:
header_id = "0"
Expand All @@ -1286,6 +1285,7 @@ def get_frame_from_container_ipdu(pdu, target_frame, root_or_cache, ns, float_fa
singnals_grouped += new_signals
signal_group_id += 1


def store_frame_timings(target_frame, cyclic_timing, event_timing, minimum_delay, repeats, starting_time, time_offset, repeating_time, root_or_cache, time_period, ns, float_factory):
if cyclic_timing is not None and event_timing is not None:
target_frame.add_attribute("GenMsgSendType", "cyclicAndSpontanX") # CycleAndSpontan
Expand Down Expand Up @@ -1602,7 +1602,7 @@ def load(file, **options):

result = {}
logger.debug("Read arxml ...")
tree = etree.parse(file)
tree = lxml.etree.parse(file)

root = tree.getroot() # type: _Element
logger.debug(" Done\n")
Expand Down Expand Up @@ -1650,7 +1650,7 @@ def load(file, **options):
logger.debug("%d I-SIGNAL-TO-I-PDU-MAPPING in arxml...", len(sig_ipdu))

if ignore_cluster_info is True:
ccs = [etree.Element("ignoreClusterInfo")] # type: typing.Sequence[_Element]
ccs = [lxml.etree.Element("ignoreClusterInfo")] # type: typing.Sequence[_Element]
else:
ccs = root.findall('.//' + ns + 'CAN-CLUSTER')
for cc in ccs: # type: _Element
Expand Down
2 changes: 1 addition & 1 deletion src/canmatrix/formats/cmcsv.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# this script exports canmatrix-objects to a CSV file. (Based on xlsx)
# Author: Martin Hoffmann ([email protected])

from __future__ import absolute_import
from __future__ import absolute_import, division, print_function

import collections
import csv
Expand Down
2 changes: 1 addition & 1 deletion src/canmatrix/formats/cmjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# json-files are the can-matrix-definitions of the CANard-project
# (https://github.com/ericevenchick/CANard)

from __future__ import absolute_import
from __future__ import absolute_import, division, print_function

import json
import sys
Expand Down
4 changes: 1 addition & 3 deletions src/canmatrix/formats/dbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
# this script exports dbc-files from a canmatrix-object
# dbc-files are the can-matrix-definitions of the CANoe (Vector Informatic)

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import, division, print_function

import collections
import copy
Expand Down
4 changes: 1 addition & 3 deletions src/canmatrix/formats/dbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
# this script imports dbf-files in a canmatrix-object
# dbf-files are the can-matrix-definitions of the busmaster-project (http://rbei-etas.github.io/busmaster/)
#
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import, division, print_function

import copy
import decimal
Expand Down
Loading

0 comments on commit fcd156a

Please sign in to comment.