26 lines
894 B
Python
26 lines
894 B
Python
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from pathlib import Path
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class RepositoryScan:
|
|
root: Path
|
|
readmes: list[Path]
|
|
docs: list[Path]
|
|
source_files: list[Path]
|
|
tests: list[Path]
|
|
|
|
|
|
class RepositoryScanner:
|
|
def scan(self, root: Path) -> RepositoryScan:
|
|
safe_root = root.resolve()
|
|
files = [path for path in safe_root.rglob("*") if path.is_file() and ".git" not in path.parts]
|
|
return RepositoryScan(
|
|
root=safe_root,
|
|
readmes=[path for path in files if path.name.lower().startswith("readme")],
|
|
docs=[path for path in files if "docs" in path.parts],
|
|
source_files=[path for path in files if path.suffix in {".py", ".js", ".ts", ".tsx"}],
|
|
tests=[path for path in files if path.name.startswith("test_") or "tests" in path.parts],
|
|
)
|