Skip to content

Commit e593d2e

Browse files
committed
One-off prune of unused categories from existing version manifests
1 parent 206e0ed commit e593d2e

15 files changed

Lines changed: 95 additions & 577 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env python3
2+
"""
3+
One-off: prune unused categories from already-built version manifests.
4+
5+
The build now emits only the categories actually referenced by at least one
6+
notebook (see lib/notebooks.py:generate_version_manifest), but versions that
7+
were built before that change still carry the full 9-category list in their
8+
manifest. Running this script rewrites those manifests in place so we don't
9+
have to wait for each version's `.build-ok` to invalidate via a real change.
10+
11+
Notebooks, outputs, and api.json are not touched.
12+
13+
Usage:
14+
python scripts/prune-manifest-categories.py # apply
15+
python scripts/prune-manifest-categories.py --dry-run # preview
16+
"""
17+
18+
from __future__ import annotations
19+
20+
import argparse
21+
import json
22+
import sys
23+
from pathlib import Path
24+
25+
26+
STATIC_DIR = Path(__file__).resolve().parent.parent / "static"
27+
28+
29+
def prune(manifest_path: Path, dry_run: bool) -> tuple[int, int]:
30+
"""Return (before, after) category count for this manifest."""
31+
with open(manifest_path, "r", encoding="utf-8") as f:
32+
manifest = json.load(f)
33+
34+
notebooks = manifest.get("notebooks", [])
35+
categories = manifest.get("categories", [])
36+
used_ids = {n["category"] for n in notebooks}
37+
pruned = [c for c in categories if c["id"] in used_ids]
38+
39+
before, after = len(categories), len(pruned)
40+
if before == after:
41+
return before, after
42+
43+
if not dry_run:
44+
manifest["categories"] = pruned
45+
with open(manifest_path, "w", encoding="utf-8") as f:
46+
json.dump(manifest, f, indent=2, ensure_ascii=False)
47+
f.write("\n")
48+
return before, after
49+
50+
51+
def main() -> int:
52+
parser = argparse.ArgumentParser(description=__doc__)
53+
parser.add_argument("--dry-run", action="store_true")
54+
args = parser.parse_args()
55+
56+
total_before = total_after = touched = 0
57+
for manifest_path in sorted(STATIC_DIR.glob("*/v*/manifest.json")):
58+
before, after = prune(manifest_path, args.dry_run)
59+
rel = manifest_path.relative_to(STATIC_DIR.parent)
60+
if before != after:
61+
touched += 1
62+
print(f" {rel}: {before}{after} categories")
63+
total_before += before
64+
total_after += after
65+
66+
action = "would prune" if args.dry_run else "pruned"
67+
print(f"\n{touched} manifest(s) {action}, total categories {total_before}{total_after}.")
68+
return 0
69+
70+
71+
if __name__ == "__main__":
72+
sys.exit(main())

static/batt/v0.1.0/manifest.json

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,5 @@
22
"package": "batt",
33
"tag": "v0.1.0",
44
"notebooks": [],
5-
"categories": [
6-
{
7-
"id": "getting-started",
8-
"title": "Getting Started",
9-
"order": 1
10-
},
11-
{
12-
"id": "control",
13-
"title": "Control Systems",
14-
"order": 2
15-
},
16-
{
17-
"id": "mechanics",
18-
"title": "Mechanics",
19-
"order": 3
20-
},
21-
{
22-
"id": "electronics",
23-
"title": "Electronics",
24-
"order": 4
25-
},
26-
{
27-
"id": "signal-processing",
28-
"title": "Signal Processing",
29-
"order": 5
30-
},
31-
{
32-
"id": "chemical",
33-
"title": "Chemical Engineering",
34-
"order": 6
35-
},
36-
{
37-
"id": "advanced",
38-
"title": "Advanced Topics",
39-
"order": 7
40-
},
41-
{
42-
"id": "rf-engineering",
43-
"title": "RF Engineering",
44-
"order": 8
45-
},
46-
{
47-
"id": "fmu",
48-
"title": "FMU Integration",
49-
"order": 9
50-
}
51-
]
52-
}
5+
"categories": []
6+
}

static/batt/v0.2.0/manifest.json

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -31,50 +31,10 @@
3131
}
3232
],
3333
"categories": [
34-
{
35-
"id": "getting-started",
36-
"title": "Getting Started",
37-
"order": 1
38-
},
39-
{
40-
"id": "control",
41-
"title": "Control Systems",
42-
"order": 2
43-
},
44-
{
45-
"id": "mechanics",
46-
"title": "Mechanics",
47-
"order": 3
48-
},
49-
{
50-
"id": "electronics",
51-
"title": "Electronics",
52-
"order": 4
53-
},
54-
{
55-
"id": "signal-processing",
56-
"title": "Signal Processing",
57-
"order": 5
58-
},
59-
{
60-
"id": "chemical",
61-
"title": "Chemical Engineering",
62-
"order": 6
63-
},
6434
{
6535
"id": "advanced",
6636
"title": "Advanced Topics",
6737
"order": 7
68-
},
69-
{
70-
"id": "rf-engineering",
71-
"title": "RF Engineering",
72-
"order": 8
73-
},
74-
{
75-
"id": "fmu",
76-
"title": "FMU Integration",
77-
"order": 9
7838
}
7939
]
80-
}
40+
}

static/chem/v0.1.0/manifest.json

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,5 @@
22
"package": "chem",
33
"tag": "v0.1.0",
44
"notebooks": [],
5-
"categories": [
6-
{
7-
"id": "getting-started",
8-
"title": "Getting Started",
9-
"order": 1
10-
},
11-
{
12-
"id": "control",
13-
"title": "Control Systems",
14-
"order": 2
15-
},
16-
{
17-
"id": "mechanics",
18-
"title": "Mechanics",
19-
"order": 3
20-
},
21-
{
22-
"id": "electronics",
23-
"title": "Electronics",
24-
"order": 4
25-
},
26-
{
27-
"id": "signal-processing",
28-
"title": "Signal Processing",
29-
"order": 5
30-
},
31-
{
32-
"id": "chemical",
33-
"title": "Chemical Engineering",
34-
"order": 6
35-
},
36-
{
37-
"id": "advanced",
38-
"title": "Advanced Topics",
39-
"order": 7
40-
},
41-
{
42-
"id": "fmu",
43-
"title": "FMU Integration",
44-
"order": 8
45-
}
46-
]
47-
}
5+
"categories": []
6+
}

static/chem/v0.2.0/manifest.json

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -40,50 +40,10 @@
4040
}
4141
],
4242
"categories": [
43-
{
44-
"id": "getting-started",
45-
"title": "Getting Started",
46-
"order": 1
47-
},
48-
{
49-
"id": "control",
50-
"title": "Control Systems",
51-
"order": 2
52-
},
53-
{
54-
"id": "mechanics",
55-
"title": "Mechanics",
56-
"order": 3
57-
},
58-
{
59-
"id": "electronics",
60-
"title": "Electronics",
61-
"order": 4
62-
},
63-
{
64-
"id": "signal-processing",
65-
"title": "Signal Processing",
66-
"order": 5
67-
},
6843
{
6944
"id": "chemical",
7045
"title": "Chemical Engineering",
7146
"order": 6
72-
},
73-
{
74-
"id": "advanced",
75-
"title": "Advanced Topics",
76-
"order": 7
77-
},
78-
{
79-
"id": "rf-engineering",
80-
"title": "RF Engineering",
81-
"order": 8
82-
},
83-
{
84-
"id": "fmu",
85-
"title": "FMU Integration",
86-
"order": 9
8747
}
8848
]
89-
}
49+
}

static/chem/v0.2.4/manifest.json

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -114,31 +114,6 @@
114114
}
115115
],
116116
"categories": [
117-
{
118-
"id": "getting-started",
119-
"title": "Getting Started",
120-
"order": 1
121-
},
122-
{
123-
"id": "control",
124-
"title": "Control Systems",
125-
"order": 2
126-
},
127-
{
128-
"id": "mechanics",
129-
"title": "Mechanics",
130-
"order": 3
131-
},
132-
{
133-
"id": "electronics",
134-
"title": "Electronics",
135-
"order": 4
136-
},
137-
{
138-
"id": "signal-processing",
139-
"title": "Signal Processing",
140-
"order": 5
141-
},
142117
{
143118
"id": "chemical",
144119
"title": "Chemical Engineering",
@@ -148,16 +123,6 @@
148123
"id": "advanced",
149124
"title": "Advanced Topics",
150125
"order": 7
151-
},
152-
{
153-
"id": "rf-engineering",
154-
"title": "RF Engineering",
155-
"order": 8
156-
},
157-
{
158-
"id": "fmu",
159-
"title": "FMU Integration",
160-
"order": 9
161126
}
162127
]
163-
}
128+
}

static/flight/v0.1.0/manifest.json

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,5 @@
22
"package": "flight",
33
"tag": "v0.1.0",
44
"notebooks": [],
5-
"categories": [
6-
{
7-
"id": "getting-started",
8-
"title": "Getting Started",
9-
"order": 1
10-
},
11-
{
12-
"id": "control",
13-
"title": "Control Systems",
14-
"order": 2
15-
},
16-
{
17-
"id": "mechanics",
18-
"title": "Mechanics",
19-
"order": 3
20-
},
21-
{
22-
"id": "electronics",
23-
"title": "Electronics",
24-
"order": 4
25-
},
26-
{
27-
"id": "signal-processing",
28-
"title": "Signal Processing",
29-
"order": 5
30-
},
31-
{
32-
"id": "chemical",
33-
"title": "Chemical Engineering",
34-
"order": 6
35-
},
36-
{
37-
"id": "advanced",
38-
"title": "Advanced Topics",
39-
"order": 7
40-
},
41-
{
42-
"id": "rf-engineering",
43-
"title": "RF Engineering",
44-
"order": 8
45-
},
46-
{
47-
"id": "fmu",
48-
"title": "FMU Integration",
49-
"order": 9
50-
}
51-
]
52-
}
5+
"categories": []
6+
}

0 commit comments

Comments
 (0)