Skip to content

Commit 983eccc

Browse files
chore(types): prune unused bundled generated modules
The generated_poc/bundled tree is built from self-contained inlined JSON schemas, so each bundled message re-emits its own copy of the shared provenance/verification/asset sub-schemas. That accounts for ~92% of the generated tree (~27.8k of ~30k class definitions), yet only one bundled module is imported anywhere: protocol/get_adcp_capabilities_response (via adcp.types.capabilities). consolidate_exports.py already excludes bundled from the public namespace, and the tree is not loaded at import adcp. Remove the 95 unreferenced bundled modules and add a post-generation prune step to generate_types.py so regeneration does not recreate them. Generation runs unchanged; the step only deletes unreferenced output, leaving every retained module byte-identical. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 7c81056 commit 983eccc

96 files changed

Lines changed: 52 additions & 625024 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

scripts/generate_types.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ def _load_resolve_bundle_key():
4747
TEMP_DIR = REPO_ROOT / ".schema_temp"
4848
DELTAS_FILE = REPO_ROOT / "SCHEMA_DELTAS.md"
4949

50+
# Bundled schemas are self-contained: each message schema inlines its entire
51+
# ``$ref`` graph, so every bundled module re-emits its own copy of the shared
52+
# provenance/verification/asset sub-schemas. The generator can't merge those
53+
# copies across files, so the bundled tree accounts for the overwhelming
54+
# majority of generated classes. ``consolidate_exports.py`` already excludes
55+
# bundled modules from the public namespace; the only one any source module
56+
# imports is ``get_adcp_capabilities_response`` (via
57+
# ``adcp.types.capabilities``), whose typed sub-models exist *only* in the
58+
# inlined bundled form. Keep that module (and the package ``__init__`` files on
59+
# its import path) and drop the rest after generation.
60+
BUNDLED_DIR_NAME = "bundled"
61+
BUNDLED_KEEP = {
62+
Path("__init__.py"),
63+
Path("protocol/__init__.py"),
64+
Path("protocol/get_adcp_capabilities_response.py"),
65+
}
66+
5067

5168
def rewrite_refs(obj, current_schema_rel_path: Path):
5269
"""
@@ -495,6 +512,38 @@ def restore_unchanged_files():
495512
print(" No timestamp-only changes found")
496513

497514

515+
def prune_unused_bundled_modules():
516+
"""Drop generated bundled modules no source module imports.
517+
518+
See ``BUNDLED_KEEP`` for why the bundled tree is almost entirely dead
519+
weight. Removing it here keeps the committed tree small without changing
520+
the content of any retained module — generation runs unchanged and this
521+
only deletes the unreferenced output afterwards.
522+
"""
523+
bundled_dir = OUTPUT_DIR / BUNDLED_DIR_NAME
524+
if not bundled_dir.exists():
525+
return
526+
527+
print("Pruning unused bundled modules...")
528+
removed = 0
529+
for py_file in bundled_dir.rglob("*.py"):
530+
if py_file.relative_to(bundled_dir) in BUNDLED_KEEP:
531+
continue
532+
py_file.unlink()
533+
removed += 1
534+
535+
# Drop now-empty package directories (deepest first).
536+
for directory in sorted(
537+
(d for d in bundled_dir.rglob("*") if d.is_dir()),
538+
key=lambda d: len(d.parts),
539+
reverse=True,
540+
):
541+
if not any(directory.iterdir()):
542+
directory.rmdir()
543+
544+
print(f" ✓ Removed {removed} unused bundled module(s)\n")
545+
546+
498547
def apply_post_generation_fixes():
499548
"""Apply post-generation fixes using the dedicated script."""
500549
print("Running post-generation fixes...")
@@ -561,6 +610,9 @@ def main():
561610
if not apply_post_generation_fixes():
562611
return 1
563612

613+
# Drop unreferenced bundled modules before consolidation
614+
prune_unused_bundled_modules()
615+
564616
# Consolidate exports into generated.py
565617
consolidate_script = REPO_ROOT / "scripts" / "consolidate_exports.py"
566618
result = subprocess.run(

src/adcp/types/generated_poc/bundled/content_standards/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)