Add diff and utils modules
Some checks failed
CI / test (3.10) (push) Failing after 14s
CI / test (3.11) (push) Failing after 17s
CI / test (3.12) (push) Failing after 17s
CI / build (push) Has been cancelled
CI / lint (push) Has been cancelled

This commit is contained in:
2026-02-02 17:22:53 +00:00
parent e97d7ea518
commit f5e453235a

View File

@@ -0,0 +1,55 @@
"""Path utilities."""
import os
from pathlib import Path
from typing import List
try:
import pathspec
PATHSPEC_AVAILABLE = True
except ImportError:
PATHSPEC_AVAILABLE = False
def glob_patterns(patterns: List[str], base_path: Path) -> List[Path]:
"""Find files matching glob patterns."""
if not PATHSPEC_AVAILABLE:
return _glob_patterns_fallback(patterns, base_path)
spec = pathspec.PathSpec.from_lines("gitwildmatch", patterns)
matched = []
for root, _dirs, files in os.walk(base_path):
root_path = Path(root)
for filename in files:
file_path = root_path / filename
relative_path = file_path.relative_to(base_path)
if spec.match_file(str(relative_path)):
matched.append(file_path)
return matched
def _glob_patterns_fallback(patterns: List[str], base_path: Path) -> List[Path]:
"""Fallback glob implementation using Path.glob."""
matched = []
for pattern in patterns:
matched.extend(base_path.rglob(pattern))
return sorted(set(matched))
def is_ignored(path: Path, ignore_patterns: List[str]) -> bool:
"""Check if a path should be ignored."""
if not PATHSPEC_AVAILABLE:
for pattern in ignore_patterns:
if path.match(pattern):
return True
return False
spec = pathspec.PathSpec.from_lines("gitwildmatch", ignore_patterns)
return spec.match_file(str(path))