wend.query¶
Queries: discovery plans that filter what a pattern finds (SEMANTICS.md ยง11).
A query starts from an expression or a union and adds filters::
src = P("src") / SubPath("rel") / T(t"{stem}.py")
tests = P("src") / SubPath("rel") / T(t"{stem}_test.py")
recent = (src - tests).where(File, modified_after(yesterday))
for m in recent.glob():
...
q - patterndrops paths thatpatternmatches;q & patternkeeps paths thatpatternalso matches, adding its bindings (a parameter both patterns bind must agree);q.where(*predicates)keeps paths for which every predicate holds. A predicate is a condition (File,Readable,Under(base)...), a filesystem test such asmodified_after, or any callable taking theMatch.
Nothing runs until glob (or match) is called, and results stream as they
are found. Filters are a conjunction: wend runs the pattern filters first,
then pure callables, then the predicates that touch the filesystem, which is
the cheapest order and gives the same results.
FsPredicate
¶
FsPredicate(description: str, test: Callable[[stat_result], bool])
Query
¶
Query(
source: Any,
drop: tuple[Any, ...] = (),
keep: tuple[Any, ...] = (),
where: tuple[Any, ...] = (),
)
A lazy discovery plan: a source pattern and filters (see the module).
glob
¶
glob(
mapping: Any = None,
/,
*,
ambiguous: Literal["raise", "skip"]
| Callable[[AmbiguousMatchError], object] = "raise",
**kw: Any,
) -> Iterator[Match]
Discover the source's paths and yield those every filter admits,
as they are found (see wend.glob for the options). Conditions are
checked on the filesystem the walk reads (fs=); a condition that
cannot be determined raises IndeterminateError.
ambiguous decides, as for wend.glob, what happens to a path
with more than one reading: one the source reads two ways, which the
source's glob reports before its first match, or one a &
pattern reads two ways, reported when the stream reaches it (as
wend.Lens.map reports). Neither is yielded.
modified_after
¶
modified_after(when: datetime | float) -> FsPredicate
The path was modified after when (a datetime or a POSIX timestamp).
modified_before
¶
modified_before(when: datetime | float) -> FsPredicate
The path was modified before when.