okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
269f33859
main
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 ): 25return os .path .relpath (path ,ROOT ).replace (os .sep ,"/" ) 26 27 28def is_archived (relpath ): 29return any (relpath .startswith (p )for p in ARCHIVE_PREFIXES ) 30 31 32def _skipped (relpath ): 33parts = relpath .split ("/" ) 34return 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. 39Ignored build trees (for example a llama.cpp copy under build-*/_deps) are therefore never scanned.""" 40try : 41r = subprocess .run (["git" ,"-C" ,root ,"ls-files" ,"-z" ,"-co" ,"--exclude-standard" ,"--" ,"*.md" ], 42capture_output = True ,text = True ,encoding = "utf-8" ,timeout = 120 ) 43except (OSError ,subprocess .SubprocessError ): 44return None 45if r .returncode != 0 : 46return None 47return [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.""" 52root = root or ROOT 53listed = _git_markdown (root ) 54if listed is not None : 55return sorted ((r ,is_archived (r ))for r in listed if not _skipped (r )) 56out = [] 57for base ,dirs ,files in os .walk (root ): 58dirs [:]= [d for d in dirs if d not in SKIP_DIRS and not (d .startswith ("wt-" )and base == root )] 59for name in files : 60if name .endswith (".md" ): 61r = os .path .relpath (os .path .join (base ,name ),root ).replace (os .sep ,"/" ) 62out .append ((r ,is_archived (r ))) 63return sorted (out ) 64 65 66def current_pages (root = None ): 67return [r for r ,archived in markdown_files (root )if not archived ]