Skip to content

Commit

Permalink
inspektor: Use pylint help text to find appropriate flags
Browse files Browse the repository at this point in the history
Let's use a heuristic that tends to be more reliable instead
of looking for python versions or pylint version strings:
Check directly the --help output. Since in most py apps
the output is auto generated from real command line options,
this should be relatively safe.

This solves a problem with moving target options such as
--score and others.

Signed-off-by: Lucas Meneghel Rodrigues <lookkas@gmail.com>
  • Loading branch information
lmr committed Aug 9, 2017
1 parent 121f501 commit 9847190
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions inspektor/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from pylint.lint import Run

from .path import PathChecker
from .utils import process


class Linter(object):
Expand All @@ -45,10 +46,15 @@ def __init__(self, args, logger=logging.getLogger('')):
self.log.info('Pylint enabled : %s' % self.enabled_errors)
else:
self.log.info('Verbose mode, no disable/enable, full reports')
help_result = process.run('pylint --help')
self.help_text = help_result.stdout

def set_verbose(self):
self.verbose = True

def _pylint_has_option(self, option):
return option in self.help_text

def get_opts(self):
"""
If VERBOSE is set, show pylint reports. If not, only an issue summary.
Expand All @@ -63,8 +69,9 @@ def get_opts(self):
pylint_args.append('--disable=%s' % self.ignored_errors)
if self.enabled_errors:
pylint_args.append('--enable=%s' % self.enabled_errors)
pylint_args.append('--reports=no')
if sys.version_info[:2] > (2, 6):
if self._pylint_has_option('--reports'):
pylint_args.append('--reports=no')
if self._pylint_has_option('--score'):
pylint_args.append('--score=no')

return pylint_args
Expand Down
4 changes: 2 additions & 2 deletions inspektor/utils/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def run(cmd, verbose=True, ignore_status=False, shell=False):
duration = time.time() - start
result = CmdResult(cmd)
result.exit_status = p.returncode
result.stdout = stdout
result.stderr = stderr
result.stdout = str(stdout)
result.stderr = str(stderr)
result.duration = duration
if p.returncode != 0 and not ignore_status:
raise exceptions.CmdError(cmd, result)
Expand Down

0 comments on commit 9847190

Please sign in to comment.