Commit 8f24f84
fer
refactor: split metrics.py into modular architecture (Phase 1, Task 4)
Intent: Improve maintainability by dividing large 2,146-line metrics module
Operators involved: Code organization (no runtime operators affected)
Affected invariants: #10 (Domain Neutrality - modular organization)
Key changes:
- Split src/tnfr/operators/metrics.py (2,146 lines) into 5 modules:
* metrics_core.py: Shared utilities and helpers (89 lines)
* metrics_basic.py: emission, reception, coherence, dissonance (500 lines)
* metrics_network.py: coupling, resonance, silence + 4 helpers (693 lines)
* metrics_structural.py: expansion, contraction, self_organization,
mutation, transition, recursivity + helper (1,089 lines)
* metrics.py: Facade for backward compatibility (61 lines)
- Created scripts/split_metrics.py for automated refactoring
- Preserved all public APIs (100% backward compatible)
- Exported private helpers (_compute_*, _detect_*) for test compatibility
Module organization:
- Core: get_node_attr() + alias system + constants
- Basic: Single-node structural operators (4 functions)
- Network: Multi-node coupling/propagation operators (3 functions + 4 helpers)
- Structural: Complex transformation operators (6 functions + 1 helper)
- Facade: Re-exports all + U6 experimental telemetry
Testing validation:
- test_operator_enhancements.py: 23/23 passed ✅
- test_sha_extended_metrics.py: 33/33 passed ✅
- test_thol_metrics.py: Passed ✅
- test_nul_densification.py: Passed ✅
- test_mutation_metrics_comprehensive.py: Passed ✅
- Total: 99+ tests verified
Benefits:
- Improved navigation: Find operator metrics by category
- Reduced cognitive load: ~400-700 lines per module vs 2,146
- Better testability: Can test modules independently
- Clearer dependencies: Explicit imports between modules
- Maintainability: Changes isolated to relevant module
Expected risks/dissonances: None - all tests passing, APIs preserved
Metrics before/after:
- Src files: 255 → 259 (+4 new modules, 1 facade)
- Test files: 492 (unchanged)
- Health: 100/100 → 100/100 (maintained) ✅
- Imports: All backward compatible
- Line distribution: 2,146 → 89+500+693+1,089+61 = 2,432 total
(includes docstrings, __all__, imports in each module)
Backup files:
- metrics.py.backup: Pre-split copy
- metrics.py.old: Renamed original after split
TNFR Canonicity: Strengthens Invariant #10 (modular organization)
without changing structural behavior.
Task completion: Phase 1, Task 4 (4h, medium risk) ✅1 parent 0f5918f commit 8f24f84
File tree
6 files changed
+2577
-2121
lines changed- scripts
- src/tnfr/operators
6 files changed
+2577
-2121
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
0 commit comments