Skip to content

Commit fcd156a

Browse files
committed
unify imports (ebroecker#236)
1 parent d11c0d3 commit fcd156a

25 files changed

+92
-98
lines changed

src/canmatrix/cancluster.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import
2+
from __future__ import absolute_import, division, print_function
3+
34
import typing
45

56
import canmatrix

src/canmatrix/canmatrix.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@
2626

2727
# TODO: Definitions should be disassembled
2828

29-
from __future__ import division, absolute_import
29+
from __future__ import absolute_import, division, print_function
3030

3131
import decimal
3232
import fnmatch
33+
import itertools
3334
import logging
3435
import math
3536
import struct
3637
import typing
37-
from itertools import chain
3838

3939
try:
4040
from itertools import zip_longest as zip_longest
4141
except ImportError:
4242
from itertools import izip_longest as zip_longest # type: ignore
4343

44-
from past.builtins import basestring
4544
import attr
45+
from past.builtins import basestring
4646

4747
import canmatrix.copy
4848
import canmatrix.types
@@ -1057,7 +1057,7 @@ def get_frame_layout(self):
10571057
big_bit_signals.append(signal)
10581058

10591059
little_bits_iter = reversed(tuple(grouper(little_bits, 8)))
1060-
little_bits = list(chain(*little_bits_iter))
1060+
little_bits = list(itertools.chain(*little_bits_iter))
10611061

10621062
return_list = [
10631063
little + big
@@ -1119,7 +1119,7 @@ def signals_to_bytes(self, data):
11191119

11201120
big_bits[most:least] = bits
11211121
little_bits_iter = reversed(tuple(grouper(little_bits, 8)))
1122-
little_bits = list(chain(*little_bits_iter))
1122+
little_bits = list(itertools.chain(*little_bits_iter))
11231123
bitstring = ''.join(
11241124
next(x for x in (l, b, '0') if x is not None)
11251125
# l if l != ' ' else (b if b != ' ' else '0')

src/canmatrix/cli/compare.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
2222
# DAMAGE.
2323

24-
from __future__ import absolute_import
25-
from __future__ import print_function
24+
from __future__ import absolute_import, division, print_function
2625

2726
import logging
2827
import sys

src/canmatrix/cli/convert.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
2222
# DAMAGE.
2323

24-
from __future__ import absolute_import
25-
from __future__ import print_function
24+
from __future__ import absolute_import, division, print_function
2625

2726
import logging
2827
import sys

src/canmatrix/compare.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@
1919
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
2020
# DAMAGE.
2121

22-
from __future__ import absolute_import
23-
from __future__ import print_function
22+
from __future__ import absolute_import, division, print_function
2423

2524
import logging
26-
import optparse
2725
import sys
2826
import typing
2927

src/canmatrix/convert.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
2020
# DAMAGE.
2121

22-
from __future__ import absolute_import
23-
from __future__ import print_function
22+
from __future__ import absolute_import, division, print_function
2423

2524
import logging
2625
import sys

src/canmatrix/copy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
2020
# DAMAGE.
2121

22-
from __future__ import absolute_import
22+
from __future__ import absolute_import, division, print_function
2323

2424
import copy
2525
import logging

src/canmatrix/formats/__init__.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# -*- coding: utf-8 -*-
2-
from importlib import import_module
3-
import sys
2+
import importlib
43
import logging
54
import os
5+
import sys
66
import typing
77

88
import canmatrix
99
import canmatrix.cancluster
10+
1011
if sys.version_info > (3, 0):
1112
import io
1213
else:
@@ -21,7 +22,7 @@
2122

2223
for module in moduleList:
2324
try:
24-
import_module("canmatrix.formats." + module)
25+
importlib.import_module("canmatrix.formats." + module)
2526
loadedFormats.append(module)
2627
except ImportError:
2728
logger.info("%s is not supported", module)

src/canmatrix/formats/arxml.py

+18-18
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,14 @@
2424
# arxml-files are the can-matrix-definitions and a lot more in AUTOSAR-Context
2525
# currently Support for Autosar 3.2 and 4.0-4.3 is planned
2626

27-
from __future__ import absolute_import
28-
from __future__ import division
29-
from __future__ import print_function
27+
from __future__ import absolute_import, division, print_function
3028

3129
import decimal
3230
import logging
3331
import typing
3432
from builtins import *
3533

36-
from lxml import etree
34+
import lxml.etree
3735

3836
import canmatrix
3937
import canmatrix.types
@@ -47,7 +45,7 @@
4745

4846

4947
class ArTree(object):
50-
def __init__(self, name="", ref=None): # type: (str, etree._Element) -> None
48+
def __init__(self, name="", ref=None): # type: (str, lxml.etree._Element) -> None
5149
self._name = name
5250
self._ref = ref
5351
self._array = [] # type: typing.List[ArTree]
@@ -65,20 +63,20 @@ def get_child_by_name(self, name): # type: (str) -> typing.Union[ArTree, None]
6563
return None
6664

6765
@property
68-
def ref(self): # type: () -> etree._Element
66+
def ref(self): # type: () -> lxml.etree._Element
6967
return self._ref
7068

7169

7270
# for typing only
73-
_Element = etree._Element
71+
_Element = lxml.etree._Element
7472
_DocRoot = typing.Union[_Element, ArTree]
7573
_MultiplexId = typing.Union[str, int, None]
7674
_FloatFactory = typing.Callable[[typing.Any], typing.Any]
7775

7876

7977
def create_sub_element(parent, element_name, text=None):
8078
# type: (_Element, str, typing.Optional[str]) -> _Element
81-
sn = etree.SubElement(parent, element_name)
79+
sn = lxml.etree.SubElement(parent, element_name)
8280
if text is not None:
8381
sn.text = str(text)
8482
return sn
@@ -135,7 +133,7 @@ def dump(dbs, f, **options):
135133

136134
if ar_version[0] == "3":
137135
xsi = 'http://www.w3.org/2001/XMLSchema-instance'
138-
root = etree.Element(
136+
root = lxml.etree.Element(
139137
'AUTOSAR',
140138
nsmap={
141139
None: 'http://autosar.org/' + ar_version,
@@ -145,7 +143,7 @@ def dump(dbs, f, **options):
145143
top_level_packages = create_sub_element(root, 'TOP-LEVEL-PACKAGES')
146144
else:
147145
xsi = 'http://www.w3.org/2001/XMLSchema-instance'
148-
root = etree.Element(
146+
root = lxml.etree.Element(
149147
'AUTOSAR',
150148
nsmap={
151149
None: "http://autosar.org/schema/r4.0",
@@ -760,7 +758,7 @@ def dump(dbs, f, **options):
760758
ipdu_ref.set('DEST', "I-SIGNAL-I-PDU")
761759
ipdu_ref.text = "/PDU/PDU_" + frame_name
762760

763-
f.write(etree.tostring(root, pretty_print=True, xml_declaration=True))
761+
f.write(lxml.etree.tostring(root, pretty_print=True, xml_declaration=True))
764762

765763

766764
###################################
@@ -1000,7 +998,7 @@ def get_signals(signal_array, frame, root_or_cache, ns, multiplex_id, float_fact
1000998

1001999
base_type = get_child(isignal, "BASE-TYPE", root_or_cache, ns)
10021000
try:
1003-
type_encoding = get_child(base_type,"BASE-TYPE-ENCODING", root_or_cache, ns).text
1001+
type_encoding = get_child(base_type, "BASE-TYPE-ENCODING", root_or_cache, ns).text
10041002
except AttributeError:
10051003
type_encoding = "None"
10061004
signal_name = None # type: typing.Optional[str]
@@ -1192,6 +1190,7 @@ def get_signals(signal_array, frame, root_or_cache, ns, multiplex_id, float_fact
11921190
new_signal.add_attribute("LongName", signal_name)
11931191
frame.add_signal(new_signal)
11941192

1193+
11951194
def get_frame_from_multiplexed_ipdu(pdu, target_frame, multiplex_translation, root_or_cache, ns, float_factory):
11961195
selector_byte_order = get_child(pdu, "SELECTOR-FIELD-BYTE-ORDER", root_or_cache, ns)
11971196
selector_len = get_child(pdu, "SELECTOR-FIELD-LENGTH", root_or_cache, ns)
@@ -1244,8 +1243,8 @@ def get_frame_from_container_ipdu(pdu, target_frame, root_or_cache, ns, float_fa
12441243
header_type = get_child(pdu, "HEADER-TYPE", root_or_cache, ns).text
12451244
if header_type == "SHORT-HEADER":
12461245
header_length = 32
1247-
target_frame.add_signal(canmatrix.Signal(start_bit=0, size=24, name="Header_ID", multiplex ="Multiplexor", is_little_endian = True))
1248-
target_frame.add_signal(canmatrix.Signal(start_bit=24, size= 8, name="Header_DLC", is_little_endian = True))
1246+
target_frame.add_signal(canmatrix.Signal(start_bit=0, size=24, name="Header_ID", multiplex="Multiplexor", is_little_endian=True))
1247+
target_frame.add_signal(canmatrix.Signal(start_bit=24, size=8, name="Header_DLC", is_little_endian=True))
12491248
elif header_type == "LONG-HEADER":
12501249
header_length = 64
12511250
target_frame.add_signal(canmatrix.Signal(start_bit=0, size=32, name="Header_ID", multiplex="Multiplexor",
@@ -1254,7 +1253,7 @@ def get_frame_from_container_ipdu(pdu, target_frame, root_or_cache, ns, float_fa
12541253
else:
12551254
raise("header " + header_type + " not supported for containers yet")
12561255
# none type
1257-
#TODO
1256+
# TODO
12581257

12591258
for cpdu in pdus:
12601259
ipdu = get_child(cpdu, "I-PDU", root_or_cache, ns)
@@ -1264,7 +1263,7 @@ def get_frame_from_container_ipdu(pdu, target_frame, root_or_cache, ns, float_fa
12641263
elif header_type == "LONG-HEADER":
12651264
header_id = get_child(ipdu, "HEADER-ID-LONG-HEADER", root_or_cache, ns).text
12661265
else:
1267-
#none type
1266+
# none type
12681267
pass
12691268
except AttributeError:
12701269
header_id = "0"
@@ -1286,6 +1285,7 @@ def get_frame_from_container_ipdu(pdu, target_frame, root_or_cache, ns, float_fa
12861285
singnals_grouped += new_signals
12871286
signal_group_id += 1
12881287

1288+
12891289
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):
12901290
if cyclic_timing is not None and event_timing is not None:
12911291
target_frame.add_attribute("GenMsgSendType", "cyclicAndSpontanX") # CycleAndSpontan
@@ -1602,7 +1602,7 @@ def load(file, **options):
16021602

16031603
result = {}
16041604
logger.debug("Read arxml ...")
1605-
tree = etree.parse(file)
1605+
tree = lxml.etree.parse(file)
16061606

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

16521652
if ignore_cluster_info is True:
1653-
ccs = [etree.Element("ignoreClusterInfo")] # type: typing.Sequence[_Element]
1653+
ccs = [lxml.etree.Element("ignoreClusterInfo")] # type: typing.Sequence[_Element]
16541654
else:
16551655
ccs = root.findall('.//' + ns + 'CAN-CLUSTER')
16561656
for cc in ccs: # type: _Element

src/canmatrix/formats/cmcsv.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# this script exports canmatrix-objects to a CSV file. (Based on xlsx)
2424
# Author: Martin Hoffmann ([email protected])
2525

26-
from __future__ import absolute_import
26+
from __future__ import absolute_import, division, print_function
2727

2828
import collections
2929
import csv

src/canmatrix/formats/cmjson.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# json-files are the can-matrix-definitions of the CANard-project
2525
# (https://github.com/ericevenchick/CANard)
2626

27-
from __future__ import absolute_import
27+
from __future__ import absolute_import, division, print_function
2828

2929
import json
3030
import sys

src/canmatrix/formats/dbc.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
# this script exports dbc-files from a canmatrix-object
2424
# dbc-files are the can-matrix-definitions of the CANoe (Vector Informatic)
2525

26-
from __future__ import absolute_import
27-
from __future__ import division
28-
from __future__ import print_function
26+
from __future__ import absolute_import, division, print_function
2927

3028
import collections
3129
import copy

src/canmatrix/formats/dbf.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
# this script imports dbf-files in a canmatrix-object
2424
# dbf-files are the can-matrix-definitions of the busmaster-project (http://rbei-etas.github.io/busmaster/)
2525
#
26-
from __future__ import absolute_import
27-
from __future__ import division
28-
from __future__ import print_function
26+
from __future__ import absolute_import, division, print_function
2927

3028
import copy
3129
import decimal

0 commit comments

Comments
 (0)