本文整理汇总了Python中pylint.lint.PyLinter.read_config_file方法的典型用法代码示例。如果您正苦于以下问题:Python PyLinter.read_config_file方法的具体用法?Python PyLinter.read_config_file怎么用?Python PyLinter.read_config_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pylint.lint.PyLinter
的用法示例。
在下文中一共展示了PyLinter.read_config_file方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_file
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import read_config_file [as 别名]
def process_file(filename):
"""
Analyze the file with pylint and write the result
to a database
"""
linter = PyLinter()
checkers.initialize(linter)
linter.read_config_file()
linter.quiet = 1
filemods = linter.expand_files((filename, ))
if filemods:
old_stats = config.load_results(filemods[0].get('basename'))
old_score = old_stats.get('global_note', 0.0)
linter.check(filename)
score = eval(linter.config.evaluation, {}, linter.stats)
# Calculate the credit for both scores
if score < 0:
credit = 2.0 * score
elif score < old_score:
credit = -1.5 * (old_score - score)
elif score < MINIMUM_SCORE:
credit = -1.5 * (MINIMUM_SCORE - score)
else:
credit = score - old_score
return score, old_score, credit
示例2: run_linter
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import read_config_file [as 别名]
def run_linter(self):
from pylint.lint import PyLinter
from pylint import checkers
from os.path import join
linter = PyLinter(pylintrc=self.lint_config)
# same, but not all pylint versions have load_default_plugins
if hasattr(linter, 'load_default_plugins'):
linter.load_default_plugins()
else:
checkers.initialize(linter)
linter.read_config_file()
linter.load_config_file()
if self.packages:
self.announce("checking packages", 2)
report_fn = "packages_report." + linter.reporter.extension
report_fn = join(self.build_base, report_fn)
with open(report_fn, "wt") as out:
linter.reporter.set_output(out)
linter.check(self.packages)
self.announce_overview(linter, report_fn)
if self.build_scripts:
self.announce("checking scripts", 2)
report_fn = "scripts_report." + linter.reporter.extension
report_fn = join(self.build_base, report_fn)
with open(report_fn, "wt") as out:
linter.reporter.set_output(out)
linter.check(self.build_scripts)
self.announce_overview(linter, report_fn)
示例3: check_pylint
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import read_config_file [as 别名]
def check_pylint(self):
"""
Check using pylint.
"""
options = self.options.get('pylint', self.file_path).copy()
if not options['enabled']:
return
del options['enabled']
if not self._compiled_tree:
# We failed to compile the tree.
return
from pylint.lint import PyLinter, fix_import_path
from pylint.reporters import CollectingReporter
linter = PyLinter()
linter.load_default_plugins()
linter.set_reporter(CollectingReporter())
if options['py3k']:
linter.python3_porting_mode()
del options['py3k']
rcfile = options.get('rcfile', None)
del options['rcfile']
if rcfile:
linter.read_config_file(config_file=rcfile)
linter.load_config_file()
else:
linter.load_configuration_from_config(options)
# PyLint does its own import and parsing, so we only pass the file
# name and the precompiled tree.
with fix_import_path(self.file_path):
linter.check(self.file_path)
for message in linter.reporter.messages:
self.message(
message.line,
'%s:%s %s' % (
message.msg_id,
message.symbol,
message.msg,
),
code=message.msg_id,
icon='info',
category='pylint',
)
示例4: run_linter
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import read_config_file [as 别名]
def run_linter(self):
linter = PyLinter(pylintrc=self.lint_config)
# load_default_plugins will call checkers.initialize if
# implemented, but some older versions of pylint don't have
# this method so we fall back to calling is manually.
if hasattr(linter, 'load_default_plugins'):
linter.load_default_plugins()
else:
checkers.initialize(linter)
linter.read_config_file()
linter.load_config_file()
# don't emit messages about suppressed or useless suppressed
# configs, it's just annoying and doesn't help.
#linter.disable('suppressed-message')
#linter.disable('useless-suppression')
if self.packages:
self.announce("pylint is checking packages", 2)
report_fn = "packages_report." + linter.reporter.extension
report_fn = join(self.build_base, report_fn)
with open(report_fn, "wt") as out:
linter.reporter.set_output(out)
linter.check(self.packages)
self.announce_overview(linter, report_fn)
if self.build_scripts:
self.announce("pylint is checking scripts", 2)
report_fn = "scripts_report." + linter.reporter.extension
report_fn = join(self.build_base, report_fn)
with open(report_fn, "wt") as out:
linter.reporter.set_output(out)
linter.check(self.build_scripts)
self.announce_overview(linter, report_fn)
示例5: Runner
# 需要导入模块: from pylint.lint import PyLinter [as 别名]
# 或者: from pylint.lint.PyLinter import read_config_file [as 别名]
class Runner():
"""
Run and control the checking process.
"""
outputStream = None
linter = None
allowOptions = None
# Customized checkers.
checkers = ("header.HeaderChecker",
"names.TwistedNamesChecker",
"pycodestyleformat.PyCodeStyleChecker",
"docstring.DocstringChecker",
"formattingoperation.FormattingOperationChecker",
"comment.CommentChecker",
"testclassname.TestClassNameChecker")
allowedMessagesFromPylint = ("F0001",
"C0103",
"C0301",
"W0311",
"W0312")
diffOption = None
errorResultRead = "Error: Failed to read result file '%s'.\n"
prefixModuleName = "************* Module "
regexLineStart = "^[WCEFR]\d{4}\:"
def __init__(self):
"""
Initialize C{PyLinter} object, and load configuration file.
"""
self.allowOptions = True
self.linter = PyLinter(self._makeOptions())
# register standard checkers.
self.linter.load_default_plugins()
# read configuration.
pathConfig = os.path.join(twistedchecker.abspath,
"configuration", "pylintrc")
self.linter.read_config_file(pathConfig)
# now we can load file config and command line, plugins (which can
# provide options) have been registered.
self.linter.load_config_file()
allowedMessages = self.registerCheckers()
# disable messages
disabledMessages = set(self.linter
.cfgfile_parser.get("TWISTEDCHECKER", "disable")
.replace(" ", "").split(","))
if disabledMessages != {""}:
for msg in disabledMessages:
self.linter.disable(msg)
allowedMessages -= disabledMessages
# set default output stream to stdout
self.setOutput(sys.stdout)
# set default reporter to limited reporter
self.setReporter(LimitedReporter(allowedMessages))
def _makeOptions(self):
"""
Return options for twistedchecker.
"""
return (
("diff",
{"type": "string",
"metavar": "<result-file>",
"help": "Set comparing result file to automatically "
"generate a diff."}
),
('pep8',
{'type': 'yn', 'metavar': '<y_or_n>',
'default': False,
'help': 'Show pep8 warnings.'}
),
('strict-epydoc',
{'type': 'yn', 'metavar': '<y_or_n>',
'default': False,
'help': "Check '@type' and '@rtype' in epydoc."}
),
)
def setOutput(self, stream):
"""
Set the stream to output result of checking.
@param stream: output stream, defaultly it should be stdout
"""
self.outputStream = stream
sys.stdout = stream
def setReporter(self, reporter):
"""
Set the reporter of pylint.
@param reporter: reporter used to show messages
"""
self.linter.set_reporter(reporter)
def displayHelp(self):
"""
#.........这里部分代码省略.........