Skip to content

Code improvements and linting #640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,6 @@ target/
# Doxygen
html/
latex/

# PyCharm
.idea
20 changes: 10 additions & 10 deletions mbed/mbed.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class ProcessException(Exception):
def popen(command, stdin=None, **kwargs):
# print for debugging
info('Exec "'+' '.join(command)+'" in '+getcwd())
proc = None
try:
proc = subprocess.Popen(command, **kwargs)
except OSError as e:
Expand All @@ -206,7 +207,7 @@ def popen(command, stdin=None, **kwargs):
else:
raise e

if proc.wait() != 0:
if proc and proc.wait() != 0:
raise ProcessException(proc.returncode, command[0], ' '.join(command), getcwd())

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

if proc.returncode is None:
code = proc.poll()
proc.poll()
else:
break

Expand Down Expand Up @@ -1282,8 +1283,8 @@ def get_cache(self, url):
def set_cache(self, url):
up = urlparse(formaturl(url, 'https'))
if self.cache and up and up.netloc and os.path.isdir(self.path):
cpath = os.path.join(self.cache, up.netloc, re.sub(r'^/', '', up.path))
try:
cpath = os.path.join(self.cache, up.netloc, re.sub(r'^/', '', up.path))
if not os.path.isdir(cpath):
os.makedirs(cpath)

Expand Down Expand Up @@ -1827,6 +1828,7 @@ def new(name, scm='git', program=False, library=False, mbedlib=False, create_onl

d_path = os.path.abspath(name or getcwd())
p_path = os.path.dirname(d_path)
d_type = None
if program and library:
error("Cannot use both --program and --library options.", 1)
elif program or library:
Expand Down Expand Up @@ -2059,7 +2061,7 @@ def publish(all_refs=None, msg=None, top=True):
if repo.is_local:
error(
"%s \"%s\" in \"%s\" is a local repository.\nPlease associate it with a remote repository URL before attempting to publish.\n"
"Read more about publishing local repositories here:\nhttps://github.com/ARMmbed/mbed-cli/#publishing-local-program-or-library" % ("Program" if top else "Library", repo.name, repo.path, repo.scm.name), 1)
"Read more about publishing local repositories here:\nhttps://github.com/ARMmbed/mbed-cli/#publishing-local-program-or-library" % ("Program" if top else "Library", repo.name, repo.path), 1)

for lib in repo.libs:
if lib.check_repo():
Expand Down Expand Up @@ -2157,7 +2159,6 @@ def update(rev=None, clean=False, clean_files=False, clean_deps=False, ignore=Fa
# Compare library references (.lib) before and after update, and remove libraries that do not have references in the current revision
for lib in repo_orig.libs:
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
gc = False
with cd(lib.path):
lib_repo = Repo.fromrepo(lib.path)
gc, msg = lib_repo.can_update(clean, clean_deps)
Expand All @@ -2180,7 +2181,6 @@ def update(rev=None, clean=False, clean_files=False, clean_deps=False, ignore=Fa
lib_repo = Repo.fromrepo(lib.path)
if (not lib.is_local and not lib_repo.is_local and
formaturl(lib.url, 'https') != formaturl(lib_repo.url, 'https')): # Repository URL has changed
gc = False
with cd(lib.path):
gc, msg = lib_repo.can_update(clean, clean_deps)
if gc:
Expand Down Expand Up @@ -2370,7 +2370,7 @@ def status_(ignore=False):
dict(name=['-S', '--supported'], dest='supported', const=True, choices=["matrix", "toolchains", "targets"], nargs="?", help='Shows supported matrix of targets and toolchains'),
dict(name='--app-config', dest="app_config", help="Path of an app configuration file (Default is to look for 'mbed_app.json')"),
help='Compile code using the mbed build tools',
description=("Compile this program using the mbed build tools."))
description="Compile this program using the mbed build tools.")
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):
# Gather remaining arguments
args = remainder
Expand Down Expand Up @@ -2490,7 +2490,7 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
dict(name='--app-config', dest="app_config", help="Path of an app configuration file (Default is to look for 'mbed_app.json')"),
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"),
help='Find, build and run tests',
description=("Find, build, and run tests in a program and libraries"))
description="Find, build, and run tests in a program and libraries")
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):
# Gather remaining arguments
args = remainder
Expand Down Expand Up @@ -2730,7 +2730,7 @@ def config_(var=None, value=None, global_cfg=False, unset=False, list_config=Fal
action('%s now set as global %s' % (value, name))
else:
value = g.get_cfg(var)
action(('%s' % value) if value else 'No global %s set' % (name))
action(('%s' % value) if value else 'No global %s set' % name)
else:
# Find the root of the program
program = Program(getcwd())
Expand Down Expand Up @@ -2897,7 +2897,7 @@ def main():
"You could retry the last command with \"-v\" flag for verbose output\n", e[0])
else:
error('OS Error: %s' % e[1], e[0])
except KeyboardInterrupt as e:
except KeyboardInterrupt:
info('User aborted!', -1)
sys.exit(255)
except Exception as e:
Expand Down
2 changes: 0 additions & 2 deletions test/sync_update_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def test_sync_update_remove(mbed, testrepos):
# Tests if adding a library is carried over sync/update
def test_sync_update_add(mbed, testrepos):
test1 = testrepos[0]
test3 = testrepos[2]
popen(['python', mbed, 'import', test1, 'testimport'])

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

with cd('test1/test2'):
Expand Down
1 change: 1 addition & 0 deletions test/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def testrepos(mbed, request):

with cd('test1/test2/test3'):
with open('test4.lib', 'w') as f:
hash = 'none'
with cd('test4'):
if scm() == 'git':
hash = pquery(['git', 'rev-parse', 'HEAD'])
Expand Down
10 changes: 1 addition & 9 deletions tools/bash_completion/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,26 @@ def getHelpTxt(command=None):
return out

def getTargetCode():
txt = ''
with open("templates/target.tmplt") as fp:
txt = fp.read()
return txt

def getToolchainCode():
txt = ''
with open("templates/toolchain.tmplt") as fp:
txt = fp.read()
return txt

def getSCMCode():
txt = ''
with open("templates/scm.tmplt") as fp:
txt = fp.read()
return txt

def getIDECode():
txt = ''
with open("templates/ide.tmplt") as fp:
txt = fp.read()
return txt

def getProtocolCode():
txt = ''
with open("templates/protocol.tmplt") as fp:
txt = fp.read()
return txt
Expand Down Expand Up @@ -159,8 +154,6 @@ def parseCommands():


def generateMain(commands):
tmplt = ""

txt = []

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


def generateCompleters(commands):
tmplt = ""
txt = []

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


def generateBoilerPlate(commands):
def generateBoilerPlate(_):
txt = []

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