# HG changeset patch # User Zach Welch zach@mandolincreekfarm.com # Fake Node ID fdb1083cf35cf98f316a35006db2cc335099a18f
Improve cpep8.py (#2355)
This patch expands cpep8.manifest to contain all files, allowing the cpep8.py script to use it instead of scanning for files. Scanning can now be done with --scan. If both --scan and --update options are given, the manifest file will be updated with the scan results.
Altogether, this should fix problems that Windows users were seeing, caused by mismatches between the dynamic manifest and the blacklist (due to different path separators).
diff --git a/tools/cpep8.manifest b/tools/cpep8.manifest index 2fe9d77..dbd90be 100644 --- a/tools/cpep8.manifest +++ b/tools/cpep8.manifest @@ -1,4 +1,143 @@ +./chirp/__init__.py +./chirp/alinco.py +./chirp/anytone.py +./chirp/ap510.py +./chirp/bandplan.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/baofeng_uv3r.py +./chirp/bitwise.py +./chirp/bitwise_grammar.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.py +./chirp/ft50_ll.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.py +./chirp/ic9x_icf.py +./chirp/ic9x_icf_ll.py +./chirp/ic9x_ll.py +./chirp/icf.py +./chirp/icomciv.py +./chirp/icq7.py +./chirp/ict70.py +./chirp/ict7h.py +./chirp/ict8.py +./chirp/icw32.py +./chirp/icx8x.py +./chirp/icx8x_ll.py +./chirp/id31.py +./chirp/id51.py +./chirp/id800.py +./chirp/id880.py +./chirp/idrp.py +./chirp/import_logic.py +./chirp/kenwood_hmk.py +./chirp/kenwood_itm.py +./chirp/kenwood_live.py +./chirp/kguv8d.py +./chirp/kyd.py +./chirp/leixen.py +./chirp/logger.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/th_uv3r.py +./chirp/th_uv3r25.py +./chirp/th_uvf8d.py +./chirp/thd72.py +./chirp/thuv1f.py +./chirp/tk8102.py +./chirp/tmv71.py +./chirp/tmv71_ll.py +./chirp/util.py +./chirp/uv5r.py +./chirp/uvb5.py +./chirp/vx170.py +./chirp/vx2.py +./chirp/vx3.py +./chirp/vx5.py +./chirp/vx510.py +./chirp/vx6.py +./chirp/vx7.py +./chirp/vx8.py +./chirp/vxa700.py +./chirp/wouxun.py +./chirp/wouxun_common.py +./chirp/xml_ll.py +./chirp/yaesu_clone.py ./chirpc +./chirpui/__init__.py +./chirpui/bandplans.py +./chirpui/bankedit.py +./chirpui/clone.py +./chirpui/cloneprog.py +./chirpui/common.py +./chirpui/config.py +./chirpui/dstaredit.py +./chirpui/editorset.py +./chirpui/fips.py +./chirpui/importdialog.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 ./chirpw +./csvdump.py +./csvdump/__init__.py +./csvdump/csvapp.py +./csvdump/csvdump.py +./locale/check_parameters.py ./rpttool +./setup.py +./share/make_supported.py +./tests/__init__.py ./tests/run_tests +./tests/unit/__init__.py +./tests/unit/base.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/cpep8.py +./tools/img2thd72.py diff --git a/tools/cpep8.py b/tools/cpep8.py index efaca7a..db33ab1 100755 --- a/tools/cpep8.py +++ b/tools/cpep8.py @@ -23,8 +23,6 @@ import logging import argparse import pep8
-scriptdir = os.path.dirname(sys.argv[0]) - parser = argparse.ArgumentParser() parser.add_argument("-a", "--all", action="store_true", help="Check all files, ignoring blacklist") @@ -32,8 +30,10 @@ parser.add_argument("-d", "--dir", action="store", default=".", help="Root directory of source tree") parser.add_argument("-s", "--stats", action="store_true", help="Only show statistics") +parser.add_argument("-S", "--scan", action="store_true", + help="Scan for additional files") parser.add_argument("-u", "--update", action="store_true", - help="Update the blacklist file") + help="Update manifest/blacklist files") parser.add_argument("-v", "--verbose", action="store_true", help="Display list of checked files") parser.add_argument("files", metavar="file", nargs='*', @@ -48,16 +48,25 @@ def file_to_lines(name): fh.close() return lines
-# read manifest and search for python files -manifest = file_to_lines(os.path.join(scriptdir, "cpep8.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 +scriptdir = os.path.dirname(sys.argv[0]) +manifest_filename = os.path.join(scriptdir, "cpep8.manifest") blacklist_filename = os.path.join(scriptdir, "cpep8.blacklist") -blacklist = file_to_lines(blacklist_filename) + +manifest = [] +if args.scan: + for root, dirs, files in os.walk(args.dir): + for f in files: + filename = os.path.join(root, f) + if f.endswith('.py'): + manifest.append(filename) + continue + with file(filename, "r") as fh: + shebang = fh.readline() + if shebang.startswith("#!/usr/bin/env python"): + manifest.append(filename) +else: + manifest += file_to_lines(manifest_filename)
if args.update: bad = [] @@ -66,17 +75,25 @@ if args.update: results = checker.check_files([f]) if results.total_errors: bad.append(f) + with file(blacklist_filename, "w") as fh: print >>fh, """\ # cpep8.blacklist: The list of files that do not meet PEP8 standards. # DO NOT ADD NEW FILES!! Instead, fix the code to be compliant. # Over time, this list should shrink and (eventually) be eliminated.""" print >>fh, "\n".join(sorted(bad)) + + if args.scan: + with file(manifest_filename, "w") as fh: + print >>fh, "\n".join(sorted(manifest)) sys.exit(0)
if args.files: manifest = args.files
+# read the blacklisted source files +blacklist = file_to_lines(blacklist_filename) + check_list = [] for f in manifest: if args.all or f not in blacklist: