-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle_89.py
More file actions
261 lines (247 loc) · 8.99 KB
/
bundle_89.py
File metadata and controls
261 lines (247 loc) · 8.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/usr/bin/env python3
import sys
from pathlib import Path
# ---- 89 files (relative to repo root) ----
FILES = [
"Cargo.toml",
"rust-toolchain.toml",
".cargo/config.toml",
"Makefile",
".gitignore",
".gitattributes",
".editorconfig",
".pre-commit-config.yaml",
"README.md",
"LICENSE",
"CONTRIBUTING.md",
"SECURITY.md",
"schemas/division_registry.schema.json",
"schemas/ballots.schema.json",
"schemas/ballot_tally.schema.json",
"schemas/parameter_set.schema.json",
"schemas/manifest.schema.json",
"schemas/result.schema.json",
"schemas/run_record.schema.json",
"schemas/frontier_map.schema.json",
"crates/vm_core/Cargo.toml",
"crates/vm_core/src/lib.rs",
"crates/vm_core/src/ids.rs",
"crates/vm_core/src/entities.rs",
"crates/vm_core/src/variables.rs",
"crates/vm_core/src/determinism.rs",
"crates/vm_core/src/rounding.rs",
"crates/vm_core/src/rng.rs",
"crates/vm_io/Cargo.toml",
"crates/vm_io/src/lib.rs",
"crates/vm_io/src/canonical_json.rs",
"crates/vm_io/src/manifest.rs",
"crates/vm_io/src/hasher.rs",
"crates/vm_io/src/loader.rs",
"crates/vm_algo/Cargo.toml",
"crates/vm_algo/src/lib.rs",
"crates/vm_algo/src/tabulation/plurality.rs",
"crates/vm_algo/src/tabulation/approval.rs",
"crates/vm_algo/src/tabulation/score.rs",
"crates/vm_algo/src/tabulation/ranked_irv.rs",
"crates/vm_algo/src/tabulation/ranked_condorcet.rs",
"crates/vm_algo/src/allocation/wta.rs",
"crates/vm_algo/src/allocation/dhondt.rs",
"crates/vm_algo/src/allocation/sainte_lague.rs",
"crates/vm_algo/src/allocation/largest_remainder.rs",
"crates/vm_algo/src/mmp.rs",
"crates/vm_algo/src/gates_frontier.rs",
"crates/vm_pipeline/Cargo.toml",
"crates/vm_pipeline/src/lib.rs",
"crates/vm_pipeline/src/load.rs",
"crates/vm_pipeline/src/validate.rs",
"crates/vm_pipeline/src/tabulate.rs",
"crates/vm_pipeline/src/allocate.rs",
"crates/vm_pipeline/src/aggregate.rs",
"crates/vm_pipeline/src/apply_rules.rs",
"crates/vm_pipeline/src/map_frontier.rs",
"crates/vm_pipeline/src/resolve_ties.rs",
"crates/vm_pipeline/src/label.rs",
"crates/vm_pipeline/src/build_result.rs",
"crates/vm_pipeline/src/build_run_record.rs",
"crates/vm_report/Cargo.toml",
"crates/vm_report/src/lib.rs",
"crates/vm_report/src/structure.rs",
"crates/vm_report/src/render_json.rs",
"crates/vm_report/src/render_html.rs",
"crates/vm_cli/Cargo.toml",
"crates/vm_cli/src/args.rs",
"crates/vm_cli/src/main.rs",
"fixtures/annex_b/part_0/parameter_set.json",
"fixtures/annex_b/part_0/division_registry.json",
"fixtures/annex_b/part_0/ballots.json",
"fixtures/annex_b/part_0/manifest.json",
"fixtures/annex_b/part_0/expected_result.json",
"tests/vm_tst_core.rs",
"tests/vm_tst_gates.rs",
"tests/vm_tst_ranked.rs",
"tests/vm_tst_mmp.rs",
"tests/determinism.rs",
"crates/vm_app/Cargo.toml",
"crates/vm_app/src-tauri/Cargo.toml",
"crates/vm_app/src-tauri/src/main.rs",
"crates/vm_app/src-tauri/tauri.conf.json",
"crates/vm_app/src-tauri/icons/icon.png",
"crates/vm_app/ui/package.json",
"crates/vm_app/ui/index.html",
"crates/vm_app/ui/vite.config.ts",
"crates/vm_app/ui/src/main.ts",
"crates/vm_app/ui/public/map/style.json",
"crates/vm_app/ui/public/map/tiles/world.mbtiles",
]
# ---- Selection policy (code only) ----
INCLUDE_FIXTURES = False # set True if you want fixtures/*.json included as "code"
ALLOWED_EXTS = {".rs", ".toml", ".ts", ".tsx", ".js", ".json", ".html", ".css", ".yml", ".yaml"}
ALLOWED_BASENAMES = {"Makefile"} # treated as code
EXCLUDE_BASENAMES = {"README.md", "LICENSE", "CONTRIBUTING.md", "SECURITY.md"}
EXCLUDE_PREFIXES_DEFAULT = [
"crates/vm_app/src-tauri/icons/", # images/icons
"crates/vm_app/ui/public/map/tiles/", # mbtiles/binaries
]
if not INCLUDE_FIXTURES:
EXCLUDE_PREFIXES_DEFAULT.append("fixtures/")
def skip_reason(rel: str) -> str | None:
p = Path(rel)
if p.name in EXCLUDE_BASENAMES:
return "docs"
for pref in EXCLUDE_PREFIXES_DEFAULT:
if rel.startswith(pref):
return "assets/binaries" if "tiles" in pref or "icons" in pref else "fixtures"
if (p.suffix.lower() not in ALLOWED_EXTS) and (p.name not in ALLOWED_BASENAMES):
return "non-code"
return None # keep
# ---- Bundling (max 10 bundles) ----
def group_for(path: str) -> str:
if path.startswith("schemas/"):
return "schemas"
if path.startswith("crates/vm_core/"):
return "vm_core"
if path.startswith("crates/vm_io/"):
return "vm_io"
if path.startswith("crates/vm_algo/"):
return "vm_algo"
if path.startswith("crates/vm_pipeline/"):
return "vm_pipeline"
if path.startswith("crates/vm_report/"):
return "vm_report"
if path.startswith("crates/vm_cli/"):
return "vm_cli"
if path.startswith("crates/vm_app/"):
return "vm_app"
if path.startswith("tests/"):
return "data_tests" # tests counted as code
return "root"
GROUP_ORDER = [
"root",
"schemas",
"vm_core",
"vm_io",
"vm_algo",
"vm_pipeline",
"vm_report",
"vm_cli",
"vm_app",
"data_tests",
]
def is_binary_file(p: Path) -> bool:
try:
with open(p, "rb") as f:
chunk = f.read(2048)
if b"\x00" in chunk:
return True
try:
chunk.decode("utf-8")
return False
except UnicodeDecodeError:
return True
except Exception:
return True
def main() -> int:
repo_root = Path(".").resolve()
out_dir = repo_root / "bundles"
out_dir.mkdir(parents=True, exist_ok=True)
# Partition into groups (only files that pass selection)
groups: dict[str, list[str]] = {name: [] for name in GROUP_ORDER}
skipped = 0
for rel in FILES:
why = skip_reason(rel)
if why is not None:
print(f"[SKIP:{why}] {rel}")
skipped += 1
continue
grp = group_for(rel)
groups.setdefault(grp, []).append(rel)
missing = 0
oks = 0
errors = 0
binaries = 0
print("\n== Validating and bundling (code only) ==\n")
for grp in GROUP_ORDER:
files = groups.get(grp, [])
if not files:
continue
out_path = out_dir / f"{grp}.txt"
with open(out_path, "w", encoding="utf-8", newline="\n") as out:
out.write(f"# bundle: {grp}\n")
for rel in files:
fpath = repo_root / rel
out.write("\n" + "-" * 80 + "\n")
out.write(f"FILE: {rel}\n")
out.write("-" * 80 + "\n")
if not fpath.exists():
print(f"[MISSING] {rel}")
out.write(f"[MISSING] {rel}\n")
missing += 1
continue
if is_binary_file(fpath):
# Shouldn't happen given selection, but guard anyway
size = fpath.stat().st_size
print(f"[BINARY] {rel} ({size} bytes) — skipped")
out.write(f"[BINARY SKIPPED] {rel} ({size} bytes)\n")
binaries += 1
continue
try:
text = fpath.read_text(encoding="utf-8")
print(f"[OK] {rel}")
out.write(text)
if not text.endswith("\n"):
out.write("\n")
oks += 1
except UnicodeDecodeError:
try:
raw = fpath.read_bytes()
text = raw.decode("latin-1", errors="replace")
print(f"[OK*] {rel} (latin-1 fallback)")
out.write(text)
if not text.endswith("\n"):
out.write("\n")
oks += 1
except Exception as e:
print(f"[ERROR] {rel} ({e})")
out.write("[UNREADABLE TEXT CONTENT]\n")
errors += 1
# Manifest
manifest = out_dir / "manifest.txt"
with open(manifest, "w", encoding="utf-8", newline="\n") as m:
total = 0
for grp in GROUP_ORDER:
files = groups.get(grp, [])
if not files:
continue
total += len(files)
m.write(f"{grp}: {len(files)} files\n")
for rel in files:
m.write(f" - {rel}\n")
m.write(f"\nTotal code files bundled: {total}\n")
m.write(f"OK: {oks} | SKIP: {skipped} | BINARY: {binaries} | MISSING: {missing} | ERRORS: {errors}\n")
print("\n== Summary ==")
print(f"OK: {oks} | SKIP: {skipped} | BINARY: {binaries} | MISSING: {missing} | ERRORS: {errors}")
print(f"Bundles written to: {out_dir}")
# Fail if anything missing or unreadable
return 1 if (missing > 0 or errors > 0) else 0
if __name__ == "__main__":
sys.exit(main())