Skip to content

Commit 7f41a57

Browse files
committed
Pylint improvements (score 9/10)
1 parent 99e9fb2 commit 7f41a57

File tree

1 file changed

+22
-28
lines changed

1 file changed

+22
-28
lines changed

mbed/mbed.py

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# pylint: disable=too-many-arguments, too-many-locals, too-many-branches, too-many-lines, line-too-long
2+
# pylint: disable=too-many-arguments, too-many-locals, too-many-branches, too-many-lines, line-too-long, too-many-nested-blocks
33
# pylint: disable=invalid-name, missing-docstring
44

55
import argparse
@@ -142,7 +142,7 @@ def popen(command, stdin=None, **kwargs):
142142
"Please verify that it's installed and accessible from your current path by executing \"%s\".\n" % (command[0], command[0]), e[0])
143143
else:
144144
raise
145-
145+
146146
if proc.wait() != 0:
147147
raise ProcessException(proc.returncode)
148148

@@ -202,9 +202,7 @@ def scm(cls):
202202
return cls
203203
return scm
204204

205-
# pylint: disable=no-self-argument
206-
# pylint: disable=no-method-argument
207-
# pylint: disable=no-member
205+
# pylint: disable=no-self-argument, no-method-argument, no-member, no-self-use
208206
@scm('hg')
209207
@staticclass
210208
class Hg(object):
@@ -386,9 +384,7 @@ def unignore(repo, file):
386384
except IOError:
387385
error("Unable to write ignore file in \"%s\"" % exclude, 1)
388386

389-
# pylint: disable=no-self-argument
390-
# pylint: disable=no-method-argument
391-
# pylint: disable=no-member
387+
# pylint: disable=no-self-argument, no-method-argument, no-member, no-self-use
392388
@scm('git')
393389
@staticclass
394390
class Git(object):
@@ -528,6 +524,12 @@ def unignore(repo, file):
528524
# Repository object
529525
class Repo(object):
530526
is_local = False
527+
name = None
528+
path = None
529+
url = None
530+
hash = None
531+
scm = None
532+
libs = []
531533

532534
@classmethod
533535
def fromurl(cls, url, path=None):
@@ -583,11 +585,9 @@ def fromrepo(cls, path=None):
583585

584586
@classmethod
585587
def isrepo(cls, path=None):
586-
for name, scm in scms.items():
588+
for name, _ in scms.items():
587589
if os.path.isdir(os.path.join(path, '.'+name)):
588590
return True
589-
else:
590-
return False
591591

592592
return False
593593

@@ -764,34 +764,31 @@ def check_repo(self, show_warning=None):
764764
# Program object, used to indicate the root of the code base
765765
class Program(object):
766766
config_file = ".mbed"
767+
path = None
768+
name = None
769+
is_cwd = False
770+
is_repo = False
767771

768772
@classmethod
769773
def get_program(cls, path=None, warnings=False):
770774
path = os.path.abspath(path or os.getcwd())
771-
rpath = None
772775

773776
program = cls()
774777
program.path = os.getcwd()
775778
program.is_cwd = True
776779

777780
while cd(path):
778781
tpath = path
779-
if os.path.isfile(os.path.join(path, program.config_file)):
782+
if Repo.isrepo(path):
780783
program.path = path
781784
program.is_cwd = False
782-
program.is_repo = Repo.isrepo(program.path)
785+
program.is_repo = True
786+
path = os.path.split(path)[0]
787+
if tpath == path: # Reached root.
783788
break
784-
else:
785-
if Repo.isrepo(path):
786-
program.path = path
787-
program.is_cwd = False
788-
program.is_repo = True
789-
path = os.path.split(path)[0]
790-
if tpath == path: # Reached root.
791-
break
792789

793790
program.name = os.path.basename(program.path)
794-
791+
795792
if warnings:
796793
if program.is_cwd:
797794
warning(
@@ -1024,7 +1021,6 @@ def import_(url, path=None, depth=None, protocol=None, top=True):
10241021
except ProcessException:
10251022
if os.path.isdir(repo.path):
10261023
rmtree_readonly(repo.path)
1027-
pass
10281024
else:
10291025
error("Unable to clone repository (%s)" % url, 1)
10301026

@@ -1047,7 +1043,6 @@ def import_(url, path=None, depth=None, protocol=None, top=True):
10471043
dict(name='--protocol', nargs='?', help='Transport protocol for the source control management. Supported: https, http, ssh, git. Default: inferred from URL.'),
10481044
help="Import missing dependencies in the current program or library.")
10491045
def deploy(depth=None, protocol=None):
1050-
sys.exit(1)
10511046
repo = Repo.fromrepo()
10521047
repo.scm.ignores(repo)
10531048

@@ -1262,7 +1257,7 @@ def sync(recursive=True, keep_refs=False, top=True):
12621257
sync(keep_refs=keep_refs, top=False)
12631258

12641259

1265-
# List command
1260+
# List command
12661261
@subcommand('ls',
12671262
dict(name=['-a', '--all'], action='store_true', help="List repository URL and hash pairs"),
12681263
dict(name=['-I', '--ignore'], action="store_true", help="Ignore errors regarding missing libraries."),
@@ -1346,7 +1341,6 @@ def compile(toolchain=None, mcu=None, source=False, build=False, compile_library
13461341

13471342
if not source or len(source) == 0:
13481343
source = [os.path.relpath(root_path, orig_path)]
1349-
13501344
if compile_tests:
13511345
# Compile tests
13521346
if not build:
@@ -1410,7 +1404,7 @@ def test(list=False):
14101404
# List all available tests (by default in a human-readable format)
14111405
try:
14121406
popen(['python', 'mbed-os/tools/test.py', '-l'] + args, env=env)
1413-
except ProcessException as e:
1407+
except ProcessException:
14141408
error('Failed to run test script')
14151409

14161410

0 commit comments

Comments
 (0)