This commit is contained in:
mike
2025-12-13 11:56:06 +01:00
commit 2b2c575385
57 changed files with 6505 additions and 0 deletions

3
app/filters/__init__.py Normal file
View File

@@ -0,0 +1,3 @@
from .gitignore import GitignoreFilter, DEFAULT_PATTERNS
__all__ = ['GitignoreFilter', 'DEFAULT_PATTERNS']

30
app/filters/gitignore.py Normal file
View File

@@ -0,0 +1,30 @@
from pathlib import Path
from typing import Set
import fnmatch
DEFAULT_PATTERNS = {
'node_modules/**', '__pycache__/**', '.git/**', 'build/**', 'dist/**',
'.cache/**', 'target/**', 'vendor/**', '.venv/**', 'venv/**',
'*.pyc', '*.pyo', '*.so', '*.dll', '*.dylib', '*.o', '*.a',
'.DS_Store', 'Thumbs.db', '.pytest_cache/**', '.tox/**',
'*.egg-info/**', '.mypy_cache/**', '.coverage', 'htmlcov/**',
'.gradle/**', 'bin/**', 'obj/**', '.vs/**', '.idea/**'
}
class GitignoreFilter:
def __init__(self, patterns: Set[str] = None):
self.patterns = patterns or DEFAULT_PATTERNS
def should_exclude(self, path: str) -> bool:
path_obj = Path(path)
for pattern in self.patterns:
if '**' in pattern:
clean_pattern = pattern.replace('/**', '').replace('**/', '')
if clean_pattern in path_obj.parts:
return True
elif fnmatch.fnmatch(path, pattern) or fnmatch.fnmatch(path_obj.name, pattern):
return True
return False
def filter_files(self, files: list) -> list:
return [f for f in files if not self.should_exclude(f)]