|
3 | 3 | import subprocess
|
4 | 4 | from pathlib import Path
|
5 | 5 | from invoke import run, task
|
| 6 | +import json |
| 7 | +import re |
6 | 8 |
|
7 | 9 | from blueprint.tasks import web, bp, print_bp, serve
|
8 | 10 |
|
9 | 11 | ROOT = Path(__file__).parent
|
10 | 12 | BP_DIR = ROOT/'blueprint'
|
| 13 | +PROJ = 'PFR' |
11 | 14 |
|
12 | 15 | @task(bp, web)
|
13 | 16 | def all(ctx):
|
@@ -48,3 +51,41 @@ def callback(changes):
|
48 | 51 | '.*\.synctex.*$',
|
49 | 52 | )
|
50 | 53 | ))
|
| 54 | + |
| 55 | +@task |
| 56 | +def check(ctx): |
| 57 | + """ |
| 58 | + Check for broken references in blueprint to Lean declarations |
| 59 | + """ |
| 60 | + |
| 61 | + broken_decls = [] |
| 62 | + |
| 63 | + DECLS_FILE = ROOT/'.lake/build/doc/declarations/declaration-data.bmp' |
| 64 | + if not DECLS_FILE.exists(): |
| 65 | + print('[ERROR] Declarations file not found. Please run `lake -Kenv=dev build %s:docs` first.' % PROJ) |
| 66 | + exit(1) |
| 67 | + |
| 68 | + DEP_GRAPH_FILE = BP_DIR/'web/dep_graph_document.html' |
| 69 | + if not DEP_GRAPH_FILE.exists(): |
| 70 | + print('[ERROR] Dependency graph file not found. Please run `inv all` (or only `inv web`) first.') |
| 71 | + exit(1) |
| 72 | + |
| 73 | + with open(DECLS_FILE) as f: |
| 74 | + lean_decls = json.load(f)['declarations'] |
| 75 | + |
| 76 | + with open(DEP_GRAPH_FILE) as f: |
| 77 | + lean_decl_regex = re.compile(r'lean_decl.*href=".*/find/#doc/([^"]+)"') |
| 78 | + for line in f: |
| 79 | + match = lean_decl_regex.search(line) |
| 80 | + if match and match.lastindex == 1: |
| 81 | + blueprint_decl = match[1] |
| 82 | + if blueprint_decl not in lean_decls: |
| 83 | + broken_decls.append(blueprint_decl) |
| 84 | + |
| 85 | + if broken_decls: |
| 86 | + print('[WARN] The following Lean declarations are referenced in the blueprint but not in Lean:\n') |
| 87 | + for decl in broken_decls: |
| 88 | + print(decl) |
| 89 | + exit(1) |
| 90 | + else: |
| 91 | + print('[OK] All Lean declarations referenced in the blueprint exist.') |
0 commit comments