From ee30211537702a30381e8377440c5a5550054a4a Mon Sep 17 00:00:00 2001 From: Hideo Hattori Date: Fri, 10 Apr 2020 19:50:45 +0900 Subject: [PATCH 1/2] add unit test: exclude option when specify directly file args --- test/test_autopep8.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/test_autopep8.py b/test/test_autopep8.py index 726c7efb..56083994 100755 --- a/test/test_autopep8.py +++ b/test/test_autopep8.py @@ -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: From 80ee47c23347e095acbd19c6fc28eb8e5f46db3c Mon Sep 17 00:00:00 2001 From: Hideo Hattori Date: Fri, 10 Apr 2020 20:09:08 +0900 Subject: [PATCH 2/2] enable exclude option when specify directly file args --- autopep8.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/autopep8.py b/autopep8.py index dc2b60d6..00a10784 100755 --- a/autopep8.py +++ b/autopep8.py @@ -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):