summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2014-04-15 19:40:52 +0100
committerLars Wirzenius <liw@liw.fi>2014-04-15 19:40:52 +0100
commitcbfab73361f859b3dcad2512c528f9820c13a0c6 (patch)
treec7332a52452887451b16a194b2a42faf296f5856
parent1aea623572f2a88775ebf2a5f6e6c945472438dc (diff)
downloadobnam-cbfab73361f859b3dcad2512c528f9820c13a0c6.tar.gz
Move nitpicking code to separate tool
-rwxr-xr-xnitpicker64
-rw-r--r--setup.py15
2 files changed, 67 insertions, 12 deletions
diff --git a/nitpicker b/nitpicker
new file mode 100755
index 00000000..7f3664b1
--- /dev/null
+++ b/nitpicker
@@ -0,0 +1,64 @@
+#!/usr/bin/env python
+# Copyright 2014 Lars Wirzenius
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# =*= License: GPL-3+ =*=
+
+
+import sys
+
+import cliapp
+
+import obnamlib
+
+
+class TabCharacter(obnamlib.ObnamError):
+
+ msg = 'TAB character found: {line}'
+
+
+class LongLine(obnamlib.ObnamError):
+
+ msg = 'long line ({length} chars after TAB expansion): {line}'
+
+
+class SourceCodeNitpicker(cliapp.Application):
+
+ def setup(self):
+ self.errors = False
+
+ def cleanup(self):
+ if self.errors:
+ sys.exit(1)
+
+ def process_input_line(self, filename, line):
+ line = line.rstrip('\n')
+
+ if '\t' in line:
+ self.error(filename, self.lineno, TabCharacter(line=line))
+
+ expanded = line.expandtabs()
+ if len(expanded) > 79:
+ self.error(
+ filename, self.lineno,
+ LongLine(line=line, length=len(expanded)))
+
+ def error(self, filename, lineno, error):
+ self.output.write(
+ '%s:%s: %s\n' % (filename, lineno, str(error)))
+ self.errors = True
+
+
+SourceCodeNitpicker().run()
diff --git a/setup.py b/setup.py
index 498bc3f8..2c18716c 100644
--- a/setup.py
+++ b/setup.py
@@ -181,22 +181,13 @@ class Check(Command):
if self.nitpick:
sources = self.find_all_source_files()
- self.check_sources_for_long_lines(sources)
+ self.check_sources_for_nitpicks(sources)
self.check_copyright_statements(sources)
print "setup.py check done"
- def check_sources_for_long_lines(self, sources):
- for filename in sources:
- self.check_one_source_for_long_lines(filename)
-
- def check_one_source_for_long_lines(self, filename):
- max_line_length = 80
- with open(filename) as f:
- for i, line in enumerate(f):
- line = line.expandtabs()
- if len(line) >= max_line_length:
- print 'LONG: %s: %d: %s' % (filename, i+1, line),
+ def check_sources_for_nitpicks(self, sources):
+ cliapp.runcmd(['./nitpicker'] + sources, stdout=None, stderr=None)
def check_copyright_statements(self, sources):
if self.copylint_is_available():