1#!/usr/bin/env python3 2 3import os 4from os.path import join, splitext 5 6from autopep8_clean_config import PATHS, BLACKLIST 7 8print(PATHS) 9SOURCE_EXT = ( 10 # Python 11 ".py", 12) 13 14 15def is_source(filename): 16 return filename.endswith(SOURCE_EXT) 17 18 19def path_iter(path, filename_check=None): 20 for dirpath, dirnames, filenames in os.walk(path): 21 # skip ".git" 22 dirnames[:] = [d for d in dirnames if not d.startswith(".")] 23 24 for filename in filenames: 25 if filename.startswith("."): 26 continue 27 filepath = join(dirpath, filename) 28 if filename_check is None or filename_check(filepath): 29 yield filepath 30 31 32def path_expand(paths, filename_check=None): 33 for f in paths: 34 if not os.path.exists(f): 35 print("Missing:", f) 36 elif os.path.isdir(f): 37 yield from path_iter(f, filename_check) 38 else: 39 yield f 40 41 42def main(): 43 import sys 44 import subprocess 45 46 if os.path.samefile(sys.argv[-1], __file__): 47 paths = path_expand(PATHS, is_source) 48 else: 49 paths = path_expand(sys.argv[1:], is_source) 50 51 for f in paths: 52 if f in BLACKLIST: 53 continue 54 55 print(f) 56 subprocess.call(( 57 "autopep8", 58 "--ignore", 59 ",".join(( 60 # Info: Use "isinstance()" instead of comparing types directly. 61 # Why disable?: Changes code logic, in rare cases we want to compare exact types. 62 "E721", 63 # Info: Fix bare except. 64 # Why disable?: Disruptive, leave our exceptions alone. 65 "E722", 66 # Info: Put imports on separate lines. 67 # Why disable?: Disruptive, we manage our own imports. 68 "E401", 69 # Info: Fix various deprecated code (via lib2to3) 70 # Why disable?: causes imports to be added/re-arranged. 71 "W690", 72 )), 73 "--aggressive", 74 "--in-place", 75 # Prefer to manually handle line wrapping 76 "--max-line-length", "200", 77 f, 78 )) 79 80 81if __name__ == "__main__": 82 main() 83