Skip to content

Commit 72d4083

Browse files
author
Olli-Pekka Puolitaival
committed
Small fixes in behaviour and style
1 parent 9e84d02 commit 72d4083

File tree

6 files changed

+13
-21
lines changed

6 files changed

+13
-21
lines changed

mbed/mbed.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ class ProcessException(Exception):
196196
def popen(command, stdin=None, **kwargs):
197197
# print for debugging
198198
info('Exec "'+' '.join(command)+'" in '+getcwd())
199+
proc = None
199200
try:
200201
proc = subprocess.Popen(command, **kwargs)
201202
except OSError as e:
@@ -206,7 +207,7 @@ def popen(command, stdin=None, **kwargs):
206207
else:
207208
raise e
208209

209-
if proc.wait() != 0:
210+
if proc and proc.wait() != 0:
210211
raise ProcessException(proc.returncode, command[0], ' '.join(command), getcwd())
211212

212213
def pquery(command, output_callback=None, stdin=None, **kwargs):
@@ -232,7 +233,7 @@ def pquery(command, output_callback=None, stdin=None, **kwargs):
232233
line = ""
233234

234235
if proc.returncode is None:
235-
code = proc.poll()
236+
proc.poll()
236237
else:
237238
break
238239

@@ -1278,6 +1279,7 @@ def get_cache(self, url):
12781279
def set_cache(self, url):
12791280
up = urlparse(formaturl(url, 'https'))
12801281
if self.cache and up and up.netloc and os.path.isdir(self.path):
1282+
cpath = 'none'
12811283
try:
12821284
cpath = os.path.join(self.cache, up.netloc, re.sub(r'^/', '', up.path))
12831285
if not os.path.isdir(cpath):
@@ -1809,6 +1811,7 @@ def new(name, scm='git', program=False, library=False, mbedlib=False, create_onl
18091811

18101812
d_path = os.path.abspath(name or getcwd())
18111813
p_path = os.path.dirname(d_path)
1814+
d_type = None
18121815
if program and library:
18131816
error("Cannot use both --program and --library options.", 1)
18141817
elif program or library:
@@ -2139,7 +2142,6 @@ def update(rev=None, clean=False, clean_files=False, clean_deps=False, ignore=Fa
21392142
# Compare library references (.lib) before and after update, and remove libraries that do not have references in the current revision
21402143
for lib in repo_orig.libs:
21412144
if not os.path.isfile(lib.lib) and os.path.isdir(lib.path): # Library reference doesn't exist in the new revision. Will try to remove library to reproduce original structure
2142-
gc = False
21432145
with cd(lib.path):
21442146
lib_repo = Repo.fromrepo(lib.path)
21452147
gc, msg = lib_repo.can_update(clean, clean_deps)
@@ -2162,7 +2164,6 @@ def update(rev=None, clean=False, clean_files=False, clean_deps=False, ignore=Fa
21622164
lib_repo = Repo.fromrepo(lib.path)
21632165
if (not lib.is_local and not lib_repo.is_local and
21642166
formaturl(lib.url, 'https') != formaturl(lib_repo.url, 'https')): # Repository URL has changed
2165-
gc = False
21662167
with cd(lib.path):
21672168
gc, msg = lib_repo.can_update(clean, clean_deps)
21682169
if gc:
@@ -2352,7 +2353,7 @@ def status_(ignore=False):
23522353
dict(name=['-S', '--supported'], dest='supported', const=True, choices=["matrix", "toolchains", "targets"], nargs="?", help='Shows supported matrix of targets and toolchains'),
23532354
dict(name='--app-config', dest="app_config", help="Path of an app configuration file (Default is to look for 'mbed_app.json')"),
23542355
help='Compile code using the mbed build tools',
2355-
description=("Compile this program using the mbed build tools."))
2356+
description="Compile this program using the mbed build tools.")
23562357
def compile_(toolchain=None, target=None, profile=False, compile_library=False, compile_config=False, config_prefix=None, source=False, build=False, clean=False, flash=False, artifact_name=None, supported=False, app_config=None):
23572358
# Gather remaining arguments
23582359
args = remainder
@@ -2472,7 +2473,7 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
24722473
dict(name='--app-config', dest="app_config", help="Path of an app configuration file (Default is to look for 'mbed_app.json')"),
24732474
dict(name='--test-config', dest="test_config", help="Path or mbed OS keyword of a test configuration file. Example: ethernet, odin_wifi, or path/to/config.json"),
24742475
help='Find, build and run tests',
2475-
description=("Find, build, and run tests in a program and libraries"))
2476+
description="Find, build, and run tests in a program and libraries")
24762477
def test_(toolchain=None, target=None, compile_list=False, run_list=False, compile_only=False, run_only=False, tests_by_name=None, source=False, profile=False, build=False, clean=False, test_spec=None, app_config=None, test_config=None):
24772478
# Gather remaining arguments
24782479
args = remainder
@@ -2712,7 +2713,7 @@ def config_(var=None, value=None, global_cfg=False, unset=False, list_config=Fal
27122713
action('%s now set as global %s' % (value, name))
27132714
else:
27142715
value = g.get_cfg(var)
2715-
action(('%s' % value) if value else 'No global %s set' % (name))
2716+
action(('%s' % value) if value else 'No global %s set' % name)
27162717
else:
27172718
# Find the root of the program
27182719
program = Program(getcwd())
@@ -2806,7 +2807,7 @@ def main():
28062807
"You could retry the last command with \"-v\" flag for verbose output\n", e[0])
28072808
else:
28082809
error('OS Error: %s' % e[1], e[0])
2809-
except KeyboardInterrupt as e:
2810+
except KeyboardInterrupt:
28102811
info('User aborted!', -1)
28112812
sys.exit(255)
28122813
except Exception as e:

test/ls_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from util import *
1414

1515
# Tests 'mbed ls' and provides sanity check of test framework
16-
def test_ls(mbed, testrepos):
16+
def test_ls(mbed, _):
1717
assertls(mbed, 'test1', [
1818
"test1",
1919
"`- test2",

test/remove_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from util import *
1414

1515
# Tests the result of 'mbed remove'
16-
def test_remove(mbed, testrepos):
16+
def test_remove(mbed, _):
1717
with cd('test1'):
1818
popen(['python', mbed, 'remove', 'test2'])
1919

test/sync_update_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ def test_sync_update_remove(mbed, testrepos):
5858
# Tests if adding a library is carried over sync/update
5959
def test_sync_update_add(mbed, testrepos):
6060
test1 = testrepos[0]
61-
test3 = testrepos[2]
6261
popen(['python', mbed, 'import', test1, 'testimport'])
6362

6463
with cd('test1/test2'):
@@ -85,7 +84,6 @@ def test_sync_update_add(mbed, testrepos):
8584
# Tests if moving a library is carried over sync/update
8685
def test_sync_update_move(mbed, testrepos):
8786
test1 = testrepos[0]
88-
test3 = testrepos[2]
8987
popen(['python', mbed, 'import', test1, 'testimport'])
9088

9189
with cd('test1/test2'):

test/util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ def testrepos(mbed, request):
162162

163163
with cd('test1/test2/test3'):
164164
with open('test4.lib', 'w') as f:
165+
hash = 'none'
165166
with cd('test4'):
166167
if scm() == 'git':
167168
hash = pquery(['git', 'rev-parse', 'HEAD'])

tools/bash_completion/generator.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,26 @@ def getHelpTxt(command=None):
2525
return out
2626

2727
def getTargetCode():
28-
txt = ''
2928
with open("templates/target.tmplt") as fp:
3029
txt = fp.read()
3130
return txt
3231

3332
def getToolchainCode():
34-
txt = ''
3533
with open("templates/toolchain.tmplt") as fp:
3634
txt = fp.read()
3735
return txt
3836

3937
def getSCMCode():
40-
txt = ''
4138
with open("templates/scm.tmplt") as fp:
4239
txt = fp.read()
4340
return txt
4441

4542
def getIDECode():
46-
txt = ''
4743
with open("templates/ide.tmplt") as fp:
4844
txt = fp.read()
4945
return txt
5046

5147
def getProtocolCode():
52-
txt = ''
5348
with open("templates/protocol.tmplt") as fp:
5449
txt = fp.read()
5550
return txt
@@ -159,8 +154,6 @@ def parseCommands():
159154

160155

161156
def generateMain(commands):
162-
tmplt = ""
163-
164157
txt = []
165158

166159
with open("templates/mbed.tmplt") as fp:
@@ -172,7 +165,6 @@ def generateMain(commands):
172165

173166

174167
def generateCompleters(commands):
175-
tmplt = ""
176168
txt = []
177169

178170
renderer = pystache.Renderer(escape=lambda u: u)
@@ -188,7 +180,7 @@ def generateCompleters(commands):
188180
return txt
189181

190182

191-
def generateBoilerPlate(commands):
183+
def generateBoilerPlate(_):
192184
txt = []
193185

194186
with open("templates/boilerplate.tmplt") as fp:

0 commit comments

Comments
 (0)