Commit d71ace55 authored by Robert Bradshaw's avatar Robert Bradshaw

Extended glob that handles ** for arbitrary directory nesting.

parent 595fd56e
from glob import glob
from glob import iglob
import re, os, sys
......@@ -33,6 +33,24 @@ def cached_method(f):
return res
return wrapper
def extended_iglob(pattern):
if '**/' in pattern:
seen = set()
first, rest = pattern.split('**/', 1)
if first == '':
first = '.'
for root in iglob(first + "/"):
for path in extended_iglob(os.path.join(root, rest)):
if path not in seen:
seen.add(path)
yield path
for path in extended_iglob(os.path.join(root, '*', '**', rest)):
if path not in seen:
seen.add(path)
yield path
else:
for path in iglob(pattern):
yield path
def parse_list(s):
"""
......@@ -411,7 +429,7 @@ def create_extension_list(patterns, exclude=[], ctx=None, aliases=None):
if not isinstance(exclude, list):
exclude = [exclude]
for pattern in exclude:
to_exclude.update(glob(pattern))
to_exclude.update(extended_iglob(pattern))
if not isinstance(patterns, list):
patterns = [patterns]
module_list = []
......@@ -434,7 +452,7 @@ def create_extension_list(patterns, exclude=[], ctx=None, aliases=None):
exn_type = template.__class__
else:
raise TypeError(pattern)
for file in glob(filepattern):
for file in extended_iglob(filepattern):
if file in to_exclude:
continue
pkg = deps.package(file)
......
PYTHON setup.py build_ext --inplace
PYTHON -c "import runner"
######## setup.py ########
from Cython.Build.Dependencies import cythonize
from distutils.core import setup
setup(
ext_modules = cythonize("**/a*.pyx", include_path=['subdir'], compiler_directives={'cdivision': True}),
)
######## a.pyx ########
######## p1/__init__.py ########
######## p1/a.pyx ########
######## p1/ab.pyx ########
######## p1/b.pyx ########
######## p1/p2/__init__.py ########
######## p1/p2/a.pyx ########
######## runner.py ########
import a
import p1.a
import p1.ab
import p1.p2.a
try:
import p1.b
assert False, "b should not be complied"
except ImportError:
pass
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment