Module import and object construction¶
What a provider may import is decided before the provider exists. Preparation hands the CPython provider a closed list: the admitted compiled interface, the declared exports, the generated adapter entrypoint, and an ordered, sealed set of module roots. The provider imports exactly those, proves each file sits under a sealed capsule root, and constructs the declared objects. This page covers the inputs to preparation, the steps for each export, and the conditions that refuse it.
What preparation supplies¶
flowchart LR
subgraph PREP["PREPARE REQUEST"]
direction TB
XCI[("Compiled interface<br/>and its hash")]
EXP["Declared exports"]
ADP["Generated adapter entrypoint"]
ROOTS[("Ordered sealed module roots")]
end
subgraph PROV["CPYTHON PROVIDER"]
direction TB
IMP{{"Import and containment check"}}
OBJ[("Constructed exports<br/>held in the provider")]
IMP --> OBJ
end
XCI --> IMP
EXP --> IMP
ADP --> IMP
ROOTS --> IMP
The module roots are the cell environment view's ordered search path. Installed packages elsewhere on the node and introspection of block code contribute nothing to the import set. See Import authority.
For each export¶
- Import the declared block module.
- Canonicalise the module's
__file__and prove it lies under a selected capsule root. - Import the generated adapter and the generated binding module, and apply the same containment check to each.
- Require both generated modules to carry the admitted interface hash.
- Construct a declared class through its zero-argument construction contract, or retain the module target for a declared function export.
Constructed objects stay in the provider for the life of the provider epoch. See Provider resource table.
Preparation refusals¶
Preparation is refused when:
- a module root named by the prepare request is missing;
- a module file resolves outside the capsule roots through a symlink;
- an export names a module the interface does not declare;
- an export is not callable;
- two exports carry the same export ordinal;
- a generated module's interface hash differs from the admitted one.
A refused preparation is final for that provider process. The search path is
fixed at initialisation, and dependencies are resolved at closure resolution,
before the cell exists, so the cell stays out of ready. See
Resolved runtime closure.