-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A new module has been created, radon.tools. There will go other CLI helpers. `iter_filenames` is now faster thanks to pathfinder, and excluding is more flexible. It can be improved upon in the future.
- Loading branch information
Showing
7 changed files
with
75 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import os | ||
import operator | ||
import itertools | ||
from functools import reduce | ||
from pathfinder import find_paths, FnmatchFilter, NotFilter, FileFilter | ||
|
||
|
||
def iter_filenames(paths, exclude=None): | ||
finder = lambda path: build_finder(path, build_filter(exclude)) | ||
return itertools.chain(*map(finder, paths)) | ||
|
||
|
||
def build_finder(path, filter): | ||
if os.path.isfile(path): | ||
return (path,) | ||
return find_paths(path, filter=filter) | ||
|
||
|
||
def build_filter(exclude=None): | ||
excluded = [FnmatchFilter(e) for e in (exclude or '').split(',') if e] | ||
f = FileFilter() & FnmatchFilter('*.py') | ||
if excluded: | ||
f &= NotFilter( | ||
reduce(operator.or_, excluded[1:], excluded[0]) | ||
) | ||
return f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters