Skip to content

Commit c93a2bf

Browse files
committed
Python2+3: Use absolute import where possible
1 parent 4322bee commit c93a2bf

File tree

8 files changed

+86
-85
lines changed

8 files changed

+86
-85
lines changed

tools/arm_pack_manager/pack_manager.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
from __future__ import print_function, division, absolute_import
12
import argparse
23
from os.path import basename
34
from tools.arm_pack_manager import Cache
45
from os.path import basename, join, dirname, exists
56
from os import makedirs
67
from itertools import takewhile
78
from fuzzywuzzy import process
8-
from tools.arm_pack_manager import Cache
9+
from .arm_pack_manager import Cache
910

1011
parser = argparse.ArgumentParser(description='A Handy little utility for keeping your cache of pack files up to date.')
1112
subparsers = parser.add_subparsers(title="Commands")
@@ -133,12 +134,12 @@ def command_find_part (cache, matches, long=False, intersection=True,
133134
aliases = sum([fuzzy_find([m], cache.aliases.keys()) for m in matches], [])
134135
if print_parts:
135136
for part in choices :
136-
print part
137+
print(part)
137138
if long :
138139
pp.pprint(cache.index[part])
139140
if print_aliases:
140141
for alias in aliases :
141-
print alias
142+
print(alias)
142143
if long :
143144
pp.pprint(cache.index[cache.aliases[alias]])
144145

tools/build_api.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
"""
17-
from __future__ import print_function
17+
from __future__ import print_function, division, absolute_import
1818

1919
import re
2020
import tempfile
@@ -27,20 +27,22 @@
2727
from time import time
2828
from intelhex import IntelHex
2929
from json import load, dump
30-
from tools.arm_pack_manager import Cache
31-
32-
from tools.utils import mkdir, run_cmd, run_cmd_ext, NotSupportedException,\
33-
ToolException, InvalidReleaseTargetException, intelhex_offset
34-
from tools.paths import MBED_CMSIS_PATH, MBED_TARGETS_PATH, MBED_LIBRARIES,\
35-
MBED_HEADER, MBED_DRIVERS, MBED_PLATFORM, MBED_HAL, MBED_CONFIG_FILE,\
36-
MBED_LIBRARIES_DRIVERS, MBED_LIBRARIES_PLATFORM, MBED_LIBRARIES_HAL,\
37-
BUILD_DIR
38-
from tools.targets import TARGET_NAMES, TARGET_MAP
39-
from tools.libraries import Library
40-
from tools.toolchains import TOOLCHAIN_CLASSES
4130
from jinja2 import FileSystemLoader
4231
from jinja2.environment import Environment
43-
from tools.config import Config
32+
33+
from .arm_pack_manager import Cache
34+
from .utils import (mkdir, run_cmd, run_cmd_ext, NotSupportedException,
35+
ToolException, InvalidReleaseTargetException,
36+
intelhex_offset)
37+
from .paths import (MBED_CMSIS_PATH, MBED_TARGETS_PATH, MBED_LIBRARIES,
38+
MBED_HEADER, MBED_DRIVERS, MBED_PLATFORM, MBED_HAL,
39+
MBED_CONFIG_FILE, MBED_LIBRARIES_DRIVERS,
40+
MBED_LIBRARIES_PLATFORM, MBED_LIBRARIES_HAL,
41+
BUILD_DIR)
42+
from .targets import TARGET_NAMES, TARGET_MAP
43+
from .libraries import Library
44+
from .toolchains import TOOLCHAIN_CLASSES
45+
from .config import Config
4446

4547
RELEASE_VERSIONS = ['2', '5']
4648

tools/config/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
"""
17+
from __future__ import print_function, division, absolute_import
1718

1819
from copy import deepcopy
1920
from six import moves
@@ -28,11 +29,11 @@
2829
from jinja2 import FileSystemLoader, StrictUndefined
2930
from jinja2.environment import Environment
3031
from jsonschema import Draft4Validator, RefResolver
31-
# Implementation of mbed configuration mechanism
32-
from tools.utils import json_file_to_dict, intelhex_offset
33-
from tools.arm_pack_manager import Cache
34-
from tools.targets import CUMULATIVE_ATTRIBUTES, TARGET_MAP, \
35-
generate_py_target, get_resolution_order, Target
32+
33+
from ..utils import json_file_to_dict, intelhex_offset
34+
from ..arm_pack_manager import Cache
35+
from ..targets import (CUMULATIVE_ATTRIBUTES, TARGET_MAP, generate_py_target,
36+
get_resolution_order, Target)
3637

3738
try:
3839
unicode

tools/export/__init__.py

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,57 +15,52 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717

18+
from __future__ import print_function, division, absolute_import
19+
1820
import sys
1921
from os.path import join, abspath, dirname, exists
2022
from os.path import basename, relpath, normpath, splitext
2123
from os import makedirs, walk
2224
import copy
2325
from shutil import rmtree, copyfile
2426
import zipfile
25-
ROOT = abspath(join(dirname(__file__), ".."))
26-
sys.path.insert(0, ROOT)
27-
28-
from tools.build_api import prepare_toolchain
29-
from tools.build_api import scan_resources
30-
from tools.toolchains import Resources
31-
from tools.export import lpcxpresso, ds5_5, iar, makefile
32-
from tools.export import embitz, coide, kds, simplicity, atmelstudio, mcuxpresso
33-
from tools.export import sw4stm32, e2studio, zip, cmsis, uvision, cdt, vscode
34-
from tools.export import gnuarmeclipse
35-
from tools.export import qtcreator
36-
from tools.export import cmake
37-
from tools.export import nb
38-
from tools.targets import TARGET_NAMES
27+
28+
from ..build_api import prepare_toolchain, scan_resources
29+
from ..toolchains import Resources
30+
from ..targets import TARGET_NAMES
31+
from . import (lpcxpresso, ds5_5, iar, makefile, embitz, coide, kds, simplicity,
32+
atmelstudio, mcuxpresso, sw4stm32, e2studio, zip, cmsis, uvision,
33+
cdt, vscode, gnuarmeclipse, qtcreator, cmake, nb)
3934

4035
EXPORTERS = {
41-
'uvision5': uvision.Uvision,
42-
'uvision': uvision.Uvision,
43-
'lpcxpresso': lpcxpresso.LPCXpresso,
44-
'gcc_arm': makefile.GccArm,
45-
'make_gcc_arm': makefile.GccArm,
46-
'make_armc5': makefile.Armc5,
47-
'make_armc6': makefile.Armc6,
48-
'make_iar': makefile.IAR,
49-
'ds5_5': ds5_5.DS5_5,
50-
'iar': iar.IAR,
51-
'embitz' : embitz.EmBitz,
52-
'coide' : coide.CoIDE,
53-
'kds' : kds.KDS,
54-
'simplicityv3' : simplicity.SimplicityV3,
55-
'atmelstudio' : atmelstudio.AtmelStudio,
56-
'sw4stm32' : sw4stm32.Sw4STM32,
57-
'e2studio' : e2studio.E2Studio,
58-
'eclipse_gcc_arm' : cdt.EclipseGcc,
59-
'eclipse_iar' : cdt.EclipseIAR,
60-
'eclipse_armc5' : cdt.EclipseArmc5,
61-
'gnuarmeclipse': gnuarmeclipse.GNUARMEclipse,
62-
'netbeans': nb.GNUARMNetbeans,
63-
'mcuxpresso': mcuxpresso.MCUXpresso,
64-
'qtcreator': qtcreator.QtCreator,
65-
'vscode_gcc_arm' : vscode.VSCodeGcc,
66-
'vscode_iar' : vscode.VSCodeIAR,
67-
'vscode_armc5' : vscode.VSCodeArmc5,
68-
'cmake_gcc_arm': cmake.GccArm
36+
u'uvision5': uvision.Uvision,
37+
u'uvision': uvision.Uvision,
38+
u'lpcxpresso': lpcxpresso.LPCXpresso,
39+
u'gcc_arm': makefile.GccArm,
40+
u'make_gcc_arm': makefile.GccArm,
41+
u'make_armc5': makefile.Armc5,
42+
u'make_armc6': makefile.Armc6,
43+
u'make_iar': makefile.IAR,
44+
u'ds5_5': ds5_5.DS5_5,
45+
u'iar': iar.IAR,
46+
u'embitz' : embitz.EmBitz,
47+
u'coide' : coide.CoIDE,
48+
u'kds' : kds.KDS,
49+
u'simplicityv3' : simplicity.SimplicityV3,
50+
u'atmelstudio' : atmelstudio.AtmelStudio,
51+
u'sw4stm32' : sw4stm32.Sw4STM32,
52+
u'e2studio' : e2studio.E2Studio,
53+
u'eclipse_gcc_arm' : cdt.EclipseGcc,
54+
u'eclipse_iar' : cdt.EclipseIAR,
55+
u'eclipse_armc5' : cdt.EclipseArmc5,
56+
u'gnuarmeclipse': gnuarmeclipse.GNUARMEclipse,
57+
u'mcuxpresso': mcuxpresso.MCUXpresso,
58+
u'netbeans': nb.GNUARMNetbeans,
59+
u'qtcreator': qtcreator.QtCreator,
60+
u'vscode_gcc_arm' : vscode.VSCodeGcc,
61+
u'vscode_iar' : vscode.VSCodeIAR,
62+
u'vscode_armc5' : vscode.VSCodeArmc5,
63+
u'cmake_gcc_arm': cmake.GccArm
6964
}
7065

7166
ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN = """

tools/memap.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22

33
"""Memory Map File Analyser for ARM mbed"""
4-
from __future__ import print_function
4+
from __future__ import print_function, division, absolute_import
55

66
from abc import abstractmethod, ABCMeta
77
from sys import stdout, exit, argv
@@ -16,8 +16,8 @@
1616
from prettytable import PrettyTable
1717
from tools.arm_pack_manager import Cache
1818

19-
from tools.utils import argparse_filestring_type, \
20-
argparse_lowercase_hyphen_type, argparse_uppercase_type
19+
from .utils import (argparse_filestring_type, argparse_lowercase_hyphen_type,
20+
argparse_uppercase_type)
2121

2222

2323
class _Parser(object):

tools/options.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,19 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
"""
17+
from __future__ import print_function, division, absolute_import
18+
1719
from json import load
1820
from os.path import join, dirname
1921
from os import listdir
2022
from argparse import ArgumentParser, ArgumentTypeError
21-
from tools.toolchains import TOOLCHAINS
22-
from tools.targets import TARGET_NAMES, Target, update_target_data
23-
from tools.utils import argparse_force_uppercase_type, \
24-
argparse_lowercase_hyphen_type, argparse_many, \
25-
argparse_filestring_type, args_error, argparse_profile_filestring_type,\
26-
argparse_deprecate
23+
24+
from .toolchains import TOOLCHAINS
25+
from .targets import TARGET_NAMES, Target, update_target_data
26+
from .utils import (argparse_force_uppercase_type, argparse_deprecate,
27+
argparse_lowercase_hyphen_type, argparse_many,
28+
argparse_filestring_type, args_error,
29+
argparse_profile_filestring_type)
2730

2831
FLAGS_DEPRECATION_MESSAGE = "Please use the --profile argument instead.\n"\
2932
"Documentation may be found in "\

tools/toolchains/__init__.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,31 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
"""
17-
from __future__ import print_function
17+
from __future__ import print_function, division, absolute_import
1818

1919
import re
2020
import sys
2121
from os import stat, walk, getcwd, sep, remove
2222
from copy import copy
2323
from time import time, sleep
2424
from shutil import copyfile
25-
from os.path import join, splitext, exists, relpath, dirname, basename, split, abspath, isfile, isdir, normcase
25+
from os.path import (join, splitext, exists, relpath, dirname, basename, split,
26+
abspath, isfile, isdir, normcase)
2627
from itertools import chain
2728
from inspect import getmro
2829
from copy import deepcopy
2930
from abc import ABCMeta, abstractmethod
3031
from distutils.spawn import find_executable
31-
3232
from multiprocessing import Pool, cpu_count
33-
from tools.utils import run_cmd, mkdir, rel_path, ToolException, NotSupportedException, split_path, compile_worker
34-
from tools.settings import MBED_ORG_USER
35-
import tools.hooks as hooks
36-
from tools.memap import MemapParser
3733
from hashlib import md5
3834
import fnmatch
3935

36+
from ..utils import (run_cmd, mkdir, rel_path, ToolException,
37+
NotSupportedException, split_path, compile_worker)
38+
from ..settings import MBED_ORG_USER
39+
from .. import hooks
40+
from ..memap import MemapParser
41+
4042

4143
#Disables multiprocessing if set to higher number than the host machine CPUs
4244
CPU_COUNT_MIN = 1

tools/utils.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
"""
17-
from __future__ import print_function
17+
from __future__ import print_function, division, absolute_import
1818
import sys
1919
import inspect
2020
import os
@@ -417,11 +417,8 @@ def parse_type(string):
417417
if not isinstance(string, unicode):
418418
string = string.decode()
419419
for option in lst:
420-
try:
421-
if case(string) == case(option):
422-
return option
423-
except Exception as e:
424-
print(e)
420+
if case(string) == case(option):
421+
return option
425422
raise argparse.ArgumentTypeError(
426423
"{0} is not a supported {1}. Supported {1}s are:\n{2}".
427424
format(string, type_name, columnate(lst)))

0 commit comments

Comments
 (0)