mirror of
https://github.com/openswarm-ai/openswarm.git
synced 2026-09-14 05:37:40 +02:00
23 lines
643 B
Python
23 lines
643 B
Python
"""Check infrastructure: shared filter/match utilities."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import fnmatch
|
|
from pathlib import Path
|
|
|
|
|
|
def _matches_any(text: str, patterns: list[str]) -> bool:
|
|
return any(fnmatch.fnmatch(text, p) for p in patterns)
|
|
|
|
|
|
def is_excluded(path: Path, root: Path, excludes: list[str]) -> bool:
|
|
rel = path.relative_to(root)
|
|
for part in rel.parts:
|
|
if _matches_any(part, excludes):
|
|
return True
|
|
return _matches_any(str(rel), excludes)
|
|
|
|
|
|
def is_excepted(rel_path: str, rule: str, exceptions: dict[str, list[str]]) -> bool:
|
|
return _matches_any(rel_path, exceptions.get(rule, []))
|