check(file_or_dir) If file_or_dir is a directory and not a symbolic link, then recursively descend the directory tree named by file_or_dir, checking all .py files along the way. If file_or_dir is an ordinary Python source file, it is checked for whitespace related problems. The diag
(file)
| 66 | return self.line |
| 67 | |
| 68 | def check(file): |
| 69 | """check(file_or_dir) |
| 70 | |
| 71 | If file_or_dir is a directory and not a symbolic link, then recursively |
| 72 | descend the directory tree named by file_or_dir, checking all .py files |
| 73 | along the way. If file_or_dir is an ordinary Python source file, it is |
| 74 | checked for whitespace related problems. The diagnostic messages are |
| 75 | written to standard output using the print statement. |
| 76 | """ |
| 77 | |
| 78 | if os.path.isdir(file) and not os.path.islink(file): |
| 79 | if verbose: |
| 80 | print("%r: listing directory" % (file,)) |
| 81 | names = os.listdir(file) |
| 82 | for name in names: |
| 83 | fullname = os.path.join(file, name) |
| 84 | if (os.path.isdir(fullname) and |
| 85 | not os.path.islink(fullname) or |
| 86 | os.path.normcase(name[-3:]) == ".py"): |
| 87 | check(fullname) |
| 88 | return |
| 89 | |
| 90 | try: |
| 91 | f = tokenize.open(file) |
| 92 | except OSError as msg: |
| 93 | errprint("%r: I/O Error: %s" % (file, msg)) |
| 94 | return |
| 95 | |
| 96 | if verbose > 1: |
| 97 | print("checking %r ..." % file) |
| 98 | |
| 99 | try: |
| 100 | process_tokens(tokenize.generate_tokens(f.readline)) |
| 101 | |
| 102 | except tokenize.TokenError as msg: |
| 103 | errprint("%r: Token Error: %s" % (file, msg)) |
| 104 | return |
| 105 | |
| 106 | except IndentationError as msg: |
| 107 | errprint("%r: Indentation Error: %s" % (file, msg)) |
| 108 | return |
| 109 | |
| 110 | except SyntaxError as msg: |
| 111 | errprint("%r: Syntax Error: %s" % (file, msg)) |
| 112 | return |
| 113 | |
| 114 | except NannyNag as nag: |
| 115 | badline = nag.get_lineno() |
| 116 | line = nag.get_line() |
| 117 | if verbose: |
| 118 | print("%r: *** Line %d: trouble in tab city! ***" % (file, badline)) |
| 119 | print("offending line: %r" % (line,)) |
| 120 | print(nag.get_msg()) |
| 121 | else: |
| 122 | if ' ' in file: file = '"' + file + '"' |
| 123 | if filename_only: print(file) |
| 124 | else: print(file, badline, repr(line)) |
| 125 | return |
searching dependent graphs…