Skip to content

Commit

Permalink
Improve extract performance via ignoring directory early during os.walk
Browse files Browse the repository at this point in the history
  • Loading branch information
stkao05 committed Feb 11, 2020
1 parent 0cfa69e commit 6ada6ee
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions babel/messages/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,22 @@ def extract_from_dir(dirname=None, method_map=DEFAULT_MAPPING,
options_map = {}

absname = os.path.abspath(dirname)

def dir_filter(method_map, dirname):
if dirname.startswith('.') or dirname.startswith('_'):
return False

absdir = os.path.join(root, dirname).replace(os.sep, '/')
for pattern, method in method_map:
if method == "ignore" and pathmatch(pattern, absdir):
return False

return True


for root, dirnames, filenames in os.walk(absname):
dirnames[:] = [
subdir for subdir in dirnames
if not (subdir.startswith('.') or subdir.startswith('_'))
]
dirnames[:] = [subdir for subdir in dirnames if dir_filter(method_map, subdir)]

dirnames.sort()
filenames.sort()
for filename in filenames:
Expand Down

0 comments on commit 6ada6ee

Please sign in to comment.