Skip to content

Commit 859138f

Browse files
committed
apply exclude option when use glob
1 parent 9fe7aae commit 859138f

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

autoflake.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ def fix_code(source, additional_imports=None, expand_star_imports=False,
615615
remove_duplicate_keys=remove_duplicate_keys,
616616
remove_unused_variables=remove_unused_variables,
617617
ignore_init_module_imports=ignore_init_module_imports,
618-
))))
618+
))))
619619

620620
if filtered_source == source:
621621
break
@@ -647,7 +647,7 @@ def fix_file(filename, args, standard_out):
647647
remove_duplicate_keys=args.remove_duplicate_keys,
648648
remove_unused_variables=args.remove_unused_variables,
649649
ignore_init_module_imports=ignore_init_module_imports,
650-
)
650+
)
651651

652652
if original_source != filtered_source:
653653
if args.in_place:
@@ -745,25 +745,33 @@ def is_python_file(filename):
745745
return True
746746

747747

748-
def match_file(filename, exclude):
749-
"""Return True if file is okay for modifying/recursing."""
748+
def is_exclude_file(filename,exclude):
749+
"""Return True if file matches exclude pattern"""
750750
base_name = os.path.basename(filename)
751751

752752
if base_name.startswith('.'):
753-
return False
753+
return True
754754

755755
for pattern in exclude:
756756
if fnmatch.fnmatch(base_name, pattern):
757-
return False
757+
return True
758758
if fnmatch.fnmatch(filename, pattern):
759-
return False
759+
return True
760+
return False
761+
762+
def match_file(filename, exclude):
763+
"""Return True if file is okay for modifying/recursing."""
764+
if is_exclude_file(filename,exclude):
765+
return False
760766

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

764770
return True
765771

766772

773+
774+
767775
def find_files(filenames, recursive, exclude):
768776
"""Yield filenames."""
769777
while filenames:
@@ -777,7 +785,8 @@ def find_files(filenames, recursive, exclude):
777785
if match_file(os.path.join(root, d),
778786
exclude)]
779787
else:
780-
yield name
788+
if not is_exclude_file(name, exclude):
789+
yield name
781790

782791

783792
def _main(argv, standard_out, standard_error):

0 commit comments

Comments
 (0)