[Python-projects] [PATCH] Let pylint exit code indicate result of checks

Mads Kiilerich mads at kiilerich.com
Wed Jan 28 00:58:13 CET 2009


# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1233100681 -3600
# Node ID 09c61bb642e0e788fa7ed8b1e5200fb28a4b40c6
# Parent  6ce473d566da188a385f60d0e559fef5349865da
Let pylint exit code indicate result of checks

If _any_ messages are shown the exitcode will be set to 2.
(Exitcode 1 already indicates that no files were specified.)

This implements what is requested on https://www.logilab.net/elo/ticket/4691 .
The approach taken in this patch is however that any message is an error. If a
message shouldn't count as an error it should be disabled.

There is a risk that some tool tools which call pylint could interprete the
exit code as if _pylint_ failed, and not that pylint completed its job and
concluded that the checked _files_ failed.

Some smoketests fails with this change - how do I change them to accept exitcode 2?

diff --git a/lint.py b/lint.py
--- a/lint.py
+++ b/lint.py
@@ -254,6 +254,7 @@
         self.base_file = None
         self.current_name = None
         self.current_file = None
+        self.msg_counter = None 
         self.stats = None
         # init options
         self.options = options + PyLinter.options
@@ -579,6 +580,7 @@
         
     def open(self):
         """initialize counters"""
+        self.msg_counter = 0
         self.stats = { 'by_module' : {},
                        'by_msg' : {},
                        'statement' : 0
@@ -853,6 +855,8 @@
         else:
             linter.check(args)
         sys.path.pop(0)
+        if self.linter.msg_counter:
+            sys.exit(2)
 
     def cb_rpython_mode(self, name, value):
         from pylint.checkers.rpython import RPythonChecker
diff --git a/utils.py b/utils.py
--- a/utils.py
+++ b/utils.py
@@ -234,6 +234,7 @@
         if not self.is_message_enabled(msg_id, line):
             return        
         # update stats
+        self.msg_counter += 1
         msg_cat = MSG_TYPES[msg_id[0]]
         self.stats[msg_cat] += 1
         self.stats['by_module'][self.current_name][msg_cat] += 1


More information about the Python-Projects mailing list