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