from __future__ import annotations

from pathlib import PurePosixPath

from app.modules.rag.indexing.common.path_filter import should_skip_indexing_path


class PythonFileFilter:
    _EXCLUDE_PARTS = {"venv", ".venv", "__pycache__", "node_modules", ".git", "dist", "build"}

    def should_index(self, path: str) -> bool:
        if should_skip_indexing_path(path):
            return False
        candidate = PurePosixPath(path)
        if candidate.suffix.lower() != ".py":
            return False
        return not any(part in self._EXCLUDE_PARTS for part in candidate.parts)
