feat: add preset bool filter
This commit is contained in:
@@ -3,6 +3,18 @@ from pathlib import Path
|
||||
from .entry import Entry
|
||||
|
||||
|
||||
class EmptyEntry(Entry):
|
||||
def __init__(self):
|
||||
super().__init__({}, Path())
|
||||
|
||||
def __bool__(self):
|
||||
return False
|
||||
|
||||
|
||||
ENTRY_NONE = EmptyEntry()
|
||||
ENTRY_SKIP = EmptyEntry()
|
||||
|
||||
|
||||
class EntryDetector:
|
||||
def detect_entry(self, basepath: Path) -> Entry | None:
|
||||
def detect_entry(self, basepath: Path) -> Entry:
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -3,6 +3,7 @@ from typing import Iterable
|
||||
|
||||
from pathspec import PathSpec
|
||||
|
||||
from ..preset.detector import ENTRY_SKIP
|
||||
from .detector import EntryDetector
|
||||
from .entry import Entry
|
||||
|
||||
@@ -15,12 +16,16 @@ class EntryResolver:
|
||||
|
||||
def _resolve(self, basepath: Path, depth: int = 0) -> Iterable[Entry]:
|
||||
if basepath.is_dir():
|
||||
if self._ignore.match_file(basepath):
|
||||
if basepath.name.startswith(".") or self._ignore.match_file(basepath):
|
||||
return
|
||||
entry = self._detector.detect_entry(basepath)
|
||||
if entry:
|
||||
yield entry
|
||||
if depth < self._max_depth and basepath.is_dir():
|
||||
if (
|
||||
not entry == ENTRY_SKIP
|
||||
and depth < self._max_depth
|
||||
and basepath.is_dir()
|
||||
):
|
||||
for path in basepath.iterdir():
|
||||
yield from self._resolve(path, depth + 1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user