arrayprobe 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. arrayprobe/__init__.py +219 -0
  2. arrayprobe/__main__.py +19 -0
  3. arrayprobe/_v314_lazy.py +48 -0
  4. arrayprobe/ai_ready.py +212 -0
  5. arrayprobe/attributed_export.py +1333 -0
  6. arrayprobe/authordefaults.py +267 -0
  7. arrayprobe/cli.py +3510 -0
  8. arrayprobe/combine.py +12 -0
  9. arrayprobe/compare.py +950 -0
  10. arrayprobe/config.py +1239 -0
  11. arrayprobe/constants.py +12 -0
  12. arrayprobe/count_closure.py +204 -0
  13. arrayprobe/diagnostic_views.py +769 -0
  14. arrayprobe/diode_report.py +265 -0
  15. arrayprobe/driver/__init__.py +5 -0
  16. arrayprobe/driver/_load_record.py +331 -0
  17. arrayprobe/driver/preflight_inputs.py +250 -0
  18. arrayprobe/driver/reprocess.py +553 -0
  19. arrayprobe/driver/run_flight.py +8166 -0
  20. arrayprobe/driver/tas_from_probe_housekeeping.py +124 -0
  21. arrayprobe/dropsize.py +519 -0
  22. arrayprobe/friendly.py +206 -0
  23. arrayprobe/geometry/__init__.py +77 -0
  24. arrayprobe/geometry/min_rectangle.py +92 -0
  25. arrayprobe/intarr.py +12 -0
  26. arrayprobe/intarr_analysis.py +16 -0
  27. arrayprobe/intarr_plots.py +12 -0
  28. arrayprobe/inventory.py +129 -0
  29. arrayprobe/jit_kernels.py +344 -0
  30. arrayprobe/lwc.py +44 -0
  31. arrayprobe/masks.py +349 -0
  32. arrayprobe/matio.py +410 -0
  33. arrayprobe/matlab_compat.py +13 -0
  34. arrayprobe/ncio.py +26 -0
  35. arrayprobe/particle.py +55 -0
  36. arrayprobe/particle_perimeter.py +12 -0
  37. arrayprobe/products.py +78 -0
  38. arrayprobe/profiles.py +179 -0
  39. arrayprobe/provenance.py +21 -0
  40. arrayprobe/py.typed +11 -0
  41. arrayprobe/readers/__init__.py +9 -0
  42. arrayprobe/readers/dmt.py +603 -0
  43. arrayprobe/readers/mask_csv.py +12 -0
  44. arrayprobe/readers/pms.py +12 -0
  45. arrayprobe/readers/sea.py +433 -0
  46. arrayprobe/readers/tasinfo.py +12 -0
  47. arrayprobe/regimes.py +507 -0
  48. arrayprobe/render.py +728 -0
  49. arrayprobe/reproduce_report.py +149 -0
  50. arrayprobe/review_agreement.py +135 -0
  51. arrayprobe/review_sampling.py +327 -0
  52. arrayprobe/run_page.py +624 -0
  53. arrayprobe/sample_area.py +12 -0
  54. arrayprobe/selector.py +206 -0
  55. arrayprobe/sizing.py +151 -0
  56. arrayprobe/time_convert.py +12 -0
  57. arrayprobe/timing_closure.py +141 -0
  58. arrayprobe/tools/__init__.py +27 -0
  59. arrayprobe/tools/make_demo_flight.py +1089 -0
  60. arrayprobe/tools/make_tas_file.py +760 -0
  61. arrayprobe/tools/probe_comparison.py +569 -0
  62. arrayprobe/tools/synthetic_truth.py +698 -0
  63. arrayprobe/tools/tas_sources.py +705 -0
  64. arrayprobe/triage_context.py +488 -0
  65. arrayprobe/triage_server.py +5215 -0
  66. arrayprobe/tune/__init__.py +15 -0
  67. arrayprobe/tune/diodes.py +400 -0
  68. arrayprobe/tune/distributions.py +300 -0
  69. arrayprobe/tune/sample.py +243 -0
  70. arrayprobe/tune/score.py +230 -0
  71. arrayprobe/tune/settings.py +354 -0
  72. arrayprobe/validate_by_condition.py +208 -0
  73. arrayprobe/validation_report.py +166 -0
  74. arrayprobe-0.1.0.dist-info/METADATA +260 -0
  75. arrayprobe-0.1.0.dist-info/RECORD +189 -0
  76. arrayprobe-0.1.0.dist-info/WHEEL +5 -0
  77. arrayprobe-0.1.0.dist-info/entry_points.txt +2 -0
  78. arrayprobe-0.1.0.dist-info/licenses/LICENSE +31 -0
  79. arrayprobe-0.1.0.dist-info/licenses/LICENSES/BSD-3-Clause.txt +47 -0
  80. arrayprobe-0.1.0.dist-info/licenses/NOTICE.md +369 -0
  81. arrayprobe-0.1.0.dist-info/top_level.txt +4 -0
  82. arrayprobe_soda2/__init__.py +131 -0
  83. arrayprobe_soda2/angles.py +143 -0
  84. arrayprobe_soda2/aspect_ratio.py +541 -0
  85. arrayprobe_soda2/backfill.py +100 -0
  86. arrayprobe_soda2/binary_dof.py +181 -0
  87. arrayprobe_soda2/buildindex.py +113 -0
  88. arrayprobe_soda2/decompress_dmt.py +285 -0
  89. arrayprobe_soda2/enhancement_hooks.py +275 -0
  90. arrayprobe_soda2/export_ascii.py +732 -0
  91. arrayprobe_soda2/export_ncdf.py +683 -0
  92. arrayprobe_soda2/export_ncdf_raf.py +396 -0
  93. arrayprobe_soda2/fillholes.py +161 -0
  94. arrayprobe_soda2/find_radius.py +105 -0
  95. arrayprobe_soda2/findsize.py +407 -0
  96. arrayprobe_soda2/fit_poisson.py +170 -0
  97. arrayprobe_soda2/fix2dimage.py +63 -0
  98. arrayprobe_soda2/fixraking.py +162 -0
  99. arrayprobe_soda2/fixstuckbits.py +146 -0
  100. arrayprobe_soda2/hvps4_read_frame.py +121 -0
  101. arrayprobe_soda2/jit_kernels.py +152 -0
  102. arrayprobe_soda2/label_blobs.py +177 -0
  103. arrayprobe_soda2/min_circle_fast.py +320 -0
  104. arrayprobe_soda2/particlesort.py +703 -0
  105. arrayprobe_soda2/pbp_writer.py +558 -0
  106. arrayprobe_soda2/poisson_spot_correct.py +183 -0
  107. arrayprobe_soda2/princomp.py +107 -0
  108. arrayprobe_soda2/probespecs.py +361 -0
  109. arrayprobe_soda2/process_2d.py +1364 -0
  110. arrayprobe_soda2/process_2d_parallel.py +626 -0
  111. arrayprobe_soda2/process_hk.py +512 -0
  112. arrayprobe_soda2/processbuffer_2dc.py +155 -0
  113. arrayprobe_soda2/processbuffer_cip.py +213 -0
  114. arrayprobe_soda2/processbuffer_f2dc.py +139 -0
  115. arrayprobe_soda2/processbuffer_spec.py +441 -0
  116. arrayprobe_soda2/processbuffer_tail.py +350 -0
  117. arrayprobe_soda2/pth_readers.py +245 -0
  118. arrayprobe_soda2/py.typed +11 -0
  119. arrayprobe_soda2/read2dbuffer.py +371 -0
  120. arrayprobe_soda2/reject.py +246 -0
  121. arrayprobe_soda2/reprocess_pbp.py +156 -0
  122. arrayprobe_soda2/sample_area.py +264 -0
  123. arrayprobe_soda2/save_writer.py +480 -0
  124. arrayprobe_soda2/sea.py +324 -0
  125. arrayprobe_soda2/spec_absolutepointers.py +109 -0
  126. arrayprobe_soda2/spec_decompress.py +203 -0
  127. arrayprobe_soda2/spec_index.py +476 -0
  128. arrayprobe_soda2/spec_read_frame.py +286 -0
  129. arrayprobe_soda2/spec_read_hk.py +301 -0
  130. arrayprobe_soda2/spec_readint.py +127 -0
  131. arrayprobe_soda2/timeconv.py +77 -0
  132. arrayprobe_soda2/update_op.py +101 -0
  133. arrayprobe_uiops/__init__.py +45 -0
  134. arrayprobe_uiops/combine.py +192 -0
  135. arrayprobe_uiops/combine_fork.py +359 -0
  136. arrayprobe_uiops/constants.py +830 -0
  137. arrayprobe_uiops/decode_naming.py +113 -0
  138. arrayprobe_uiops/diode_mask.py +250 -0
  139. arrayprobe_uiops/engine_absence.py +41 -0
  140. arrayprobe_uiops/export_oap.py +325 -0
  141. arrayprobe_uiops/geometry_core.py +366 -0
  142. arrayprobe_uiops/habit.py +749 -0
  143. arrayprobe_uiops/habit_core.py +248 -0
  144. arrayprobe_uiops/hollow_size_rule.py +376 -0
  145. arrayprobe_uiops/imgproc.py +2081 -0
  146. arrayprobe_uiops/imgproc_core.py +275 -0
  147. arrayprobe_uiops/intarr.py +167 -0
  148. arrayprobe_uiops/intarr_analysis.py +569 -0
  149. arrayprobe_uiops/intarr_plots.py +119 -0
  150. arrayprobe_uiops/jit_kernels.py +430 -0
  151. arrayprobe_uiops/lwc.py +70 -0
  152. arrayprobe_uiops/matlab_compat.py +860 -0
  153. arrayprobe_uiops/measure.py +346 -0
  154. arrayprobe_uiops/min_circle.py +204 -0
  155. arrayprobe_uiops/min_ellipse.py +161 -0
  156. arrayprobe_uiops/min_rectangle.py +200 -0
  157. arrayprobe_uiops/ncar_2dc_timing.py +100 -0
  158. arrayprobe_uiops/ncio.py +810 -0
  159. arrayprobe_uiops/oap_read.py +228 -0
  160. arrayprobe_uiops/particle.py +51 -0
  161. arrayprobe_uiops/particle_perimeter.py +94 -0
  162. arrayprobe_uiops/particle_physics.py +199 -0
  163. arrayprobe_uiops/pecan_params.py +134 -0
  164. arrayprobe_uiops/probe_cases.py +298 -0
  165. arrayprobe_uiops/product_sanity.py +337 -0
  166. arrayprobe_uiops/profile.py +71 -0
  167. arrayprobe_uiops/profiles.py +756 -0
  168. arrayprobe_uiops/provenance.py +804 -0
  169. arrayprobe_uiops/py.typed +11 -0
  170. arrayprobe_uiops/qc.py +169 -0
  171. arrayprobe_uiops/readers/__init__.py +8 -0
  172. arrayprobe_uiops/readers/mask_csv.py +74 -0
  173. arrayprobe_uiops/readers/pms.py +239 -0
  174. arrayprobe_uiops/readers/tasinfo.py +57 -0
  175. arrayprobe_uiops/rect_ellipse.py +129 -0
  176. arrayprobe_uiops/register_image_assisted.py +25 -0
  177. arrayprobe_uiops/reject.py +501 -0
  178. arrayprobe_uiops/reject_core.py +220 -0
  179. arrayprobe_uiops/sample_area.py +93 -0
  180. arrayprobe_uiops/sizedist.py +1923 -0
  181. arrayprobe_uiops/sizedist_core.py +814 -0
  182. arrayprobe_uiops/sizedist_tables.py +642 -0
  183. arrayprobe_uiops/spec.py +1094 -0
  184. arrayprobe_uiops/spec_core.py +703 -0
  185. arrayprobe_uiops/stray_pixel.py +103 -0
  186. arrayprobe_uiops/tas.py +191 -0
  187. arrayprobe_uiops/time_convert.py +41 -0
  188. uiops/__init__.py +402 -0
  189. uiops/py.typed +11 -0
@@ -0,0 +1,275 @@
1
+ # SPDX-License-Identifier: BSD-3-Clause
2
+ # Reproduces SODA-2, Copyright (c) 2016 UCAR; see LICENSES/BSD-3-Clause.txt and NOTICE.md.
3
+ """Named hook points through which an optional correction package can substitute one port call.
4
+
5
+ Port tooling, not IDL: no ``.pro`` counterpart, and it computes nothing. The
6
+ "recorded, not applied" gap: ``arrayprobe soda2 run`` could only *record* which SODA-2
7
+ corrections a config turned on, because nothing let a correction reach the driver. This module
8
+ is that surface, kept on the port's side of the one-way boundary so the port never imports the
9
+ corrections -- ``arrayprobe_soda2_enhancements`` imports *this*, never the reverse
10
+ (``tests/test_no_enhancement_coupling.py``).
11
+
12
+ **What a hook point is.** Every port module binds its callees at import time
13
+ (``from .label_blobs import label_blobs``), and the driver chain looks each callee up in the
14
+ *consumer's* module globals at call time. A :class:`HookPoint` names one such binding --
15
+ consumer module, attribute, the call site that reads it -- so substituting that one global
16
+ changes exactly that one call and nothing else. No driver line had to change for this: the
17
+ bindings already exist, and the table below names them. (The alternative -- an explicit
18
+ ``hooks.call("label_blobs", ...)`` at each call site -- would edit ``process_2d.py``,
19
+ ``processbuffer_tail.py`` and four other port modules for no gain in what can be substituted.)
20
+
21
+ **No default behaviour change, measured rather than asserted.** At rest every consumer binding
22
+ *is* (identity, not equality) the port's own function captured when this module was imported;
23
+ :func:`pristine` reports it per point and ``tests/test_soda2_enhancement_hooks.py`` asserts it,
24
+ and also runs the driver with every point replaced by a counting pass-through to prove each named
25
+ binding is really called by the driver and that routing a call through a hook moves no written
26
+ value. :func:`overridden` restores the captured originals in ``finally``, so an exception inside
27
+ the ``with`` block cannot leave a substitution behind.
28
+
29
+ **Refusals.** An unknown point name, a point already overridden (no silent stacking: two
30
+ corrections on one point must be composed into one callable by whoever owns them), and a point
31
+ found not pristine on entry (someone else patched the binding) each raise :class:`HookError`.
32
+
33
+ Not thread-safe: the bindings are module globals, so a substitution is process-wide for the
34
+ duration of the ``with`` block. The SODA-2 driver is single-threaded.
35
+ """
36
+
37
+ from __future__ import annotations
38
+
39
+ import importlib
40
+ from collections.abc import Callable, Iterator, Mapping
41
+ from contextlib import contextmanager
42
+ from dataclasses import dataclass
43
+ from types import ModuleType
44
+ from typing import Any
45
+
46
+ __all__ = [
47
+ "HOOK_POINTS",
48
+ "HookError",
49
+ "HookPoint",
50
+ "Reconstruction",
51
+ "active",
52
+ "current",
53
+ "original",
54
+ "overridden",
55
+ "pristine",
56
+ "reconstruction_plan",
57
+ ]
58
+
59
+
60
+ class HookError(RuntimeError):
61
+ """A substitution was refused: unknown point, already overridden, or not pristine."""
62
+
63
+
64
+ @dataclass(frozen=True)
65
+ class HookPoint:
66
+ """One call the driver chain makes through a module-global binding.
67
+
68
+ ``consumer`` is the module whose global the call site reads; ``provider`` the module that
69
+ defines the port's own function; ``attribute`` the name in both. ``call_site`` cites the
70
+ port line (and the IDL line it ports) where the binding is read.
71
+ """
72
+
73
+ name: str
74
+ consumer: str
75
+ provider: str
76
+ attribute: str
77
+ call_site: str
78
+
79
+
80
+ @dataclass(frozen=True)
81
+ class Reconstruction:
82
+ """How a *fresh interpreter* rebuilds one :func:`overridden` substitution from plain data.
83
+
84
+ A substitution is a mapping of point name -> **function object**, and a function
85
+ object neither pickles in general nor survives a ``spawn``-started worker's re-import of
86
+ the package -- which is why ``process_2d_parallel.refuse_unsplittable`` refused ``jobs >
87
+ 1`` outright whenever anything was substituted. This dataclass is the narrow escape: the
88
+ installer states *how to build the same mapping again from data*, and both halves of it
89
+ are data.
90
+
91
+ ``factory`` is ``"module.path:callable"``, importable by name in a fresh interpreter;
92
+ ``payload`` is the one picklable argument it takes. :meth:`build` imports and calls it and
93
+ returns the mapping. The installer is responsible for the factory being a pure function of
94
+ its payload -- ``overridden`` checks that it rebuilds *the same point names*, which catches
95
+ a stale or mismatched plan, and the parallel path's byte-identity test is what proves the
96
+ rebuilt callables are the same corrections.
97
+
98
+ A caller that passes an ad-hoc lambda through :func:`overridden` supplies no
99
+ reconstruction, and stays refused. That is the honest residual: the refusal narrows from
100
+ *"any live substitution"* to *"a substitution this process cannot rebuild by name"*.
101
+ """
102
+
103
+ factory: str
104
+ payload: Any
105
+
106
+ def build(self) -> dict[str, Callable[..., Any]]:
107
+ """Import ``factory`` and call it on ``payload``; the substitution mapping."""
108
+ mod_name, sep, attr = self.factory.partition(":")
109
+ if not sep or not mod_name or not attr:
110
+ raise HookError(f"reconstruction factory {self.factory!r} is not 'module:callable'")
111
+ fn = getattr(_module(mod_name), attr)
112
+ built = fn(self.payload)
113
+ if not isinstance(built, Mapping):
114
+ raise HookError(f"reconstruction factory {self.factory!r} returned "
115
+ f"{type(built).__name__}, not a mapping of point name -> callable")
116
+ return dict(built)
117
+
118
+
119
+ _PKG = "arrayprobe_soda2"
120
+
121
+
122
+ def _point(name: str, consumer: str, provider: str, call_site: str,
123
+ attribute: str | None = None) -> HookPoint:
124
+ return HookPoint(name=name, consumer=f"{_PKG}.{consumer}", provider=f"{_PKG}.{provider}",
125
+ attribute=attribute or name, call_site=call_site)
126
+
127
+
128
+ #: Every substitutable binding, keyed by point name. Ordered driver-outermost first.
129
+ HOOK_POINTS: dict[str, HookPoint] = {p.name: p for p in (
130
+ _point("spec_index", "buildindex", "spec_index",
131
+ "buildindex.py:28 (soda2_buildindex.pro -> spec_index)"),
132
+ _point("open_pbp_ncdf", "process_2d", "pbp_writer",
133
+ "process_2d.py:520 (soda2_process_2d.pro, ncdfparticlefile)"),
134
+ _point("process_hk", "process_2d", "process_hk",
135
+ "process_2d.py:534 (soda2_process_2d.pro -> process_hk)"),
136
+ _point("process_spec_buffer", "processbuffer_spec", "processbuffer_spec",
137
+ "processbuffer_spec.py:390 (soda2_processbuffer.pro -> spec_processbuffer)"),
138
+ _point("binary_dof", "processbuffer_spec", "binary_dof",
139
+ "processbuffer_spec.py:276 (spec_processbuffer.pro:303, dofreject == 3)"),
140
+ _point("fixstuckbits", "processbuffer_tail", "fixstuckbits",
141
+ "processbuffer_tail.py:196 (soda2_processbuffer.pro, stuckbits)"),
142
+ _point("label_blobs", "processbuffer_tail", "label_blobs",
143
+ "processbuffer_tail.py:253-257 (soda2_processbuffer.pro, the three label_blobs calls)"),
144
+ _point("fillholes", "processbuffer_tail", "fillholes",
145
+ "processbuffer_tail.py:287 (soda2_processbuffer.pro, the line before :716)"),
146
+ _point("poisson_spot_correct", "processbuffer_tail", "poisson_spot_correct",
147
+ "processbuffer_tail.py:289 (soda2_processbuffer.pro:716)"),
148
+ _point("soda2_findsize", "processbuffer_tail", "findsize",
149
+ "processbuffer_tail.py:295 (soda2_processbuffer.pro:719-737)"),
150
+ _point("aspect_ratio", "findsize", "aspect_ratio",
151
+ "findsize.py:247 (soda2_findsize.pro -> aspect_ratio)"),
152
+ _point("axis_and_ratio", "aspect_ratio", "aspect_ratio",
153
+ "aspect_ratio.py:528 (aspect_ratio.pro's axis/ratio block, :66 and :105)"),
154
+ )}
155
+
156
+
157
+ def _module(name: str) -> ModuleType:
158
+ return importlib.import_module(name)
159
+
160
+
161
+ #: The port's own function behind every point, captured once, at import of this module --
162
+ #: the reference :func:`pristine` compares against by identity. Captured from the provider,
163
+ #: so a point whose consumer and provider are the same module still has an independent side.
164
+ _ORIGINALS: dict[str, Callable[..., Any]] = {
165
+ name: getattr(_module(p.provider), p.attribute) for name, p in HOOK_POINTS.items()
166
+ }
167
+
168
+ _ACTIVE: dict[str, Callable[..., Any]] = {}
169
+
170
+ #: The :class:`Reconstruction` the live substitution was installed with, or ``None`` -- either
171
+ #: because nothing is substituted or because the installer supplied no way to rebuild it.
172
+ _PLAN: Reconstruction | None = None
173
+
174
+
175
+ def _get(name: str) -> HookPoint:
176
+ try:
177
+ return HOOK_POINTS[name]
178
+ except KeyError:
179
+ raise HookError(f"unknown SODA-2 hook point {name!r}; "
180
+ f"known: {sorted(HOOK_POINTS)}") from None
181
+
182
+
183
+ def original(name: str) -> Callable[..., Any]:
184
+ """The port's own function behind point ``name``."""
185
+ _get(name)
186
+ return _ORIGINALS[name]
187
+
188
+
189
+ def current(name: str) -> Callable[..., Any]:
190
+ """What the call site behind point ``name`` would call right now."""
191
+ p = _get(name)
192
+ return getattr(_module(p.consumer), p.attribute)
193
+
194
+
195
+ def pristine() -> dict[str, bool]:
196
+ """Per point: is the consumer's binding the port's own function (identity)?"""
197
+ return {name: current(name) is _ORIGINALS[name] for name in HOOK_POINTS}
198
+
199
+
200
+ def active() -> dict[str, str]:
201
+ """Points currently overridden -> the replacement's qualified name."""
202
+ return {name: f"{getattr(fn, '__module__', '?')}.{getattr(fn, '__qualname__', repr(fn))}"
203
+ for name, fn in sorted(_ACTIVE.items())}
204
+
205
+
206
+ def reconstruction_plan() -> Reconstruction | None:
207
+ """The live substitution's :class:`Reconstruction`, or ``None``.
208
+
209
+ ``None`` means one of two different things and the caller must treat them the same way:
210
+ nothing is substituted, or something is and its installer gave no way to rebuild it in a
211
+ fresh interpreter. Only a non-``None`` plan licenses carrying the substitution into a
212
+ ``spawn``-started worker (``process_2d_parallel``).
213
+ """
214
+ return _PLAN
215
+
216
+
217
+ @contextmanager
218
+ def overridden(replacements: Mapping[str, Callable[..., Any]], *,
219
+ reconstruction: Reconstruction | None = None) -> Iterator[dict[str, str]]:
220
+ """Substitute the named bindings for the duration of the ``with`` block.
221
+
222
+ Yields :func:`active`'s view of what was substituted. An empty mapping substitutes nothing
223
+ and is allowed, so a caller need not special-case "every correction off".
224
+
225
+ ``reconstruction`` states how a fresh interpreter rebuilds ``replacements`` from
226
+ plain data; it is **checked here, not trusted** -- the factory is imported and called and
227
+ must produce the same point names, so a plan that has drifted from what is being installed
228
+ fails at install time rather than in a worker. Omitted, the substitution is process-local
229
+ and ``jobs > 1`` stays refused.
230
+ """
231
+ for name in replacements:
232
+ _get(name)
233
+ if name in _ACTIVE:
234
+ raise HookError(f"hook point {name!r} is already overridden by {active()[name]}; "
235
+ "compose the corrections into one callable instead of stacking")
236
+ if current(name) is not _ORIGINALS[name]:
237
+ raise HookError(f"hook point {name!r} is not pristine: "
238
+ f"{HOOK_POINTS[name].consumer}.{HOOK_POINTS[name].attribute} was "
239
+ "rebound outside enhancement_hooks")
240
+ if not callable(replacements[name]):
241
+ raise HookError(f"replacement for hook point {name!r} is not callable")
242
+ if reconstruction is not None:
243
+ rebuilt = reconstruction.build()
244
+ if sorted(rebuilt) != sorted(replacements):
245
+ raise HookError(
246
+ f"reconstruction {reconstruction.factory!r} rebuilds hook points "
247
+ f"{sorted(rebuilt)} but {sorted(replacements)} are being installed; a plan "
248
+ "that does not reproduce the substitution would carry a DIFFERENT set of "
249
+ "corrections into a worker process")
250
+ not_callable = sorted(n for n, fn in rebuilt.items() if not callable(fn))
251
+ if not_callable:
252
+ raise HookError(f"reconstruction {reconstruction.factory!r} rebuilt "
253
+ f"{not_callable} as non-callables")
254
+ global _PLAN
255
+ # Two `overridden` blocks on disjoint points can nest. Neither plan then describes the
256
+ # whole live substitution, so the combined state is declared unrebuildable and `jobs > 1`
257
+ # goes back to being refused -- the conservative direction.
258
+ previous_plan, previous_active = _PLAN, bool(_ACTIVE)
259
+ installed: list[str] = []
260
+ try:
261
+ for name, fn in replacements.items():
262
+ p = HOOK_POINTS[name]
263
+ setattr(_module(p.consumer), p.attribute, fn)
264
+ _ACTIVE[name] = fn
265
+ installed.append(name)
266
+ if installed:
267
+ _PLAN = None if previous_active else reconstruction
268
+ yield active()
269
+ finally:
270
+ for name in reversed(installed):
271
+ p = HOOK_POINTS[name]
272
+ setattr(_module(p.consumer), p.attribute, _ORIGINALS[name])
273
+ del _ACTIVE[name]
274
+ if installed:
275
+ _PLAN = previous_plan