Factor ignore logic into a predicate builder.
This commit is contained in:
parent
06d6b0b205
commit
67db8ddca8
@ -291,6 +291,37 @@ def foo(self, **kwargs):
|
|||||||
% (next(kwargs.iterkeys()), fun.__name__))
|
% (next(kwargs.iterkeys()), fun.__name__))
|
||||||
|
|
||||||
|
|
||||||
|
def match_predicate(*args):
|
||||||
|
"""Utility function for making string matching predicates.
|
||||||
|
|
||||||
|
Each arg can be a:
|
||||||
|
- regex
|
||||||
|
- list or tuple of regexes
|
||||||
|
- predicate that takes a string.
|
||||||
|
|
||||||
|
This returns a predicate that is true if:
|
||||||
|
- any arg regex matches
|
||||||
|
- any regex in a list or tuple of regexes matches.
|
||||||
|
- any predicate in args matches.
|
||||||
|
"""
|
||||||
|
def match(string):
|
||||||
|
for arg in args:
|
||||||
|
if isinstance(arg, basestring):
|
||||||
|
if re.search(arg, string):
|
||||||
|
return True
|
||||||
|
elif isinstance(arg, list) or isinstance(arg, tuple):
|
||||||
|
if any(re.search(i, string) for i in arg):
|
||||||
|
return True
|
||||||
|
elif callable(arg):
|
||||||
|
if arg(string):
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
raise ValueError("args to match_predicate must be regex, "
|
||||||
|
"list of regexes, or callable.")
|
||||||
|
return False
|
||||||
|
return match
|
||||||
|
|
||||||
|
|
||||||
class RequiredAttributeError(ValueError):
|
class RequiredAttributeError(ValueError):
|
||||||
def __init__(self, message):
|
def __init__(self, message):
|
||||||
super(RequiredAttributeError, self).__init__(message)
|
super(RequiredAttributeError, self).__init__(message)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
|
from llnl.util.lang import match_predicate
|
||||||
|
|
||||||
from spack import *
|
from spack import *
|
||||||
import spack
|
import spack
|
||||||
@ -85,9 +86,8 @@ def setup_dependent_environment(self, module, spec, ext_spec):
|
|||||||
|
|
||||||
def python_ignore(self, ext_pkg, args):
|
def python_ignore(self, ext_pkg, args):
|
||||||
"""Add some ignore files to activate/deactivate args."""
|
"""Add some ignore files to activate/deactivate args."""
|
||||||
orig_ignore = args.get('ignore', lambda f: False)
|
ignore_arg = args.get('ignore', lambda f: False)
|
||||||
|
|
||||||
def ignore(filename):
|
|
||||||
# Always ignore easy-install.pth, as it needs to be merged.
|
# Always ignore easy-install.pth, as it needs to be merged.
|
||||||
patterns = [r'easy-install\.pth$']
|
patterns = [r'easy-install\.pth$']
|
||||||
|
|
||||||
@ -98,10 +98,7 @@ def ignore(filename):
|
|||||||
patterns.append(r'bin/easy_install[^/]*$')
|
patterns.append(r'bin/easy_install[^/]*$')
|
||||||
patterns.append(r'setuptools.*egg$')
|
patterns.append(r'setuptools.*egg$')
|
||||||
|
|
||||||
return (any(re.search(p, filename) for p in patterns) or
|
return match_predicate(ignore_arg, patterns)
|
||||||
orig_ignore(filename))
|
|
||||||
|
|
||||||
return ignore
|
|
||||||
|
|
||||||
|
|
||||||
def write_easy_install_pth(self, exts):
|
def write_easy_install_pth(self, exts):
|
||||||
|
Loading…
Reference in New Issue
Block a user