-
Notifications
You must be signed in to change notification settings - Fork 17
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
Fix license check #28
Changes from all commits
10037ac
9d66cc5
121f501
48e617a
a720ce7
4090f51
ae9d774
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,9 @@ | |
from pylint.lint import Run | ||
|
||
from .path import PathChecker | ||
from .utils import process | ||
|
||
_PYLINT_HELP_TEXT = process.run('pylint --help', verbose=False).stdout | ||
|
||
|
||
class Linter(object): | ||
|
@@ -49,6 +52,10 @@ def __init__(self, args, logger=logging.getLogger('')): | |
def set_verbose(self): | ||
self.verbose = True | ||
|
||
@staticmethod | ||
def _pylint_has_option(option): | ||
return option in _PYLINT_HELP_TEXT | ||
|
||
def get_opts(self): | ||
""" | ||
If VERBOSE is set, show pylint reports. If not, only an issue summary. | ||
|
@@ -63,8 +70,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='): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, hopefully they won't change that format 😄 |
||
pylint_args.append('--score=no') | ||
|
||
return pylint_args | ||
|
@@ -89,19 +97,23 @@ def check_file(self, path): | |
:return: False, if pylint found syntax problems, True, if pylint didn't | ||
find problems, or path is not a python module or script. | ||
""" | ||
checker = PathChecker(path=path, args=self.args, label='Lint') | ||
checker = PathChecker(path=path, args=self.args, label='Lint', | ||
logger=self.log) | ||
if not checker.check_attributes('text', 'python', 'not_empty'): | ||
return True | ||
try: | ||
runner = Run(self.get_opts() + [path], exit=False) | ||
if runner.linter.msg_status != 0: | ||
self.log.error('Pylint check fail: %s', path) | ||
self.failed_paths.append(path) | ||
checker.log_status(status='FAIL') | ||
else: | ||
checker.log_status(status='PASS') | ||
return runner.linter.msg_status == 0 | ||
except Exception as details: | ||
self.log.error('Pylint check fail: %s (pylint exception: %s)', | ||
path, details) | ||
self.failed_paths.append(path) | ||
checker.log_status(status='FAIL') | ||
return False | ||
|
||
def check(self, path): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,7 +64,8 @@ def check_file(self, path): | |
:return: False, if pylint found syntax problems, True, if pylint didn't | ||
find problems, or path is not a python module or script. | ||
""" | ||
checker = PathChecker(path=path, args=self.args, label='Style') | ||
checker = PathChecker(path=path, args=self.args, label='Style', | ||
logger=self.log) | ||
if not checker.check_attributes('text', 'python', 'not_empty'): | ||
return True | ||
|
||
|
@@ -82,20 +83,26 @@ def check_file(self, path): | |
status = 1 | ||
|
||
if status != 0: | ||
self.log.error('Style check fail: %s', path) | ||
self.failed_paths.append(path) | ||
fix_status = '' | ||
if AUTOPEP8_CAPABLE: | ||
if self.args.fix: | ||
self.log.info('Trying to fix errors with autopep8') | ||
try: | ||
process.run('autopep8 --in-place --max-line-length=%s --ignore %s %s' % (self.args.max_line_length, self.args.disable, path)) | ||
process.run('autopep8 --in-place --max-line-length=%s --ignore %s %s' % (self.args.max_line_length, self.ignored_errors, path)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a fix not related to this commit... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I'm a lazy bastard :) Sorry for that one. |
||
fix_status = 'FIX OK' | ||
except Exception: | ||
self.log.error('Unable to fix errors') | ||
exc_info = sys.exc_info() | ||
stacktrace.log_exc_info(exc_info, 'inspektor.style') | ||
fix_status = 'FIX NOT OK' | ||
else: | ||
self.log.error('Python library autopep8 not installed. ' | ||
'Please install it if you want to use --fix') | ||
fix_status = 'FIX NOT OK' | ||
checker.log_status(status='FAIL', extra=fix_status) | ||
else: | ||
checker.log_status(status='PASS') | ||
|
||
return status == 0 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this required? Isn't the return of communicate already string? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In py3 it's bytes :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK |
||
result.duration = duration | ||
if p.returncode != 0 and not ignore_status: | ||
raise exceptions.CmdError(cmd, result) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, at this point they are useless...