edk2toollib/gitignore_parser.py
def rule_from_pattern(pattern, base_path=None, source=None):
    """
    Take a .gitignore match pattern, such as "*.py[cod]" or "**/*.bak",
    and return an IgnoreRule suitable for matching against files and
    directories. Patterns which do not match files, such as comments
    and blank lines, will return None.
    Because git allows for nested .gitignore files, a base_path value
    is required for correct behavior. The base path should be absolute.
    """
    if base_path and base_path != abspath(base_path):
        raise ValueError('base_path must be absolute')
    # Store the exact pattern for our repr and string functions
    orig_pattern = pattern
    # Early returns follow
    # Discard comments and seperators
    if pattern.strip() == '' or pattern[0] == '#':
        return
    # Discard anything with more than two consecutive asterisks
    if pattern.find('***') > -1:
        return
    # Strip leading bang before examining double asterisks
    if pattern[0] == '!':
        negation = True
        pattern = pattern[1:]
    else:
        negation = False
    # Discard anything with invalid double-asterisks -- they can appear
    # at the start or the end, or be surrounded by slashes
    for m in re.finditer(r'\*\*', pattern):
        start_index = m.start()
        if (start_index != 0 and start_index != len(pattern) - 2
            and (pattern[start_index - 1] != '/' or pattern[start_index + 2] != '/')): # noqa
            return

    # Special-casing '/', which doesn't match any files or directories
    if pattern.rstrip() == '/':
        return

    directory_only = pattern[-1] == '/'
    # A slash is a sign that we're tied to the base_path of our rule
    # set.
    anchored = '/' in pattern[:-1]
    if pattern[0] == '/':
        pattern = pattern[1:]
    if pattern[0] == '*' and pattern[1] == '*':
        pattern = pattern[2:]
        anchored = False
    if pattern[0] == '/':
        pattern = pattern[1:]
    if pattern[-1] == '/':
        pattern = pattern[:-1]
    regex = fnmatch_pathname_to_regex(
        pattern
    )
    if anchored:
        regex = ''.join(['^', regex])
    return IgnoreRule(
        pattern=orig_pattern,
        regex=regex,
        negation=negation,
        directory_only=directory_only,
        anchored=anchored,
        base_path=Path(base_path) if base_path else None,
        source=source
    )

    Take a .gitignore match pattern, such as "*.py[cod]" or "**/*.bak",
    and return an IgnoreRule suitable for matching against files and
    directories. Patterns which do not match files, such as comments
    and blank lines, will return None.
    Because git allows for nested .gitignore files, a base_path value
    is required for correct behavior. The base path should be absolute.
    
Take a .gitignore match pattern, such as "*.py[cod]" or "**.bak",
and return an IgnoreRule suitable for matching against files and
directories. Patterns which do not match files, such as comments
and blank lines, will return None.
Because git allows for nested .gitignore files, a base_path value
is required for correct behavior. The base path should be absolute.
Take a . gitignore match pattern such as " * . py [ cod ] " or " ** . bak " and return an IgnoreRule suitable for matching against files and directories . Patterns which do not match files such as comments and blank lines will return None . Because git allows for nested . gitignore files a base_path value is required for correct behavior . The base path should be absolute .
def rule_from_pattern(pattern, base_path=None, source=None):
    if base_path and base_path != abspath(base_path):
        raise ValueError('base_path must be absolute')
    orig_pattern = pattern
    if pattern.strip() == '' or pattern[0] == '#':
        return
    if pattern.find('***') > -1:
        return
    if pattern[0] == '!':
        negation = True
        pattern = pattern[1:]
    else:
        negation = False
    for m in re.finditer(r'\*\*', pattern):
        start_index = m.start()
        if (start_index != 0 and start_index != len(pattern) - 2
            and (pattern[start_index - 1] != '/' or pattern[start_index + 2] != '/')): 
            return
    if pattern.rstrip() == '/':
        return
    directory_only = pattern[-1] == '/'
    anchored = '/' in pattern[:-1]
    if pattern[0] == '/':
        pattern = pattern[1:]
    if pattern[0] == '*' and pattern[1] == '*':
        pattern = pattern[2:]
        anchored = False
    if pattern[0] == '/':
        pattern = pattern[1:]
    if pattern[-1] == '/':
        pattern = pattern[:-1]
    regex = fnmatch_pathname_to_regex(
        pattern
    )
    if anchored:
        regex = ''.join(['^', regex])
    return IgnoreRule(
        pattern=orig_pattern,
        regex=regex,
        negation=negation,
        directory_only=directory_only,
        anchored=anchored,
        base_path=Path(base_path) if base_path else None,
        source=source
    )
def rule_from_pattern ( pattern , base_path = None , source = None ) : if base_path and base_path != abspath ( base_path ) : raise ValueError ( 'base_path must be absolute' ) orig_pattern = pattern if pattern . strip ( ) == '' or pattern [ 0 ] == '#' : return if pattern . find ( '***' ) > - 1 : return if pattern [ 0 ] == '!' : negation = True pattern = pattern [ 1 : ] else : negation = False for m in re . finditer ( r'\*\*' , pattern ) : start_index = m . start ( ) if ( start_index != 0 and start_index != len ( pattern ) - 2 and ( pattern [ start_index - 1 ] != '/' or pattern [ start_index + 2 ] != '/' ) ) : return if pattern . rstrip ( ) == '/' : return directory_only = pattern [ - 1 ] == '/' anchored = '/' in pattern [ : - 1 ] if pattern [ 0 ] == '/' : pattern = pattern [ 1 : ] if pattern [ 0 ] == '*' and pattern [ 1 ] == '*' : pattern = pattern [ 2 : ] anchored = False if pattern [ 0 ] == '/' : pattern = pattern [ 1 : ] if pattern [ - 1 ] == '/' : pattern = pattern [ : - 1 ] regex = fnmatch_pathname_to_regex ( pattern ) if anchored : regex = '' . join ( [ '^' , regex ] ) return IgnoreRule ( pattern = orig_pattern , regex = regex , negation = negation , directory_only = directory_only , anchored = anchored , base_path = Path ( base_path ) if base_path else None , source = source )
Take a .gitignore match pattern, such as "*.py[cod]" or "**/*.bak",
and return an IgnoreRule suitable for matching against files and
directories.
Take a . gitignore match pattern such as " * . py [ cod ] " or " ** / * . bak " and return an IgnoreRule suitable for matching against files and directories .
"""
    Take a .gitignore match pattern, such as "*.py[cod]" or "**/*.bak",
    and return an IgnoreRule suitable for matching against files and
    directories. Patterns which do not match files, such as comments
    and blank lines, will return None.
    Because git allows for nested .gitignore files, a base_path value
    is required for correct behavior. The base path should be absolute.
    """ # Store the exact pattern for our repr and string functions # Early returns follow # Discard comments and seperators # Discard anything with more than two consecutive asterisks # Strip leading bang before examining double asterisks # Discard anything with invalid double-asterisks -- they can appear # at the start or the end, or be surrounded by slashes # noqa # Special-casing '/', which doesn't match any files or directories # A slash is a sign that we're tied to the base_path of our rule # set.
pattern
base_path
source