From c16b9c60871f4f5ed28f03892bdfccab759efc7a Mon Sep 17 00:00:00 2001 From: Harkirat155 Date: Mon, 7 Dec 2020 10:47:56 +0530 Subject: [PATCH] Resolves #882; pull upstream --- .pre-commit-config.yml => .pre-commit-config.yaml | 0 .pre-commit-hooks.yml => .pre-commit-hooks.yaml | 0 CHANGELOG | 2 ++ yapf/yapflib/file_resources.py | 7 ++++--- yapftests/file_resources_test.py | 10 ++++++---- 5 files changed, 12 insertions(+), 7 deletions(-) rename .pre-commit-config.yml => .pre-commit-config.yaml (100%) rename .pre-commit-hooks.yml => .pre-commit-hooks.yaml (100%) diff --git a/.pre-commit-config.yml b/.pre-commit-config.yaml similarity index 100% rename from .pre-commit-config.yml rename to .pre-commit-config.yaml diff --git a/.pre-commit-hooks.yml b/.pre-commit-hooks.yaml similarity index 100% rename from .pre-commit-hooks.yml rename to .pre-commit-hooks.yaml diff --git a/CHANGELOG b/CHANGELOG index d3169c0f7..e512fef6c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,8 @@ - Add 'BLANK_LINES_BETWEEN_TOP_LEVEL_IMPORTS_AND_VARIABLES' to support setting a custom number of blank lines between top-level imports and variable definitions. +### Fixed +- Exclude directories on Windows. ## [0.30.0] 2020-04-23 ### Added diff --git a/yapf/yapflib/file_resources.py b/yapf/yapflib/file_resources.py index 50b4687f4..4c6bf38e8 100644 --- a/yapf/yapflib/file_resources.py +++ b/yapf/yapflib/file_resources.py @@ -154,6 +154,7 @@ def _FindPythonFiles(filenames, recursive, exclude): """Find all Python files.""" if exclude and any(e.startswith('./') for e in exclude): raise errors.YapfError("path in '--exclude' should not start with ./") + exclude = exclude and [e.rstrip("/" + os.path.sep) for e in exclude] python_files = [] for filename in filenames: @@ -186,10 +187,10 @@ def _FindPythonFiles(filenames, recursive, exclude): def IsIgnored(path, exclude): """Return True if filename matches any patterns in exclude.""" - path = path.lstrip('/') - while path.startswith('./'): + path = path.lstrip(os.path.sep) + while path.startswith('.' + os.path.sep): path = path[2:] - return any(fnmatch.fnmatch(path, e.rstrip('/')) for e in exclude) + return any(fnmatch.fnmatch(path, e.rstrip(os.path.sep)) for e in exclude) def IsPythonFile(filename): diff --git a/yapftests/file_resources_test.py b/yapftests/file_resources_test.py index c91d93cf8..2bf68ab1c 100644 --- a/yapftests/file_resources_test.py +++ b/yapftests/file_resources_test.py @@ -152,8 +152,8 @@ def setUp(self): # pylint: disable=g-missing-super-call self.old_dir = os.getcwd() def tearDown(self): # pylint: disable=g-missing-super-call - shutil.rmtree(self.test_tmpdir) os.chdir(self.old_dir) + shutil.rmtree(self.test_tmpdir) def _make_test_dir(self, name): fullpath = os.path.normpath(os.path.join(self.test_tmpdir, name)) @@ -313,7 +313,8 @@ def test_find_with_excluded_dirs(self): 'test2/testinner/', ])) - self.assertEqual(found, ['test3/foo/bar/bas/xxx/testfile3.py']) + self.assertEqual( + found, ['test3/foo/bar/bas/xxx/testfile3.py'.replace("/", os.path.sep)]) found = sorted( file_resources.GetCommandLineFiles(['.'], @@ -323,7 +324,8 @@ def test_find_with_excluded_dirs(self): 'test3', ])) - self.assertEqual(found, ['./test2/testinner/testfile2.py']) + self.assertEqual( + found, ['./test2/testinner/testfile2.py'.replace("/", os.path.sep)]) def test_find_with_excluded_current_dir(self): with self.assertRaises(errors.YapfError): @@ -386,7 +388,7 @@ def test_sub_path(self): def test_trailing_slash(self): self.assertTrue(file_resources.IsIgnored('z', ['z'])) - self.assertTrue(file_resources.IsIgnored('z', ['z/'])) + self.assertTrue(file_resources.IsIgnored('z', ['z' + os.path.sep])) class BufferedByteStream(object):