Permalink
Browse files

Use os.walk with fnmatch instead of glob

Python 2 doesn't support `glob` with `recursive` argument
  • Loading branch information...
hombit committed Oct 31, 2018
1 parent 0e7c7e4 commit eb27c4bbbcfb0d6f5b4476ee6563f4b256df6559
Showing with 9 additions and 6 deletions.
  1. +9 −6 bin/sci_py_test_style
@@ -1,5 +1,6 @@
#!/usr/bin/env python

import fnmatch
import glob
import os
from itertools import chain
@@ -24,12 +25,14 @@ def check_style(fpath):


def package_files(package_dir):
def path(ext):
return os.path.join(package_dir, '**/*'+ext)

fpaths = list(chain.from_iterable(
(glob.iglob(path(ext), recursive=True) for ext in EXTS)
))
# It would be better to use glob.iglob('**/*.py', recursive=True) but it
# isn't available before Python 3.5
def fpath_gen(ext):
for root, dirnames, filenames in os.walk(package_dir):
for filename in fnmatch.filter(filenames, '*'+ext):
yield os.path.join(root, filename)

fpaths = list(chain.from_iterable(fpath_gen(ext) for ext in EXTS))
setup_py = os.path.join(package_dir, '../setup.py')
fpaths.append(setup_py)
return fpaths

0 comments on commit eb27c4b

Please sign in to comment.