Created
June 6, 2013 12:44
-
-
Save klen/5721225 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pylint(path, **meta): | |
""" Pylint code checking. | |
:return list: List of errors. | |
""" | |
from sys import version_info | |
if version_info > (3, 0): | |
import logging | |
logging.warn("Pylint don't supported python3 and will be disabled.") | |
return [] | |
# Clean ASTNG MANAGER cache # 1 | |
# ------------------------------ | |
from .pylint.logilab.astng.builder import MANAGER | |
MANAGER.astng_cache.clear() | |
# Clean ASTNG MANAGER cache # 2 | |
# ------------------------------ | |
from .pylint.logilab.astng.builder import MANAGER | |
MANAGER.astng_cache = {} | |
MANAGER._mod_file_cache = {} | |
MANAGER.transformers = [] | |
MANAGER.brain = {} | |
# Clean ASTNG MANAGER cache # 3 | |
# ------------------------------ | |
from .pylint.logilab.astng import builder, manager | |
manager.ASTNGManager.brain = {} | |
builder.MANAGER = manager.ASTNGManager() | |
from .pylint.lint import Run | |
from .pylint.reporters import BaseReporter | |
class Reporter(BaseReporter): | |
def __init__(self): | |
self.errors = [] | |
BaseReporter.__init__(self) | |
def _display(self, layout): | |
pass | |
def add_message(self, msg_id, location, msg): | |
_, _, line, col = location[1:] | |
self.errors.append(dict( | |
lnum=line, | |
col=col, | |
text="%s %s" % (msg_id, msg), | |
type=msg_id[0] | |
)) | |
pylintrc = op.join(environ.get('HOME', ''), '.pylintrc') | |
defattrs = '-r n' | |
if not op.exists(pylintrc): | |
defattrs += ' --rcfile={0}'.format(PYLINT_RC) | |
attrs = meta.get('pylint', defattrs.split()) | |
runner = Run( | |
[path] + attrs, reporter=Reporter(), exit=False) | |
return runner.linter.reporter.errors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment