@@ -49,6 +49,21 @@ def _get_list_of_committed_files():
49
49
return files
50
50
51
51
52
+ def _is_python_file (filename ):
53
+ """Check if the input file looks like a Python script
54
+
55
+ Returns True if the filename ends in ".py" or if the first line
56
+ contains "python" and "#!", returns False otherwise.
57
+
58
+ """
59
+ if filename .endswith ('.py' ):
60
+ return True
61
+ else :
62
+ with open (filename , 'r' ) as file_handle :
63
+ first_line = file_handle .readline ()
64
+ return 'python' in first_line and '#!' in first_line
65
+
66
+
52
67
def check_repo (
53
68
limit , pylint = 'pylint' , pylintrc = '.pylintrc' , pylint_params = None ):
54
69
""" Main function doing the checks
@@ -70,16 +85,8 @@ def check_repo(
70
85
71
86
# Find Python files
72
87
for filename in _get_list_of_committed_files ():
73
- # Check the file extension
74
- if filename [- 3 :] == '.py' :
75
- python_files .append ((filename , None ))
76
- continue
77
-
78
- # Check the first line for a python shebang
79
88
try :
80
- with open (filename , 'r' ) as file_handle :
81
- first_line = file_handle .readline ()
82
- if 'python' in first_line and '#!' in first_line :
89
+ if _is_python_file (filename ):
83
90
python_files .append ((filename , None ))
84
91
except IOError :
85
92
print 'File not found (probably deleted): {}\t \t SKIPPED' .format (
0 commit comments