Skip to content

Commit

Permalink
Resolves #882;
Browse files Browse the repository at this point in the history
pull upstream
  • Loading branch information
Harkirat155 committed Dec 7, 2020
1 parent 97fb350 commit c16b9c6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions CHANGELOG
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions yapf/yapflib/file_resources.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
10 changes: 6 additions & 4 deletions yapftests/file_resources_test.py
Expand Up @@ -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))
Expand Down Expand Up @@ -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(['.'],
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit c16b9c6

Please sign in to comment.