Skip to content

Gitignore parser

gitignore_parser

Gitignore parser configured to work for edk2-pytool-library.

IgnoreRule

Class representing a single rule parsed from a .ignore file.

__str__

__str__() -> str

String representation (user friendly) of the rule.

__repr__

__repr__() -> str

String representation (developer friendly) of the rule.

match

match(abs_path: str) -> bool

Returns True or False if the path matches the rule.

handle_negation

handle_negation(file_path: str, rules: list) -> bool

Allows matched value override if negation is true.

Otherwise matched cannot be overwritten with an exception. Used for ensuring rules with ! will override a previous true result back to false.

parse_gitignore_file

parse_gitignore_file(
    full_path: str, base_dir: Optional[str] = None
) -> Callable

Parse a gitignore file.

parse_gitignore_lines

parse_gitignore_lines(
    lines: list, full_path: str, base_dir: str
) -> Callable

Parse a list of lines matching gitignore syntax.

rule_from_pattern

rule_from_pattern(
    pattern: str,
    base_path: Optional[str] = None,
    source: Optional[str] = None,
) -> IgnoreRule

Generates an IgnoreRule object from a pattern.

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.

fnmatch_pathname_to_regex

fnmatch_pathname_to_regex(
    pattern: str,
    directory_only: bool,
    negation: bool,
    anchored: bool = False,
) -> str

Implements fnmatch style-behavior, as though with FNM_PATHNAME flagged.

WARNING: the path seperator will not match shell-style '*' and '.' wildcards.