提交 c4750c68 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Merge pull request #2593 from lamblin/skip_flake8

Skip flake8 if not installed
...@@ -5,11 +5,16 @@ __authors__ = ("Saizheng Zhang") ...@@ -5,11 +5,16 @@ __authors__ = ("Saizheng Zhang")
__copyright__ = "(c) 2015, Universite de Montreal" __copyright__ = "(c) 2015, Universite de Montreal"
__contact__ = "Saizheng Zhang <saizhenglisa..at..gmail.com>" __contact__ = "Saizheng Zhang <saizhenglisa..at..gmail.com>"
import unittest from nose.plugins.skip import SkipTest
import os import os
from fnmatch import fnmatch from fnmatch import fnmatch
import theano import theano
import flake8.engine, flake8.main try:
import flake8.engine
import flake8.main
flake8_available = True
except ImportError:
flake8_available = False
whitelist_flake8 = [ whitelist_flake8 = [
"updates.py", "updates.py",
...@@ -33,7 +38,6 @@ whitelist_flake8 = [ ...@@ -33,7 +38,6 @@ whitelist_flake8 = [
"tests/test_record.py", "tests/test_record.py",
"tests/__init__.py", "tests/__init__.py",
"tests/test_updates.py", "tests/test_updates.py",
"tests/test_flake8.py",
"tests/main.py", "tests/main.py",
"tests/test_pickle_unpickle_theano_fn.py", "tests/test_pickle_unpickle_theano_fn.py",
"tests/test_determinism.py", "tests/test_determinism.py",
...@@ -341,7 +345,7 @@ whitelist_flake8 = [ ...@@ -341,7 +345,7 @@ whitelist_flake8 = [
] ]
def list_files(dir_path = theano.__path__[0], pattern = '*.py'): def list_files(dir_path=theano.__path__[0], pattern='*.py'):
""" """
List all files under theano's path. List all files under theano's path.
""" """
...@@ -349,8 +353,8 @@ def list_files(dir_path = theano.__path__[0], pattern = '*.py'): ...@@ -349,8 +353,8 @@ def list_files(dir_path = theano.__path__[0], pattern = '*.py'):
for (dir, _, files) in os.walk(dir_path): for (dir, _, files) in os.walk(dir_path):
for f in files: for f in files:
if fnmatch(f, pattern): if fnmatch(f, pattern):
path = os.path.join(dir, f) path = os.path.join(dir, f)
files_list.append(path) files_list.append(path)
return files_list return files_list
...@@ -358,7 +362,8 @@ def test_format_flake8(): ...@@ -358,7 +362,8 @@ def test_format_flake8():
""" """
Test if flake8 is respected. Test if flake8 is respected.
""" """
files_to_check = [] if not flake8_available:
raise SkipTest("flake8 is not installed")
total_errors = 0 total_errors = 0
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])
...@@ -393,7 +398,7 @@ def print_files_information_flake8(): ...@@ -393,7 +398,7 @@ def print_files_information_flake8():
print(file) print(file)
print("Files that can be removed from whitelist:") print("Files that can be removed from whitelist:")
for file in non_infracting_files: for file in non_infracting_files:
print(file) print(file)
def check_all_files(dir_path=theano.__path__[0], pattern='*.py'): def check_all_files(dir_path=theano.__path__[0], pattern='*.py'):
...@@ -410,10 +415,11 @@ def check_all_files(dir_path=theano.__path__[0], pattern='*.py'): ...@@ -410,10 +415,11 @@ def check_all_files(dir_path=theano.__path__[0], pattern='*.py'):
if fnmatch(f, pattern): if fnmatch(f, pattern):
error_num = flake8.main.check_file(os.path.join(dir, f)) error_num = flake8.main.check_file(os.path.join(dir, f))
if error_num > 0: if error_num > 0:
path = os.path.relpath(os.path.join(dir, f), theano.__path__[0]) path = os.path.relpath(os.path.join(dir, f),
f_txt.write('"'+ path + '",\n') theano.__path__[0])
f_txt.write('"' + path + '",\n')
f_txt.close() f_txt.close()
if __name__ == "__main__": if __name__ == "__main__":
print_files_information_flake8() print_files_information_flake8()
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论