Unverified 提交 3ff31f1a authored 作者: abergeron's avatar abergeron 提交者: GitHub

Merge pull request #6583 from nouiz/flake8_version

Support more recent flake8 version
......@@ -101,7 +101,7 @@ def do_setup():
install_requires=['numpy>=1.9.1', 'scipy>=0.14', 'six>=1.9.0'],
# pygments is a dependency for Sphinx code highlight
extras_require={
'test': ['nose>=1.3.0', 'parameterized', 'flake8<3'],
'test': ['nose>=1.3.0', 'parameterized', 'flake8'],
'doc': ['Sphinx>=0.5.1', 'pygments']
},
package_data={
......
......@@ -130,7 +130,7 @@ def maybe_add_to_os_environ_pathlist(var, newpath):
if newpath not in oldpaths:
newpaths = os.pathsep.join([newpath] + oldpaths)
os.environ[var] = newpaths
except:
except Exception:
pass
__all__ += ['maybe_add_to_os_environ_pathlist']
......@@ -124,7 +124,7 @@ class change_flags(object):
try:
for k, v in iteritems(self.confs):
v.__set__(None, self.new_vals[k])
except:
except Exception:
self.__exit__()
raise
......
......@@ -245,7 +245,7 @@ class Loop(VM):
t1 = time.time()
self.call_counts[i] += 1
self.call_times[i] += t1 - t0
except:
except Exception:
link.raise_with_op(node, thunk)
else:
for cont in self.pre_call_clear:
......@@ -253,7 +253,7 @@ class Loop(VM):
try:
for thunk, node in zip(self.thunks, self.nodes):
thunk()
except:
except Exception:
link.raise_with_op(node, thunk)
......@@ -289,7 +289,7 @@ class LoopGC(VM):
for old_s in old_storage:
old_s[0] = None
i += 1
except:
except Exception:
link.raise_with_op(node, thunk)
else:
for cont in self.pre_call_clear:
......@@ -300,7 +300,7 @@ class LoopGC(VM):
thunk()
for old_s in old_storage:
old_s[0] = None
except:
except Exception:
link.raise_with_op(node, thunk)
......
......@@ -1007,7 +1007,7 @@ class ScanInplaceOptimizer(Optimizer):
try:
alloc_ops += (theano.gpuarray.GpuAlloc,
theano.gpuarray.GpuAllocEmpty)
except:
except Exception:
pass
nodes = fgraph.toposort()[::-1]
......
......@@ -3838,7 +3838,7 @@ class Split(Op):
try:
len_along_axis = x.shape[axis]
except:
except Exception:
raise ValueError('Split.perform() with axis=(%s) is invalid'
' for x.shape==(%s)'
% (axis, x.shape))
......
......@@ -104,7 +104,7 @@ class PdbBreakpoint(Op):
if condition:
try:
monitored = [np.asarray(inp) for inp in inputs[1:]]
except:
except Exception:
raise ValueError("Some of the inputs to the PdbBreakpoint op "
"'%s' could not be casted to NumPy arrays" %
self.name)
......
......@@ -7,10 +7,15 @@ import os
import sys
from fnmatch import fnmatch
import theano
new_flake8 = True
try:
import flake8.engine
import flake8.main
flake8_available = True
try:
import flake8.engine
new_flake8 = False
except ImportError:
import flake8.api.legacy
except ImportError:
flake8_available = False
......@@ -29,9 +34,11 @@ __contact__ = "Saizheng Zhang <saizhenglisa..at..gmail.com>"
# - "'division' present"
# - "'absolute_import' present"
# - "'print_function' present"
# - "expected 2 blank lines after class or function definition"' (E305)
# - "ambiguous variable name" (E741)
# Redundant error code generated by flake8-future-import module
ignore = ('E501', 'E123', 'E133', 'FI12', 'FI14', 'FI15', 'FI16', 'FI17',
'FI50', 'FI51', 'FI53')
'FI50', 'FI51', 'FI53', 'E305', 'E741')
whitelist_flake8 = [
"__init__.py",
......@@ -126,6 +133,8 @@ def test_format_flake8():
if not flake8_available:
raise SkipTest("flake8 is not installed")
total_errors = 0
files_to_checks = []
for path in list_files():
rel_path = os.path.relpath(path, theano.__path__[0])
if sys.platform == 'win32':
......@@ -133,8 +142,17 @@ def test_format_flake8():
if rel_path in whitelist_flake8:
continue
else:
files_to_checks.append(path)
if new_flake8:
guide = flake8.api.legacy.get_style_guide(ignore=ignore)
r = guide.check_files(files_to_checks)
total_errors = r.total_errors
else:
for path in files_to_checks:
error_num = flake8.main.check_file(path, ignore=ignore)
total_errors += error_num
if total_errors > 0:
raise AssertionError("FLAKE8 Format not respected")
......
......@@ -75,7 +75,7 @@ class testgrad_sources_inputs(unittest.TestCase):
# Test grad is called correctly for a 1-to-1 op
gval = theano.tensor.matrix()
class O(gof.op.Op):
class TestOp(gof.op.Op):
__props__ = ()
def make_node(self):
......@@ -85,7 +85,7 @@ class testgrad_sources_inputs(unittest.TestCase):
def grad(self, inp, grads):
return gval,
a1 = O().make_node()
a1 = TestOp().make_node()
g = grad_sources_inputs([(a1.outputs[0], one)], None)
self.assertTrue(g[a1.inputs[0]] is gval)
......@@ -93,7 +93,7 @@ class testgrad_sources_inputs(unittest.TestCase):
# Test grad is called correctly for a 1-to-many op
gval = theano.tensor.matrix()
class O(gof.op.Op):
class TestOp(gof.op.Op):
__props__ = ()
def make_node(self):
......@@ -105,7 +105,7 @@ class testgrad_sources_inputs(unittest.TestCase):
x, = inp
gz1, gz2 = grads
return gval,
a1 = O().make_node()
a1 = TestOp().make_node()
g = grad_sources_inputs([(a1.outputs[0], one)], None)
self.assertTrue(g[a1.inputs[0]] is gval)
......@@ -114,7 +114,7 @@ class testgrad_sources_inputs(unittest.TestCase):
gval0 = theano.tensor.scalar()
gval1 = theano.tensor.scalar()
class O(gof.op.Op):
class TestOp(gof.op.Op):
__props__ = ()
def make_node(self):
......@@ -126,7 +126,7 @@ class testgrad_sources_inputs(unittest.TestCase):
x0, x1 = inp
gz, = grads
return (gval0, gval1)
a1 = O().make_node()
a1 = TestOp().make_node()
g = grad_sources_inputs([(a1.outputs[0], one)], None)
self.assertTrue(g[a1.inputs[0]] is gval0)
self.assertTrue(g[a1.inputs[1]] is gval1)
......@@ -136,7 +136,7 @@ class testgrad_sources_inputs(unittest.TestCase):
gval0 = theano.tensor.matrix()
gval1 = theano.tensor.matrix()
class O(gof.op.Op):
class TestOp(gof.op.Op):
__props__ = ()
def make_node(self):
......@@ -146,7 +146,7 @@ class testgrad_sources_inputs(unittest.TestCase):
def grad(self, inp, grads):
return gval0, gval1
a1 = O().make_node()
a1 = TestOp().make_node()
g = grad_sources_inputs([(a1.outputs[0], one)], None)
self.assertTrue(g[a1.inputs[0]] is gval0)
self.assertTrue(g[a1.inputs[1]] is gval1)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论