Skip to content

Commit

Permalink
fix(tools): exclude binary files automatically instead of failing
Browse files Browse the repository at this point in the history
Fixes #166
  • Loading branch information
rubik committed Feb 3, 2019
1 parent 72903d5 commit 3b5d1f7
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions radon/cli/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,15 @@ def _open(path):

def _is_python_file(filename):
'''Check if a file is a Python source file.'''
if filename.endswith('.py'):
if filename == '-' or filename.endswith('.py'):
return True
with open(filename) as fobj:
first_line = fobj.readline()
if first_line.startswith('#!') and 'python' in first_line:
return True
try:
with open(filename) as fobj:
first_line = fobj.readline()
if first_line.startswith('#!') and 'python' in first_line:
return True
except Exception:
return False
return False


Expand Down

0 comments on commit 3b5d1f7

Please sign in to comment.