GitHub

API reference for glob.

Glob patterns matched against /-separated paths (Effect's Glob)::

from pyfect import glob

ts = glob.make("src/**/*.ts")
glob.match(ts, "src/a/b.ts")      # True
ts.match("src/.hidden/b.ts")      # False: wildcards skip dot names
glob.make("*", dot=True).match(".env")   # True

Syntax: * and ? within a segment, ** across segments (dir/** includes dir), bracket classes ([a-z], [!a], [[:digit:]]), braces ({a,b}, nested; more than 10,000 expansions leave the braces literal) and \ escapes. A trailing / matches only directories. Wildcards skip names that start with . unless the pattern segment starts with . or dot is set. Matching is case-sensitive and never backtracks exponentially. FileSystem.glob walks a directory tree with the same patterns.

Classes

Functions

make

make(pattern, *, dot=False) -> Glob

Compile pattern; with dot, wildcards and ** also match names that start with ..

ParameterTypeDescription
patternstr
dotbool = False

Returns Glob

def make(pattern: str, *, dot: bool = False) -> Glob:
    """Compile ``pattern``; with ``dot``, wildcards and ``**`` also match
    names that start with ``.``."""
    return Glob(pattern, dot=dot)

match

match(self, path) -> bool

Whether path matches the glob (also glob.match(path)).

ParameterTypeDescription
selfGlob
pathstr

Returns bool

def match(self: Glob, path: str) -> bool:
    """Whether ``path`` matches the glob (also ``glob.match(path)``)."""
    return self.match(path)

escape

escape(text) -> str

text with every glob special character escaped, so it matches only itself.

ParameterTypeDescription
textstr

Returns str

def escape(text: str) -> str:
    """``text`` with every glob special character escaped, so it matches
    only itself."""
    return _SPECIAL.sub(lambda m: "\\" + m.group(0), text)