Skip to content

Commit

Permalink
Merge pull request #537 from hhatto/enable-exclude-option-with-direct…
Browse files Browse the repository at this point in the history
…ly-file-args

enable exclude option when specify directly file args
  • Loading branch information
hhatto committed Apr 11, 2020
2 parents f27d479 + 80ee47c commit 06bfc5a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
8 changes: 7 additions & 1 deletion autopep8.py
Expand Up @@ -4209,7 +4209,13 @@ def find_files(filenames, recursive, exclude):
if match_file(os.path.join(root, d),
exclude)]
else:
yield name
is_exclude_match = False
for pattern in exclude:
if fnmatch.fnmatch(name, pattern):
is_exclude_match = True
break
if not is_exclude_match:
yield name


def _fix_file(parameters):
Expand Down
22 changes: 22 additions & 0 deletions test/test_autopep8.py
Expand Up @@ -5485,6 +5485,28 @@ def test_exclude(self):
finally:
shutil.rmtree(temp_directory)

def test_exclude_with_directly_file_args(self):
temp_directory = mkdtemp(dir='.')
try:
filepath_a = os.path.join(temp_directory, 'a.py')
with open(filepath_a, 'w') as output:
output.write("'abc' \n")

os.mkdir(os.path.join(temp_directory, 'd'))
filepath_b = os.path.join(temp_directory, 'd', 'b.py')
with open(os.path.join(filepath_b), 'w') as output:
output.write('123 \n')

p = Popen(list(AUTOPEP8_CMD_TUPLE) +
['--exclude=*/a.py', '--diff', filepath_a, filepath_b],
stdout=PIPE)
result = p.communicate()[0].decode('utf-8')

self.assertNotIn('abc', result)
self.assertIn('123', result)
finally:
shutil.rmtree(temp_directory)

def test_invalid_option_combinations(self):
line = "'abc' \n"
with temporary_file_context(line) as filename:
Expand Down

0 comments on commit 06bfc5a

Please sign in to comment.