(pat: str)
| 177 | pass |
| 178 | |
| 179 | def to_predicate(pat: str): |
| 180 | pattern = pat.lstrip("/").strip() |
| 181 | if not pattern: |
| 182 | return lambda _p: False |
| 183 | |
| 184 | # Directory match (e.g. foo/). If pattern includes a slash, treat as anchored path prefix. |
| 185 | if pattern.endswith("/"): |
| 186 | directory = pattern[:-1].lstrip("/") |
| 187 | |
| 188 | def _dir(path: str) -> bool: |
| 189 | n = (path or "").lstrip("/") |
| 190 | if not directory: |
| 191 | return False |
| 192 | if "/" in directory: |
| 193 | # anchored subpath: match exact or prefix (e.g., "frontend/node_modules/") |
| 194 | return n == directory or n.startswith(directory + "/") |
| 195 | # segment match anywhere (e.g., any "node_modules" segment in the path) |
| 196 | parts = n.split("/") if n else [] |
| 197 | return directory in parts |
| 198 | |
| 199 | return _dir |
| 200 | |
| 201 | # Exact basename match |
| 202 | if ("*" not in pattern) and ("?" not in pattern): |
| 203 | |
| 204 | def _exact(path: str) -> bool: |
| 205 | n = (path or "").lstrip("/") |
| 206 | base = n.split("/")[-1] if n else n |
| 207 | return base == pattern |
| 208 | |
| 209 | return _exact |
| 210 | |
| 211 | # Basic glob on basename |
| 212 | import re |
| 213 | |
| 214 | regex_str = ( |
| 215 | "^" |
| 216 | + "".join( |
| 217 | (".*" if tok == "*" else "." if tok == "?" else re.escape(tok)) |
| 218 | for tok in [t for t in re.split(r"([*?])", pattern) if t != ""] |
| 219 | ) |
| 220 | + "$" |
| 221 | ) |
| 222 | compiled = re.compile(regex_str) |
| 223 | |
| 224 | def _glob(path: str) -> bool: |
| 225 | n = (path or "").lstrip("/") |
| 226 | base = n.split("/")[-1] if n else n |
| 227 | return bool(compiled.match(base)) |
| 228 | |
| 229 | return _glob |
| 230 | |
| 231 | predicates = [to_predicate(p) for p in patterns] |
| 232 |
no outgoing calls
no test coverage detected