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") # TrueSyntax: * 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) -> GlobCompile pattern; with dot, wildcards and ** also match
names that start with ..
| Parameter | Type | Description |
|---|---|---|
pattern | str | |
dot | bool = 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) -> boolWhether path matches the glob (also glob.match(path)).
| Parameter | Type | Description |
|---|---|---|
self | Glob | |
path | str |
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) -> strtext with every glob special character escaped, so it matches
only itself.
| Parameter | Type | Description |
|---|---|---|
text | str |
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)