Skip to content

Commit

Permalink
Addressing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
autophagy committed May 31, 2018
1 parent 9fa5d9c commit ab209ba
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
11 changes: 8 additions & 3 deletions black.py
Original file line number Diff line number Diff line change
Expand Up @@ -2792,17 +2792,22 @@ def gen_python_files_in_dir(
"""Generate all files under `path` whose paths are not excluded by the
`exclude` regex, but are included by the `include` regex.
"""

for child in path.iterdir():
searchable_path = str(child)
if Path(child.parts[0]).is_dir():
searchable_path = "/" + searchable_path
if child.is_dir():
if exclude.search(str(child) + "/"):
searchable_path = searchable_path + "/"
if exclude.search(searchable_path):
continue

yield from gen_python_files_in_dir(child, include, exclude)

elif (
child.is_file()
and include.search(str(child))
and not exclude.search(str(child))
and include.search(searchable_path)
and not exclude.search(searchable_path)
):
yield child

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions tests/test_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,11 +855,11 @@ def test_pipe_force_py36(self) -> None:
def test_include_exclude(self) -> None:
path = THIS_DIR / "include_exclude_tests"
include = re.compile(r"\.pyi?$")
exclude = re.compile(r"exclude/|\.definitely_exclude/")
exclude = re.compile(r"/exclude/|/\.definitely_exclude/")
sources: List[Path] = []
expected = [
Path(THIS_DIR / "include_exclude_tests/b/c/a.py"),
Path(THIS_DIR / "include_exclude_tests/b/c/a.pyi"),
Path(THIS_DIR / "include_exclude_tests/b/dont_exclude/a.py"),
Path(THIS_DIR / "include_exclude_tests/b/dont_exclude/a.pyi"),
]
sources.extend(black.gen_python_files_in_dir(path, include, exclude))
self.assertEqual(sorted(expected), sorted(sources))
Expand Down

0 comments on commit ab209ba

Please sign in to comment.