Hi, this is the core of the code I use to call pylint from paver as part of a
build process:
from pylint import lint as linter
# report according to file extension
reporters = {
".html": linter.HTMLReporter,
".log": linter.ParseableTextReporter,
".txt": linter.TextReporter,
}
argv = ["--rcfile", rcfile, ....]
sys.stderr.write("Running %s::pylint '%s'\n" % (sys.argv[0], "'
'".join(argv)))
outfile = options.get("output", None)
if outfile:
outfile = os.path.abspath(outfile)
try:
saved_cwd = os.getcwd()
try:
if os.path.exists("src"):
os.chdir("src")
if outfile:
reporterClass = reporters.get(path(outfile).ext,
linter.TextReporter)
sys.stderr.write("Writing output to %r\n" % (str(outfile),))
linter.Run(argv, reporter=reporterClass(open(outfile, "w")))
else:
linter.Run(argv)
finally:
os.chdir(saved_cwd)
except SystemExit, exc:
if not exc.code:
sys.stderr.write("paver::lint - No problems found.\n")
elif exc.code & 32:
# usage error (internal error in this code)
sys.stderr.write("paver::lint - Usage error, bad arguments %r?!\n"
% (argv,))
raise
else:
bits = {
1: "fatal",
2: "error",
4: "warning",
8: "refactor",
16: "convention",
}
sys.stderr.write("paver::lint - Some %s message(s) issued.\n" % (
", ".join([text for bit, text in bits.items() if exc.code &
bit])
))
if exc.code & 3:
sys.stderr.write("paver::lint - Exiting due to fatal / error
message.\n")
raise
BTW, nowadays it's more usual to run this stuff in a continuous build system
_triggered_ by a commit, you might consider that approach instead of a commit
hook, since it has numerous advantages.
________________________________________
Von: [email protected]
[[email protected]] im Auftrag von Stephen Mullins
[[email protected]]
Gesendet: Dienstag, 21. Dezember 2010 01:31
An: [email protected]
Betreff: [Python-projects] Using pylint as a mercurial commit hook
Hello,
I just discovered pylint while looking for a static code analysis tool and am
interested in using it at work. What would make it most effective is to
integrate pylint with mercurial to check for stying/errors on any files that
have been added or modified in the changeset. I've written commit hooks before
so I'm familiar with that piece. I'd like to know if this has already been done
before, if not is there documentation on using pylint in a python process? I
realize its intended to be called from the command line but I'm hoping its
straightforward to use an API from within a python module.
Thanks,
Stephen
_______________________________________________
Python-Projects mailing list
[email protected]
http://lists.logilab.org/mailman/listinfo/python-projects