okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221fused_gr: the dynamic-shared-memory opt-in of the single-token down kernel is set once per device, not once per process (a layer split runs it on several cards); doc_pages lists the .md files git knows about, so an ignored build tree's llama.cpp copy is not link-checked269f33859

main
2.7 KiB67 linesraw
1"""Which Markdown files are current pages and which are archived history.
2
3One list, used by the release check (tools/release_manifest.py) and the link check (tools/check_links.py), so the two
4agree about what "current" means.  Standard library only.
5"""
6import os
7import subprocess
8
9ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
10
11# Folders that are never scanned: dependencies, build output, version control, other people's code.
12SKIP_DIRS = {".git", "node_modules", "third_party", "dist", "target", "build", "__pycache__", ".venv", "venv"}
13
14# Archived material: dated reports, finished campaigns, release notes, measurement logs.  They keep the versions and
15# the links they had when they were written.  (Folders end in "/"; "docs/release-notes-" is a file-name prefix.)
16ARCHIVE_PREFIXES = (
17    "history/",
18    "bench/results/",
19    "phaseA-tests/",
20    "docs/release-notes-",
21)
22
23
24def rel(path):
25    return os.path.relpath(path, ROOT).replace(os.sep, "/")
26
27
28def is_archived(relpath):
29    return any(relpath.startswith(p) for p in ARCHIVE_PREFIXES)
30
31
32def _skipped(relpath):
33    parts = relpath.split("/")
34    return any(p in SKIP_DIRS for p in parts[:-1]) or (len(parts) > 1 and parts[0].startswith("wt-"))
35
36
37def _git_markdown(root):
38    """The .md files git knows about (tracked, plus untracked files that are not ignored), or None outside a git tree.
39    Ignored build trees (for example a llama.cpp copy under build-*/_deps) are therefore never scanned."""
40    try:
41        r = subprocess.run(["git", "-C", root, "ls-files", "-z", "-co", "--exclude-standard", "--", "*.md"],
42                           capture_output=True, text=True, encoding="utf-8", timeout=120)
43    except (OSError, subprocess.SubprocessError):
44        return None
45    if r.returncode != 0:
46        return None
47    return [p for p in r.stdout.split("\0") if p and os.path.isfile(os.path.join(root, p))]
48
49
50def markdown_files(root=None):
51    """Every .md file under the repository as (relative path, archived?), sorted."""
52    root = root or ROOT
53    listed = _git_markdown(root)
54    if listed is not None:
55        return sorted((r, is_archived(r)) for r in listed if not _skipped(r))
56    out = []
57    for base, dirs, files in os.walk(root):
58        dirs[:] = [d for d in dirs if d not in SKIP_DIRS and not (d.startswith("wt-") and base == root)]
59        for name in files:
60            if name.endswith(".md"):
61                r = os.path.relpath(os.path.join(base, name), root).replace(os.sep, "/")
62                out.append((r, is_archived(r)))
63    return sorted(out)
64
65
66def current_pages(root=None):
67    return [r for r, archived in markdown_files(root) if not archived]