Load and cache .codeyignore patterns for a given cwd.
(cwd: str)
| 18 | _ignore_cache: dict = {} |
| 19 | |
| 20 | def _load_ignore_patterns(cwd: str) -> frozenset: |
| 21 | """Load and cache .codeyignore patterns for a given cwd.""" |
| 22 | ignore_file = Path(cwd) / ".codeyignore" |
| 23 | mtime = ignore_file.stat().st_mtime if ignore_file.exists() else None |
| 24 | cached = _ignore_cache.get(cwd) |
| 25 | if cached and cached[0] == mtime: |
| 26 | return cached[1] |
| 27 | patterns = set(_DEFAULT_IGNORE) |
| 28 | if ignore_file.exists(): |
| 29 | try: |
| 30 | for line in ignore_file.read_text().splitlines(): |
| 31 | line = line.strip() |
| 32 | if line and not line.startswith("#"): |
| 33 | patterns.add(line) |
| 34 | except Exception: |
| 35 | pass |
| 36 | result = frozenset(patterns) |
| 37 | _ignore_cache[cwd] = (mtime, result) |
| 38 | return result |
| 39 | |
| 40 | def is_ignored(path): |
| 41 | """Check if a file should be ignored based on .codeyignore or defaults.""" |
no test coverage detected