Fix flake8 violation (utils/reindent.py)

This commit is contained in:
Takeshi KOMIYA 2016-06-11 23:29:03 +09:00
parent 7ab5bed4be
commit 2483122c2f
2 changed files with 20 additions and 13 deletions

View File

@ -26,4 +26,4 @@ universal = 1
[flake8]
max-line-length=95
ignore=E113,E116,E221,E226,E241,E251
exclude=utils/*,tests/*,build/*,sphinx/search/*,sphinx/pycode/pgen2/*
exclude=tests/*,build/*,sphinx/search/*,sphinx/pycode/pgen2/*

View File

@ -40,11 +40,12 @@ you'd prefer. You can always use the --nobackup option to prevent this.
"""
from __future__ import print_function
__version__ = "1"
import tokenize
import os, shutil
import os
import sys
import shutil
import tokenize
__version__ = "1"
if sys.version_info >= (3, 0):
def tokens(readline, tokeneater):
@ -58,11 +59,13 @@ recurse = 0
dryrun = 0
makebackup = True
def usage(msg=None):
if msg is not None:
print(msg, file=sys.stderr)
print(__doc__, file=sys.stderr)
def errprint(*args):
sep = ""
for arg in args:
@ -70,12 +73,13 @@ def errprint(*args):
sep = " "
sys.stderr.write("\n")
def main():
import getopt
global verbose, recurse, dryrun, makebackup
try:
opts, args = getopt.getopt(sys.argv[1:], "drnvh",
["dryrun", "recurse", "nobackup", "verbose", "help"])
["dryrun", "recurse", "nobackup", "verbose", "help"])
except getopt.error as msg:
usage(msg)
return
@ -99,6 +103,7 @@ def main():
for arg in args:
check(arg)
def check(file):
if os.path.isdir(file) and not os.path.islink(file):
if verbose:
@ -108,8 +113,8 @@ def check(file):
fullname = os.path.join(file, name)
if ((recurse and os.path.isdir(fullname) and
not os.path.islink(fullname) and
not os.path.split(fullname)[1].startswith("."))
or name.lower().endswith(".py")):
not os.path.split(fullname)[1].startswith(".")) or
name.lower().endswith(".py")):
check(fullname)
return
@ -145,6 +150,7 @@ def check(file):
print("unchanged.")
return False
def _rstrip(line, JUNK='\n \t'):
"""Return line stripped of trailing spaces, tabs, newlines.
@ -158,8 +164,8 @@ def _rstrip(line, JUNK='\n \t'):
i -= 1
return line[:i]
class Reindenter:
class Reindenter:
def __init__(self, f):
self.find_stmt = 1 # next token begins a fresh stmt?
self.level = 0 # current indent level
@ -218,15 +224,15 @@ class Reindenter:
if have == getlspace(lines[jline]):
want = jlevel * 4
break
if want < 0: # Maybe it's a hanging
# comment like this one,
if want < 0: # Maybe it's a hanging
# comment like this one,
# in which case we should shift it like its base
# line got shifted.
for j in xrange(i-1, -1, -1):
jline, jlevel = stats[j]
if jlevel >= 0:
want = have + getlspace(after[jline-1]) - \
getlspace(lines[jline])
want = (have + getlspace(after[jline-1]) -
getlspace(lines[jline]))
break
if want < 0:
# Still no luck -- leave it alone.
@ -301,6 +307,7 @@ class Reindenter:
if line: # not endmarker
self.stats.append((position[0], self.level))
# Count number of leading blanks.
def getlspace(line):
i, n = 0, len(line)