Download stackgo/stackbuild/repo_filesystem.py from s0duku/the-stack-go: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/datasets/s0duku/the-stack-go/resolve/main/stackgo/stackbuild/repo_filesystem.py
- Command line
-
hf download hf://datasets/s0duku/the-stack-go/stackgo/stackbuild/repo_filesystem.py
-
curl -L -o repo_filesystem.py https://huggingface.co/datasets/s0duku/the-stack-go/resolve/main/stackgo/stackbuild/repo_filesystem.py
1.3 kB
| """Read-only adapter for scanning a repository checkout.""" | |
| from __future__ import annotations | |
| from pathlib import Path | |
| from .repo_model import Repo, RepoFile | |
| SKIP_DIRS = {".git", ".hg", ".svn", "node_modules", ".venv", "venv", "__pycache__"} | |
| def repo_from_path(root: str | Path, *, repo_id: str | None = None, | |
| revision_id: str = "working-tree", max_file_bytes: int = 2_000_000) -> Repo: | |
| root = Path(root).resolve() | |
| files: list[RepoFile] = [] | |
| for path in sorted(root.rglob("*")): | |
| if not path.is_file() or any(part in SKIP_DIRS for part in path.relative_to(root).parts): | |
| continue | |
| try: | |
| size = path.stat().st_size | |
| if size > max_file_bytes: | |
| continue | |
| content = path.read_bytes() | |
| except OSError: | |
| continue | |
| if b"\x00" in content[:8192]: | |
| continue | |
| relative = path.relative_to(root).as_posix() | |
| language = None | |
| try: | |
| from tree_sitter_language_pack import detect_language_from_path | |
| language = detect_language_from_path(relative) | |
| except Exception: | |
| pass | |
| files.append(RepoFile(relative, content, language=language)) | |
| return Repo(repo_id or root.name, revision_id, tuple(files)) | |