Skip to content

Commit d0f57fd

Browse files
committed
Add inv check
1 parent 1d0bb4a commit d0f57fd

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tasks.py

+41
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
import subprocess
44
from pathlib import Path
55
from invoke import run, task
6+
import json
7+
import re
68

79
from blueprint.tasks import web, bp, print_bp, serve
810

911
ROOT = Path(__file__).parent
1012
BP_DIR = ROOT/'blueprint'
13+
PROJ = 'PFR'
1114

1215
@task(bp, web)
1316
def all(ctx):
@@ -48,3 +51,41 @@ def callback(changes):
4851
'.*\.synctex.*$',
4952
)
5053
))
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

Comments
 (0)