Skip to content

Commit

Permalink
Allow excluding directories
Browse files Browse the repository at this point in the history
This fixes #92.
  • Loading branch information
myint committed Oct 26, 2013
1 parent 95dbfcc commit f318bf5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ Options::
infinite)
-a, --aggressive enable non-whitespace changes; multiple -a result in
more aggressive changes
--exclude=globs exclude files that match these comma-separated globs
--exclude=globs exclude file/directory names that match these comma-
separated globs
--list-fixes list codes for fixes; used by --ignore and --select
--ignore=errors do not fix these errors/warnings (default: E24)
--select=errors fix only these errors/warnings (e.g. E4,W)
Expand Down
15 changes: 9 additions & 6 deletions autopep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -1936,8 +1936,8 @@ def create_parser():
help='enable non-whitespace changes; '
'multiple -a result in more aggressive changes')
parser.add_option('--exclude', metavar='globs',
help='exclude files that match these comma-separated '
'globs')
help='exclude file/directory names that match these '
'comma-separated globs')
parser.add_option('--list-fixes', action='store_true',
help='list codes for fixes; '
'used by --ignore and --select')
Expand Down Expand Up @@ -2204,14 +2204,16 @@ def flush(self):

def match_file(filename, exclude):
"""Return True if file is okay for modifying/recursing."""
if os.path.basename(filename).startswith('.'):
base_name = os.path.basename(filename)

if base_name.startswith('.'):
return False

for pattern in exclude:
if fnmatch.fnmatch(filename, pattern):
if fnmatch.fnmatch(base_name, pattern):
return False

if not is_python_file(filename):
if not os.path.isdir(filename) and not is_python_file(filename):
return False

return True
Expand All @@ -2226,7 +2228,8 @@ def find_files(filenames, recursive, exclude):
filenames += [os.path.join(root, f) for f in children
if match_file(f, exclude)]
directories[:] = [d for d in directories
if not d.startswith('.')]
if match_file(os.path.join(root, d),
exclude)]
else:
yield name

Expand Down

0 comments on commit f318bf5

Please sign in to comment.