Skip to content

Commit 649ee38

Browse files
committed
Pylint fixes
1 parent 014b56d commit 649ee38

File tree

1 file changed

+45
-41
lines changed

1 file changed

+45
-41
lines changed

mbed/mbed.py

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33
# Copyright (c) 2016 ARM Limited, All Rights Reserved
44
# SPDX-License-Identifier: Apache-2.0
55

6-
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
88

99
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
1010

11-
# Unless required by applicable law or agreed to in writing, software
12-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
1314
# either express or implied.
1415

1516

16-
# pylint: disable=too-many-arguments, too-many-locals, too-many-branches, too-many-lines, line-too-long, too-many-nested-blocks, too-many-public-methods, too-many-instance-attributes
17-
# pylint: disable=invalid-name, missing-docstring
17+
# pylint: disable=too-many-arguments, too-many-locals, too-many-branches, too-many-lines, line-too-long,
18+
# pylint: disable=too-many-nested-blocks, too-many-public-methods, too-many-instance-attributes, too-many-statements
19+
# pylint: disable=invalid-name, missing-docstring, bad-continuation
1820

19-
import argparse
21+
import traceback
2022
import sys
2123
import re
2224
import subprocess
@@ -29,6 +31,7 @@
2931
from urlparse import urlparse
3032
import urllib
3133
import zipfile
34+
import argparse
3235

3336

3437
# Application version
@@ -227,10 +230,10 @@ def staticclass(cls):
227230
# Handling for multiple version controls
228231
scms = {}
229232
def scm(name):
230-
def scm(cls):
233+
def _scm(cls):
231234
scms[name] = cls()
232235
return cls
233-
return scm
236+
return _scm
234237

235238
# pylint: disable=no-self-argument, no-method-argument, no-member, no-self-use, unused-argument
236239
@scm('bld')
@@ -245,19 +248,19 @@ def isurl(url):
245248
else:
246249
return False
247250

248-
def init(path, url):
251+
def init(path):
249252
if not os.path.exists(path):
250253
os.mkdir(path)
251-
with cd(path):
252-
Bld.seturl(url)
253254

254255
def clone(url, path=None, depth=None, protocol=None):
255256
m = Bld.isurl(url)
256257
if not m:
257258
raise ProcessException(1, "Not an mbed library build URL")
258259

259260
try:
260-
Bld.init(path, url+'/tip')
261+
Bld.init(path)
262+
with cd(path):
263+
Bld.seturl(url+'/tip')
261264
except Exception as e:
262265
error(e[1], e[0])
263266

@@ -924,11 +927,11 @@ def __wrap_scm(self, method):
924927
def __scm_call(*args, **kwargs):
925928
if self.scm and hasattr(self.scm, method) and callable(getattr(self.scm, method)):
926929
with cd(self.path):
927-
return getattr(self.scm, method)(*args, **kwargs)
930+
return getattr(self.scm, method)(*args, **kwargs)
928931
return __scm_call
929932

930-
def __getattr__(self, attr):
931-
if attr in ['geturl', 'getrev', 'add', 'remove', 'ignores', 'ignore', 'unignore',
933+
def __getattr__(self, attr):
934+
if attr in ['geturl', 'getrev', 'add', 'remove', 'ignores', 'ignore', 'unignore',
932935
'status', 'dirty', 'commit', 'outgoing', 'publish', 'checkout', 'update',
933936
'isdetached']:
934937
wrapper = self.__wrap_scm(attr)
@@ -984,8 +987,8 @@ def clone(self, url, path, depth=None, protocol=None, **kwargs):
984987
self.ignores()
985988
self.set_cache(url)
986989
return True
987-
else:
988-
return False
990+
991+
return False
989992

990993
def getlibs(self):
991994
for root, dirs, files in os.walk(self.path):
@@ -1114,10 +1117,10 @@ def __init__(self, path=None, print_warning=False):
11141117
warning(
11151118
"Could not find mbed program in current path \"%s\".\n"
11161119
"You can fix this by calling \"mbed new .\" or \"mbed default root .\" in the root of your program." % self.path)
1117-
1120+
11181121
def get_cfg(self, *args, **kwargs):
11191122
return Cfg(self.path).get(*args, **kwargs) or Global().get_cfg(*args, **kwargs)
1120-
1123+
11211124
def set_cfg(self, *args, **kwargs):
11221125
return Cfg(self.path).set(*args, **kwargs)
11231126

@@ -1212,7 +1215,7 @@ def add_tools(self, path):
12121215
action("Couldn't find build tools in your program. Downloading the mbed SDK tools...")
12131216
repo = Repo.fromurl(mbed_sdk_tools_url)
12141217
repo.clone(mbed_sdk_tools_url, tools_dir)
1215-
except:
1218+
except Exception:
12161219
if os.path.exists(tools_dir):
12171220
rmtree_readonly(tools_dir)
12181221
error("An error occurred while cloning the mbed SDK tools from \"%s\"" % mbed_sdk_tools_url)
@@ -1252,7 +1255,7 @@ def __init__(self):
12521255

12531256
def get_cfg(self, *args, **kwargs):
12541257
return Cfg(self.path).get(*args, **kwargs)
1255-
1258+
12561259
def set_cfg(self, *args, **kwargs):
12571260
return Cfg(self.path).set(*args, **kwargs)
12581261

@@ -1342,7 +1345,7 @@ def formaturl(url, format="default"):
13421345

13431346
# Process handling
13441347
def subcommand(name, *args, **kwargs):
1345-
def subcommand(command):
1348+
def __subcommand(command):
13461349
if not kwargs.get('description') and kwargs.get('help'):
13471350
kwargs['description'] = kwargs['help']
13481351
if not kwargs.get('formatter_class'):
@@ -1374,7 +1377,7 @@ def thunk(parsed_args):
13741377

13751378
subparser.set_defaults(command=thunk)
13761379
return command
1377-
return subcommand
1380+
return __subcommand
13781381

13791382

13801383
# New command
@@ -1888,7 +1891,7 @@ def compile(toolchain=None, mcu=None, source=False, build=False, compile_library
18881891
+ ['-t', tchain, '-m', target]
18891892
+ list(chain.from_iterable(izip(repeat('--source'), source)))
18901893
+ (['-v'] if verbose else [])
1891-
+ (list(chain.from_iterable(izip(repeat('--prefix'), prefix))) if prefix else []),
1894+
+ (list(chain.from_iterable(izip(repeat('--prefix'), config_prefix))) if config_prefix else []),
18921895
env=env)
18931896

18941897
if compile_library:
@@ -1942,7 +1945,7 @@ def test_(toolchain=None, mcu=None, list_compile=False, list_run=False, compile_
19421945
program = Program(os.getcwd(), True)
19431946
# Remember the original path. this is needed for compiling only the libraries and tests for the current folder.
19441947
orig_path = os.getcwd()
1945-
1948+
19461949
# Change directories to the program root to use mbed OS tools
19471950
with cd(program.path):
19481951
target = program.get_mcu(mcu)
@@ -1952,21 +1955,21 @@ def test_(toolchain=None, mcu=None, list_compile=False, list_run=False, compile_
19521955

19531956
env = os.environ.copy()
19541957
env['PYTHONPATH'] = os.path.abspath(program.path)
1955-
1958+
19561959
# Setup the source path if not specified
19571960
if not source or len(source) == 0:
19581961
source = [os.path.relpath(program.path, orig_path)]
1959-
1962+
19601963
# Setup the build path if not specified
19611964
if not build:
19621965
build = os.path.join(os.path.relpath(program.path, orig_path), '.build/tests', target, tchain)
1963-
1966+
19641967
# Create the path to the test spec file
19651968
test_spec = os.path.join(build, 'test_spec.json')
1966-
1969+
19671970
# Determine if building and running tests
19681971
build_and_run_tests = not list_compile and not list_run and not compile_only and not run_only
1969-
1972+
19701973
if compile_only or build_and_run_tests:
19711974
cmd = ['python', '-u', os.path.join(tools_dir, 'test.py')]
19721975
cmd += list(chain.from_iterable(izip(repeat('-D'), macros)))
@@ -1977,37 +1980,37 @@ def test_(toolchain=None, mcu=None, list_compile=False, list_run=False, compile_
19771980
cmd += ['--test-spec', test_spec]
19781981
cmd += (['-n', tests_by_name] if tests_by_name else [])
19791982
cmd += (['-v'] if verbose else [])
1980-
1983+
19811984
try:
19821985
popen(cmd + args, env=env)
19831986
except ProcessException:
19841987
error('Failed to run the test compiling script')
1985-
1988+
19861989
if run_only or build_and_run_tests:
19871990
cmd = ['mbedgt', '--test-spec', test_spec]
19881991
cmd += (['-n', tests_by_name] if tests_by_name else [])
19891992
cmd += (['-V'] if verbose else [])
1990-
1993+
19911994
try:
19921995
popen(cmd + args, env=env)
19931996
except ProcessException:
19941997
error('Failed to run test runner')
1995-
1998+
19961999
if list_compile:
19972000
cmd = ['python', '-u', os.path.join(tools_dir, 'test.py'), '--list']
19982001
cmd += (['-n', tests_by_name] if tests_by_name else [])
19992002
cmd += (['-v'] if verbose else [])
2000-
2003+
20012004
try:
20022005
popen(cmd + args, env=env)
20032006
except ProcessException:
20042007
error('Failed to run buildable tests listing script')
2005-
2008+
20062009
if list_run:
20072010
cmd = ['mbedgt', '--test-spec', test_spec, '--list']
20082011
cmd += (['-n', tests_by_name] if tests_by_name else [])
20092012
cmd += (['-V'] if verbose else [])
2010-
2013+
20112014
try:
20122015
popen(cmd + args, env=env)
20132016
except ProcessException:
@@ -2033,7 +2036,8 @@ def export(ide=None, mcu=None):
20332036
macros = program.get_macros()
20342037

20352038
env = os.environ.copy()
2036-
env['PYTHONPATH'] = '.'
2039+
env['PYTHONPATH'] = os.path.abspath(program.path)
2040+
20372041
popen(['python', '-u', os.path.join(tools_dir, 'project.py')]
20382042
+ list(chain.from_iterable(izip(repeat('-D'), macros)))
20392043
+ ['-i', ide, '-m', target, '--source=%s' % program.path]
@@ -2058,7 +2062,8 @@ def detect():
20582062

20592063
# Prepare environment variables
20602064
env = os.environ.copy()
2061-
env['PYTHONPATH'] = '.'
2065+
env['PYTHONPATH'] = os.path.abspath(program.path)
2066+
20622067
popen(['python', '-u', os.path.join(tools_dir, 'detect_targets.py')]
20632068
+ args,
20642069
env=env)
@@ -2153,8 +2158,7 @@ def toolchain_(name=None, global_cfg=False):
21532158
except KeyboardInterrupt as e:
21542159
error('User aborted!', 255)
21552160
except Exception as e:
2156-
if verbose:
2157-
import traceback
2161+
if very_verbose:
21582162
traceback.print_exc(file=sys.stdout)
21592163
error("Unknown Error: %s" % e, 255)
21602164
sys.exit(status or 0)

0 commit comments

Comments
 (0)