| 1 |
""" |
| 2 |
A program to run pyflakes on all in-tree source files, with some |
| 3 |
basic ignoring capabilities. |
| 4 |
|
| 5 |
This assumes it's being called from the tests subdirectory of |
| 6 |
a complete DaCHS checkout. |
| 7 |
|
| 8 |
This is essentially a leaned-down version of the pyflakes script |
| 9 |
with some stuff for which we feel we can crash removed. |
| 10 |
|
| 11 |
See docs/develNotes.rstx for extra ignoring features of this |
| 12 |
script. |
| 13 |
""" |
| 14 |
|
| 15 |
#c Copyright 2008-2025, the GAVO project <[email protected]> |
| 16 |
#c |
| 17 |
#c This program is free software, covered by the GNU GPL. See the |
| 18 |
#c COPYING file in the source distribution. |
| 19 |
|
| 20 |
|
| 21 |
import _ast |
| 22 |
import glob |
| 23 |
import os |
| 24 |
|
| 25 |
from pyflakes import checker |
| 26 |
|
| 27 |
|
| 28 |
def iterSourceFiles(): |
| 29 |
yield from glob.glob("*.py") |
| 30 |
|
| 31 |
for dir, dirs, names in os.walk("../gavo"): |
| 32 |
parts = dir.split("/")[1:] |
| 33 |
if parts[-1]=='imp': |
| 34 |
# Don't check files we don't actually maintain |
| 35 |
del dirs[:] |
| 36 |
continue |
| 37 |
|
| 38 |
for name in names: |
| 39 |
if name.endswith(".py"): |
| 40 |
yield os.path.join(dir, name) |
| 41 |
|
| 42 |
|
| 43 |
def checkOne(filename): |
| 44 |
with open(filename) as f: |
| 45 |
codeString = f.read() |
| 46 |
lines = codeString.split("\n") |
| 47 |
if "# Not checked by pyflakes" in codeString: |
| 48 |
return |
| 49 |
|
| 50 |
tree = compile(codeString, filename, "exec", _ast.PyCF_ONLY_AST) |
| 51 |
w = checker.Checker(tree, filename) |
| 52 |
w.messages.sort(key=lambda msg: msg.lineno) |
| 53 |
for msg in w.messages: |
| 54 |
if not "#noflake" in lines[msg.lineno-1]: |
| 55 |
|
| 56 |
# globally ignore import * warnings (and decide whether to get |
| 57 |
# rid of the imports or fix pyflakes) |
| 58 |
# if (msg.message |
| 59 |
# =="'from %s import *' used; unable to detect undefined names"): |
| 60 |
# continue |
| 61 |
|
| 62 |
print(msg) |
| 63 |
|
| 64 |
|
| 65 |
def main(): |
| 66 |
for filename in iterSourceFiles(): |
| 67 |
checkOne(filename) |
| 68 |
|
| 69 |
|
| 70 |
if __name__=="__main__": |
| 71 |
main() |