[chirp_devel] [PATCH 4/7] Add pep8 checker script (#2355)
Zach Welch
Thu Feb 26 00:42:17 PST 2015
# HG changeset patch
# User Zach Welch <zach at mandolincreekfarm.com>
Add pep8 checker script (#2355)
This patch adds a new script that runs the pep8 tool on the CHIRP source
code files. This script is intended to be included in the repository
pre-commit hook, preventing patches from causing style regressions.
The script checks a blacklist of files that are not yet compliant with
the style standards, and those files will not be scanned (unless -a is
given). Since no new files should ever be added to the blacklist, it
should eventually shrink to empty, and the script will check the entire
codebase.
The blacklist makes it safe to begin using this tool immediately, so
this patch also adds a call to it from run_all_tests.sh.
diff --git a/run_all_tests.sh b/run_all_tests.sh
index 48e20a4..8938a58 100755
--- a/run_all_tests.sh
+++ b/run_all_tests.sh
@@ -26,8 +26,14 @@ function style_tests() {
./tools/checkpatch.sh
}
-TESTS="unit_tests driver_tests make_supported style_tests"
-for testname in $TESTS; do
+function pep8() {
+ ./tools/pep8.py --stats
+}
+
+if test -z "${TESTS[*]}"; then
+ TESTS=( unit_tests driver_tests make_supported style_tests pep8 )
+fi
+for testname in "${TESTS[@]}"; do
eval "$testname" || record_failure "$testname"
done
diff --git a/tools/pep8.blacklist b/tools/pep8.blacklist
new file mode 100644
index 0000000..2e87a8f
--- /dev/null
+++ b/tools/pep8.blacklist
@@ -0,0 +1,142 @@
+# DO NOT ADD NEW FILES!! Instead, fix the code to be compliant.
+# Over time, this list should shrink and (eventually) be eliminated.
+# The current list of files that do not yet meet PEP8 standards.
+./chirp/alinco.py
+./chirp/anytone.py
+./chirp/ap510.py
+./chirp/bandplan_au.py
+./chirp/bandplan_iaru_r1.py
+./chirp/bandplan_iaru_r2.py
+./chirp/bandplan_iaru_r3.py
+./chirp/bandplan_na.py
+./chirp/bandplan.py
+./chirp/baofeng_uv3r.py
+./chirp/bitwise_grammar.py
+./chirp/bitwise.py
+./chirp/bjuv55.py
+./chirp/chirp_common.py
+./chirp/detect.py
+./chirp/directory.py
+./chirp/elib_intl.py
+./chirp/errors.py
+./chirp/ft1802.py
+./chirp/ft1d.py
+./chirp/ft2800.py
+./chirp/ft50_ll.py
+./chirp/ft50.py
+./chirp/ft60.py
+./chirp/ft7800.py
+./chirp/ft817.py
+./chirp/ft857.py
+./chirp/ft90.py
+./chirp/ftm350.py
+./chirp/generic_csv.py
+./chirp/generic_tpe.py
+./chirp/generic_xml.py
+./chirp/h777.py
+./chirp/ic208.py
+./chirp/ic2100.py
+./chirp/ic2200.py
+./chirp/ic2720.py
+./chirp/ic2820.py
+./chirp/ic9x_icf_ll.py
+./chirp/ic9x_icf.py
+./chirp/ic9x_ll.py
+./chirp/ic9x.py
+./chirp/icf.py
+./chirp/icomciv.py
+./chirp/icq7.py
+./chirp/ict70.py
+./chirp/ict7h.py
+./chirp/ict8.py
+./chirp/icw32.py
+./chirp/icx8x_ll.py
+./chirp/icx8x.py
+./chirp/id31.py
+./chirp/id51.py
+./chirp/id800.py
+./chirp/id880.py
+./chirp/idrp.py
+./chirp/import_logic.py
+./chirp/__init__.py
+./chirp/kenwood_hmk.py
+./chirp/kenwood_itm.py
+./chirp/kenwood_live.py
+./chirp/kguv8d.py
+./chirp/kyd.py
+./chirp/leixen.py
+./chirp/memmap.py
+./chirp/platform.py
+./chirp/puxing.py
+./chirp/pyPEG.py
+./chirp/radioreference.py
+./chirp/rfinder.py
+./chirp/settings.py
+./chirp/template.py
+./chirp/th9800.py
+./chirp/thd72.py
+./chirp/thuv1f.py
+./chirp/th_uv3r25.py
+./chirp/th_uv3r.py
+./chirp/th_uvf8d.py
+./chirp/tk8102.py
+./chirp/tmv71_ll.py
+./chirp/tmv71.py
+./chirpui/bandplans.py
+./chirpui/bankedit.py
+./chirpui/cloneprog.py
+./chirpui/clone.py
+./chirpui/common.py
+./chirpui/config.py
+./chirpui/dstaredit.py
+./chirpui/editorset.py
+./chirpui/fips.py
+./chirpui/importdialog.py
+./chirpui/__init__.py
+./chirpui/inputdialog.py
+./chirpui/mainapp.py
+./chirpui/memdetail.py
+./chirpui/memedit.py
+./chirpui/miscwidgets.py
+./chirpui/radiobrowser.py
+./chirpui/reporting.py
+./chirpui/settingsedit.py
+./chirpui/shiftdialog.py
+./chirp/util.py
+./chirp/uv5r.py
+./chirp/uvb5.py
+./chirp/vx170.py
+./chirp/vx2.py
+./chirp/vx3.py
+./chirp/vx510.py
+./chirp/vx5.py
+./chirp/vx6.py
+./chirp/vx7.py
+./chirp/vx8.py
+./chirp/vxa700.py
+./chirp/wouxun_common.py
+./chirp/wouxun.py
+./chirp/xml_ll.py
+./chirp/yaesu_clone.py
+./csvdump/csvapp.py
+./csvdump/csvdump.py
+./csvdump/__init__.py
+./csvdump.py
+./locale/check_parameters.py
+./rpttool
+./setup.py
+./share/make_supported.py
+./tests/__init__.py
+./tests/run_tests
+./tests/unit/base.py
+./tests/unit/__init__.py
+./tests/unit/test_bitwise.py
+./tests/unit/test_chirp_common.py
+./tests/unit/test_import_logic.py
+./tests/unit/test_mappingmodel.py
+./tests/unit/test_memedit_edits.py
+./tests/unit/test_platform.py
+./tests/unit/test_settings.py
+./tests/unit/test_shiftdialog.py
+./tools/bitdiff.py
+./tools/img2thd72.py
diff --git a/tools/pep8.manifest b/tools/pep8.manifest
new file mode 100644
index 0000000..2fe9d77
--- /dev/null
+++ b/tools/pep8.manifest
@@ -0,0 +1,4 @@
+./chirpc
+./chirpw
+./rpttool
+./tests/run_tests
diff --git a/tools/pep8.py b/tools/pep8.py
new file mode 100755
index 0000000..efbfd14
--- /dev/null
+++ b/tools/pep8.py
@@ -0,0 +1,75 @@
+#!/usr/bin/env python
+#
+# pep8.py - Check Python source files for PEP8 compliance.
+#
+# Copyright 2015 Zachary T Welch <zach at mandolincreekfarm.com>
+#
+# 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/>.
+
+import os
+import sys
+import logging
+import argparse
+import subprocess
+
+scriptdir = os.path.dirname(sys.argv[0])
+sys.path.insert(0, os.path.join(scriptdir, ".."))
+
+from chirp import logger
+
+LOG = logging.getLogger("pep8.py")
+
+parser = argparse.ArgumentParser()
+parser.add_argument("-a", "--all", action="store_true",
+ help="Check all files, ignoring blacklist")
+parser.add_argument("-d", "--dir", action="store", default=".",
+ help="Root directory of source tree")
+parser.add_argument("--stats", action="store_true",
+ help="Only show statistics")
+parser.add_argument("files", metavar="file", nargs='*',
+ help="List of files to check (if none, check all)")
+logger.add_arguments(parser)
+args = parser.parse_args()
+logger.handle_options(args)
+
+
+def file_to_lines(name):
+ fh = file(name, "r")
+ lines = fh.read().split("\n")
+ lines.pop()
+ fh.close()
+ return lines
+
+# read manifest and search for python files
+manifest = file_to_lines(os.path.join(scriptdir, "pep8.manifest"))
+for root, dirs, files in os.walk(args.dir):
+ for f in files:
+ if f.endswith('.py'):
+ manifest.append(os.path.join(root, f))
+
+# read the blacklisted source files
+blacklist = file_to_lines(os.path.join(scriptdir, "pep8.blacklist"))
+
+if args.files:
+ manifest = args.files
+
+for f in manifest:
+ if args.all or f not in blacklist:
+ LOG.info("checking %s", f)
+ cmdline = ['pep8', f]
+ if args.stats:
+ cmdline += ['-q', '--statistics']
+ returnvalue = subprocess.call(cmdline)
+ if not args.all and returnvalue:
+ sys.exit(returnvalue)
More information about the chirp_devel
mailing list