Fix pylint errors and warnings

Remove `except` block which immediately raises the same exception again (it's
not a subclass of another caught exception, so this is safe).

Remove a false positive, because it is not emitted from the code base.

Disable subprocess-popen-preexec-fn in startProgram, which is not used
internally.
This commit is contained in:
Lars Karlitski 2018-09-17 12:03:21 +02:00 committed by Alexander Todorov
parent 9736dff762
commit 160044ba9d
5 changed files with 9 additions and 12 deletions

View File

@ -23,9 +23,11 @@ log = logging.getLogger("composer")
import os import os
import sys import sys
from composer import vernum # Disable pylint warnings for these, because it cannot deal with this file and
from composer.cli import main # the module both being called "composer"
from composer.cli.cmdline import composer_cli_parser from composer import vernum # pylint: disable=import-self
from composer.cli import main # pylint: disable=no-name-in-module
from composer.cli.cmdline import composer_cli_parser # pylint: disable=no-name-in-module
VERSION = "{0}-{1}".format(os.path.basename(sys.argv[0]), vernum) VERSION = "{0}-{1}".format(os.path.basename(sys.argv[0]), vernum)

View File

@ -115,6 +115,7 @@ def startProgram(argv, root='/', stdin=None, stdout=subprocess.PIPE, stderr=subp
if env_add: if env_add:
env.update(env_add) env.update(env_add)
# pylint: disable=subprocess-popen-preexec-fn
return subprocess.Popen(argv, return subprocess.Popen(argv,
stdin=stdin, stdin=stdin,
stdout=stdout, stdout=stdout,

View File

@ -196,10 +196,7 @@ def loop_attach(outfile):
# Sometimes the loop device isn't ready yet, make extra sure before returning # Sometimes the loop device isn't ready yet, make extra sure before returning
loop_waitfor(dev, outfile) loop_waitfor(dev, outfile)
except CalledProcessError: except RuntimeError:
# Problems running losetup are always errors, raise immediately
raise
except RuntimeError as e:
# Try to setup the loop device 3 times # Try to setup the loop device 3 times
if retries == 3: if retries == 3:
logger.error("loop_attach failed, retries exhausted.") logger.error("loop_attach failed, retries exhausted.")

View File

@ -248,10 +248,10 @@ class LoraxTemplateRunner(object):
# skip the bit about "ltmpl.py, in _run()" - we know that # skip the bit about "ltmpl.py, in _run()" - we know that
exclines.pop(1) exclines.pop(1)
# log the "ErrorType: this is what happened" line # log the "ErrorType: this is what happened" line
logger.error(" " + exclines[-1].strip()) logger.error(" %s", exclines[-1].strip())
# and log the entire traceback to the debug log # and log the entire traceback to the debug log
for _line in ''.join(exclines).splitlines(): for _line in ''.join(exclines).splitlines():
logger.debug(" " + _line) logger.debug(" %s", _line)
if self.fatalerrors: if self.fatalerrors:
raise raise

View File

@ -9,9 +9,6 @@ class LoraxLintConfig(PocketLintConfig):
PocketLintConfig.__init__(self) PocketLintConfig.__init__(self)
self.falsePositives = [ FalsePositive(r"Module 'pylorax' has no 'version' member"), self.falsePositives = [ FalsePositive(r"Module 'pylorax' has no 'version' member"),
# threading.Lock() is a factory function which returns an
# instance of the Lock class that is supported by the platform
FalsePositive(r"Context manager 'lock' doesn't implement __enter__ and __exit__"),
FalsePositive(r"Catching too general exception Exception"), FalsePositive(r"Catching too general exception Exception"),
FalsePositive(r"^E0712.*: Catching an exception which doesn't inherit from (Base|)Exception: GError$"), FalsePositive(r"^E0712.*: Catching an exception which doesn't inherit from (Base|)Exception: GError$"),
FalsePositive(r"Module 'composer' has no 'version' member"), FalsePositive(r"Module 'composer' has no 'version' member"),