| 1 | #! /usr/bin/env python
|
|---|
| 2 |
|
|---|
| 3 | """The Tab Nanny despises ambiguous indentation. She knows no mercy.
|
|---|
| 4 |
|
|---|
| 5 | tabnanny -- Detection of ambiguous indentation
|
|---|
| 6 |
|
|---|
| 7 | For the time being this module is intended to be called as a script.
|
|---|
| 8 | However it is possible to import it into an IDE and use the function
|
|---|
| 9 | check() described below.
|
|---|
| 10 |
|
|---|
| 11 | Warning: The API provided by this module is likely to change in future
|
|---|
| 12 | releases; such changes may not be backward compatible.
|
|---|
| 13 | """
|
|---|
| 14 |
|
|---|
| 15 | # Released to the public domain, by Tim Peters, 15 April 1998.
|
|---|
| 16 |
|
|---|
| 17 | # XXX Note: this is now a standard library module.
|
|---|
| 18 | # XXX The API needs to undergo changes however; the current code is too
|
|---|
| 19 | # XXX script-like. This will be addressed later.
|
|---|
| 20 |
|
|---|
| 21 | __version__ = "6"
|
|---|
| 22 |
|
|---|
| 23 | import os
|
|---|
| 24 | import sys
|
|---|
| 25 | import getopt
|
|---|
| 26 | import tokenize
|
|---|
| 27 | if not hasattr(tokenize, 'NL'):
|
|---|
| 28 | raise ValueError("tokenize.NL doesn't exist -- tokenize module too old")
|
|---|
| 29 |
|
|---|
| 30 | __all__ = ["check", "NannyNag", "process_tokens"]
|
|---|
| 31 |
|
|---|
| 32 | verbose = 0
|
|---|
| 33 | filename_only = 0
|
|---|
| 34 |
|
|---|
| 35 | def errprint(*args):
|
|---|
| 36 | sep = ""
|
|---|
| 37 | for arg in args:
|
|---|
| 38 | sys.stderr.write(sep + str(arg))
|
|---|
| 39 | sep = " "
|
|---|
| 40 | sys.stderr.write("\n")
|
|---|
| 41 |
|
|---|
| 42 | def main():
|
|---|
| 43 | global verbose, filename_only
|
|---|
| 44 | try:
|
|---|
| 45 | opts, args = getopt.getopt(sys.argv[1:], "qv")
|
|---|
| 46 | except getopt.error, msg:
|
|---|
| 47 | errprint(msg)
|
|---|
| 48 | return
|
|---|
| 49 | for o, a in opts:
|
|---|
| 50 | if o == '-q':
|
|---|
| 51 | filename_only = filename_only + 1
|
|---|
| 52 | if o == '-v':
|
|---|
| 53 | verbose = verbose + 1
|
|---|
| 54 | if not args:
|
|---|
| 55 | errprint("Usage:", sys.argv[0], "[-v] file_or_directory ...")
|
|---|
| 56 | return
|
|---|
| 57 | for arg in args:
|
|---|
| 58 | check(arg)
|
|---|
|
|---|