Python2+3: Use absolute import where possible

pull/5848/head
Jimmy Brisson 2018-01-12 16:34:32 -06:00
parent 4322bee175
commit c93a2bfa4c
8 changed files with 85 additions and 84 deletions

View File

@ -1,3 +1,4 @@
from __future__ import print_function, division, absolute_import
import argparse import argparse
from os.path import basename from os.path import basename
from tools.arm_pack_manager import Cache from tools.arm_pack_manager import Cache
@ -5,7 +6,7 @@ from os.path import basename, join, dirname, exists
from os import makedirs from os import makedirs
from itertools import takewhile from itertools import takewhile
from fuzzywuzzy import process from fuzzywuzzy import process
from tools.arm_pack_manager import Cache from .arm_pack_manager import Cache
parser = argparse.ArgumentParser(description='A Handy little utility for keeping your cache of pack files up to date.') parser = argparse.ArgumentParser(description='A Handy little utility for keeping your cache of pack files up to date.')
subparsers = parser.add_subparsers(title="Commands") subparsers = parser.add_subparsers(title="Commands")
@ -133,12 +134,12 @@ def command_find_part (cache, matches, long=False, intersection=True,
aliases = sum([fuzzy_find([m], cache.aliases.keys()) for m in matches], []) aliases = sum([fuzzy_find([m], cache.aliases.keys()) for m in matches], [])
if print_parts: if print_parts:
for part in choices : for part in choices :
print part print(part)
if long : if long :
pp.pprint(cache.index[part]) pp.pprint(cache.index[part])
if print_aliases: if print_aliases:
for alias in aliases : for alias in aliases :
print alias print(alias)
if long : if long :
pp.pprint(cache.index[cache.aliases[alias]]) pp.pprint(cache.index[cache.aliases[alias]])

View File

@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
""" """
from __future__ import print_function from __future__ import print_function, division, absolute_import
import re import re
import tempfile import tempfile
@ -27,20 +27,22 @@ from os import linesep, remove, makedirs
from time import time from time import time
from intelhex import IntelHex from intelhex import IntelHex
from json import load, dump from json import load, dump
from tools.arm_pack_manager import Cache
from tools.utils import mkdir, run_cmd, run_cmd_ext, NotSupportedException,\
ToolException, InvalidReleaseTargetException, intelhex_offset
from tools.paths import MBED_CMSIS_PATH, MBED_TARGETS_PATH, MBED_LIBRARIES,\
MBED_HEADER, MBED_DRIVERS, MBED_PLATFORM, MBED_HAL, MBED_CONFIG_FILE,\
MBED_LIBRARIES_DRIVERS, MBED_LIBRARIES_PLATFORM, MBED_LIBRARIES_HAL,\
BUILD_DIR
from tools.targets import TARGET_NAMES, TARGET_MAP
from tools.libraries import Library
from tools.toolchains import TOOLCHAIN_CLASSES
from jinja2 import FileSystemLoader from jinja2 import FileSystemLoader
from jinja2.environment import Environment from jinja2.environment import Environment
from tools.config import Config
from .arm_pack_manager import Cache
from .utils import (mkdir, run_cmd, run_cmd_ext, NotSupportedException,
ToolException, InvalidReleaseTargetException,
intelhex_offset)
from .paths import (MBED_CMSIS_PATH, MBED_TARGETS_PATH, MBED_LIBRARIES,
MBED_HEADER, MBED_DRIVERS, MBED_PLATFORM, MBED_HAL,
MBED_CONFIG_FILE, MBED_LIBRARIES_DRIVERS,
MBED_LIBRARIES_PLATFORM, MBED_LIBRARIES_HAL,
BUILD_DIR)
from .targets import TARGET_NAMES, TARGET_MAP
from .libraries import Library
from .toolchains import TOOLCHAIN_CLASSES
from .config import Config
RELEASE_VERSIONS = ['2', '5'] RELEASE_VERSIONS = ['2', '5']

View File

@ -14,6 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
""" """
from __future__ import print_function, division, absolute_import
from copy import deepcopy from copy import deepcopy
from six import moves from six import moves
@ -28,11 +29,11 @@ from intelhex import IntelHex
from jinja2 import FileSystemLoader, StrictUndefined from jinja2 import FileSystemLoader, StrictUndefined
from jinja2.environment import Environment from jinja2.environment import Environment
from jsonschema import Draft4Validator, RefResolver from jsonschema import Draft4Validator, RefResolver
# Implementation of mbed configuration mechanism
from tools.utils import json_file_to_dict, intelhex_offset from ..utils import json_file_to_dict, intelhex_offset
from tools.arm_pack_manager import Cache from ..arm_pack_manager import Cache
from tools.targets import CUMULATIVE_ATTRIBUTES, TARGET_MAP, \ from ..targets import (CUMULATIVE_ATTRIBUTES, TARGET_MAP, generate_py_target,
generate_py_target, get_resolution_order, Target get_resolution_order, Target)
try: try:
unicode unicode

View File

@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from __future__ import print_function, division, absolute_import
import sys import sys
from os.path import join, abspath, dirname, exists from os.path import join, abspath, dirname, exists
from os.path import basename, relpath, normpath, splitext from os.path import basename, relpath, normpath, splitext
@ -22,50 +24,43 @@ from os import makedirs, walk
import copy import copy
from shutil import rmtree, copyfile from shutil import rmtree, copyfile
import zipfile import zipfile
ROOT = abspath(join(dirname(__file__), ".."))
sys.path.insert(0, ROOT)
from tools.build_api import prepare_toolchain from ..build_api import prepare_toolchain, scan_resources
from tools.build_api import scan_resources from ..toolchains import Resources
from tools.toolchains import Resources from ..targets import TARGET_NAMES
from tools.export import lpcxpresso, ds5_5, iar, makefile from . import (lpcxpresso, ds5_5, iar, makefile, embitz, coide, kds, simplicity,
from tools.export import embitz, coide, kds, simplicity, atmelstudio, mcuxpresso atmelstudio, mcuxpresso, sw4stm32, e2studio, zip, cmsis, uvision,
from tools.export import sw4stm32, e2studio, zip, cmsis, uvision, cdt, vscode cdt, vscode, gnuarmeclipse, qtcreator, cmake, nb)
from tools.export import gnuarmeclipse
from tools.export import qtcreator
from tools.export import cmake
from tools.export import nb
from tools.targets import TARGET_NAMES
EXPORTERS = { EXPORTERS = {
'uvision5': uvision.Uvision, u'uvision5': uvision.Uvision,
'uvision': uvision.Uvision, u'uvision': uvision.Uvision,
'lpcxpresso': lpcxpresso.LPCXpresso, u'lpcxpresso': lpcxpresso.LPCXpresso,
'gcc_arm': makefile.GccArm, u'gcc_arm': makefile.GccArm,
'make_gcc_arm': makefile.GccArm, u'make_gcc_arm': makefile.GccArm,
'make_armc5': makefile.Armc5, u'make_armc5': makefile.Armc5,
'make_armc6': makefile.Armc6, u'make_armc6': makefile.Armc6,
'make_iar': makefile.IAR, u'make_iar': makefile.IAR,
'ds5_5': ds5_5.DS5_5, u'ds5_5': ds5_5.DS5_5,
'iar': iar.IAR, u'iar': iar.IAR,
'embitz' : embitz.EmBitz, u'embitz' : embitz.EmBitz,
'coide' : coide.CoIDE, u'coide' : coide.CoIDE,
'kds' : kds.KDS, u'kds' : kds.KDS,
'simplicityv3' : simplicity.SimplicityV3, u'simplicityv3' : simplicity.SimplicityV3,
'atmelstudio' : atmelstudio.AtmelStudio, u'atmelstudio' : atmelstudio.AtmelStudio,
'sw4stm32' : sw4stm32.Sw4STM32, u'sw4stm32' : sw4stm32.Sw4STM32,
'e2studio' : e2studio.E2Studio, u'e2studio' : e2studio.E2Studio,
'eclipse_gcc_arm' : cdt.EclipseGcc, u'eclipse_gcc_arm' : cdt.EclipseGcc,
'eclipse_iar' : cdt.EclipseIAR, u'eclipse_iar' : cdt.EclipseIAR,
'eclipse_armc5' : cdt.EclipseArmc5, u'eclipse_armc5' : cdt.EclipseArmc5,
'gnuarmeclipse': gnuarmeclipse.GNUARMEclipse, u'gnuarmeclipse': gnuarmeclipse.GNUARMEclipse,
'netbeans': nb.GNUARMNetbeans, u'mcuxpresso': mcuxpresso.MCUXpresso,
'mcuxpresso': mcuxpresso.MCUXpresso, u'netbeans': nb.GNUARMNetbeans,
'qtcreator': qtcreator.QtCreator, u'qtcreator': qtcreator.QtCreator,
'vscode_gcc_arm' : vscode.VSCodeGcc, u'vscode_gcc_arm' : vscode.VSCodeGcc,
'vscode_iar' : vscode.VSCodeIAR, u'vscode_iar' : vscode.VSCodeIAR,
'vscode_armc5' : vscode.VSCodeArmc5, u'vscode_armc5' : vscode.VSCodeArmc5,
'cmake_gcc_arm': cmake.GccArm u'cmake_gcc_arm': cmake.GccArm
} }
ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN = """ ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN = """

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
"""Memory Map File Analyser for ARM mbed""" """Memory Map File Analyser for ARM mbed"""
from __future__ import print_function from __future__ import print_function, division, absolute_import
from abc import abstractmethod, ABCMeta from abc import abstractmethod, ABCMeta
from sys import stdout, exit, argv from sys import stdout, exit, argv
@ -16,8 +16,8 @@ from copy import deepcopy
from prettytable import PrettyTable from prettytable import PrettyTable
from tools.arm_pack_manager import Cache from tools.arm_pack_manager import Cache
from tools.utils import argparse_filestring_type, \ from .utils import (argparse_filestring_type, argparse_lowercase_hyphen_type,
argparse_lowercase_hyphen_type, argparse_uppercase_type argparse_uppercase_type)
class _Parser(object): class _Parser(object):

View File

@ -14,16 +14,19 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
""" """
from __future__ import print_function, division, absolute_import
from json import load from json import load
from os.path import join, dirname from os.path import join, dirname
from os import listdir from os import listdir
from argparse import ArgumentParser, ArgumentTypeError from argparse import ArgumentParser, ArgumentTypeError
from tools.toolchains import TOOLCHAINS
from tools.targets import TARGET_NAMES, Target, update_target_data from .toolchains import TOOLCHAINS
from tools.utils import argparse_force_uppercase_type, \ from .targets import TARGET_NAMES, Target, update_target_data
argparse_lowercase_hyphen_type, argparse_many, \ from .utils import (argparse_force_uppercase_type, argparse_deprecate,
argparse_filestring_type, args_error, argparse_profile_filestring_type,\ argparse_lowercase_hyphen_type, argparse_many,
argparse_deprecate argparse_filestring_type, args_error,
argparse_profile_filestring_type)
FLAGS_DEPRECATION_MESSAGE = "Please use the --profile argument instead.\n"\ FLAGS_DEPRECATION_MESSAGE = "Please use the --profile argument instead.\n"\
"Documentation may be found in "\ "Documentation may be found in "\

View File

@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
""" """
from __future__ import print_function from __future__ import print_function, division, absolute_import
import re import re
import sys import sys
@ -22,21 +22,23 @@ from os import stat, walk, getcwd, sep, remove
from copy import copy from copy import copy
from time import time, sleep from time import time, sleep
from shutil import copyfile from shutil import copyfile
from os.path import join, splitext, exists, relpath, dirname, basename, split, abspath, isfile, isdir, normcase from os.path import (join, splitext, exists, relpath, dirname, basename, split,
abspath, isfile, isdir, normcase)
from itertools import chain from itertools import chain
from inspect import getmro from inspect import getmro
from copy import deepcopy from copy import deepcopy
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
from distutils.spawn import find_executable from distutils.spawn import find_executable
from multiprocessing import Pool, cpu_count from multiprocessing import Pool, cpu_count
from tools.utils import run_cmd, mkdir, rel_path, ToolException, NotSupportedException, split_path, compile_worker
from tools.settings import MBED_ORG_USER
import tools.hooks as hooks
from tools.memap import MemapParser
from hashlib import md5 from hashlib import md5
import fnmatch import fnmatch
from ..utils import (run_cmd, mkdir, rel_path, ToolException,
NotSupportedException, split_path, compile_worker)
from ..settings import MBED_ORG_USER
from .. import hooks
from ..memap import MemapParser
#Disables multiprocessing if set to higher number than the host machine CPUs #Disables multiprocessing if set to higher number than the host machine CPUs
CPU_COUNT_MIN = 1 CPU_COUNT_MIN = 1

View File

@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
""" """
from __future__ import print_function from __future__ import print_function, division, absolute_import
import sys import sys
import inspect import inspect
import os import os
@ -417,11 +417,8 @@ def argparse_force_type(case):
if not isinstance(string, unicode): if not isinstance(string, unicode):
string = string.decode() string = string.decode()
for option in lst: for option in lst:
try:
if case(string) == case(option): if case(string) == case(option):
return option return option
except Exception as e:
print(e)
raise argparse.ArgumentTypeError( raise argparse.ArgumentTypeError(
"{0} is not a supported {1}. Supported {1}s are:\n{2}". "{0} is not a supported {1}. Supported {1}s are:\n{2}".
format(string, type_name, columnate(lst))) format(string, type_name, columnate(lst)))