Preparing a shared Python component¶
A block's Python requirement is resolved foundation-first. The order is fixed:
reusable-block declared requirement
-> compatible foundation component: reuse it
-> otherwise compatible admitted project-prepared Python component: reuse it
within block-declared authority
-> otherwise exact external solve and automatic immutable block-local
component build
So if the foundation already carries a compatible torch, every block that
declares torch resolves to it and runtime.xratu needs no entry at all.
Preparing one would change nothing, because a prepared component never outranks
a compatible component in the selected foundation.
document.dependencies.requirements is for the second line: a package the
foundation does not carry, which several blocks need.
The problem it solves¶
Twelve blocks declare torch>=2.4,<3 and the foundation has no Torch. Each
block's closure then reaches the third line and runs its own external solve
against the approved sources.
Nothing makes those twelve solves agree. The index moves, so blocks resolved on Monday can land on 2.4.1 and blocks resolved on Friday on 2.4.2. Both satisfy the constraint, and the project ends up running two Torch versions it never chose.
Declaring the requirement once at project scope replaces those twelve solves with one:
The solve happens at project scope, the admitted result pins one
selected_version, and every block whose constraint that version satisfies
reuses it by reaching the second line instead of the third.
What stays on the block¶
All twelve still declare what they import:
The project entry decides which bytes satisfy the declaration. The declaration
is what carries import authority, and a block without one receives
UndeclaredDependency however much the project prepared.
What a prepared component reaches¶
flowchart LR
P["Prepared component<br/>torch 2.4.1"]
P --> A["Block A<br/>declares torch"]
P --> B["Block B<br/>declares torch"]
P -.->|"never selected"| C["Block C<br/>declares nothing"]
A prepared component is a candidate offered to the resolver, so Block C receives nothing from it. Preparation is invisible to a block that did not ask.
Each prepared entry records the requirement as declared, the version resolution
chose, the exact bytes as component_digest, and the component's own
component_inventory_digest and provenance_digest.
What preparation does not change¶
Storage. Build and release may deduplicate and cache a component by digest across thousands of closures, so twelve blocks that independently resolve to the same version already share one copy of the bytes. Preparation converges the version; the caching was happening either way.
Import authority. Eight field names are refused on the admitted result so a candidate cannot read as a grant:
| Refused field | What it would have granted |
|---|---|
import_roots |
A path the interpreter searches |
module_roots |
The same, by another name |
provided_modules |
Importable module names |
python_distribution_requirements |
A second authoring decision |
operating_system_requirements |
The same, for the system half |
foundation_digest |
A foundation choice |
env_group |
A runtime lane |
allow_system_site_fallback |
A fallback import path |
AdmittedProjectRuntimeDependenciesV1 refuses import_roots; a prepared component
is reusable bytes, never an import grant, and the declaration it resolves
belongs to the intent
See Presence versus import authority.
The foundation. Preparing mutates no foundation, and foundation_digest is
unchanged by it. The component is built and admitted alongside the foundation,
not into it. See
Changing shared dependencies.
What a block gets when it selects one¶
The binding records where the bytes came from and whose declaration authorised
them, and those are separate facts. A prepared component gives a binding whose
source is project_prepared and whose requirement_scope is
reusable_block.
A Python binding is always reusable_block scope, even when its source is
project_prepared. Preparing at project scope supplies the version; the
authorising declaration stays the block's. See
Requirement scope and binding source.
Completeness¶
Every prepared requirement resolves to exactly one component, and nothing appears that was not declared:
prepared_python_components does not account for declared ['torch>=2.4,<3']; a
project requirement prepared for reuse that resolved to nothing would fail much
later, in a block, for want of bytes the project said it had
When a block wants a different version¶
The twelfth block needs torch>=2.6 for a new operator. The prepared component
at 2.4.1 does not satisfy its constraint, so it falls to the third line and
resolves its own 2.6.0 into its own closure. The other eleven keep the prepared
one.
A prepared version is therefore a default rather than a ceiling. See Version coexistence.