Skip to content

Commit 7ab675b

Browse files
docs(imports): Allign docs and clean redaction.
1 parent 361cd62 commit 7ab675b

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

docs/pages/reference/imports.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "Imports"
33
description: "Importing modules in Edge Python: syntax, resolution, and the two module flavors."
44
---
55

6-
Supports `import`, `from <spec> import <names>`, `from <spec> import *`. Resolution is compile-time, the VM never learns what a module is; bytecode flattens every import into the sequence that materialises the exports.
6+
Supports `import`, `from <spec> import <names>`, `from <spec> import *`. Resolution is compile-time: the VM never learns what a module is; bytecode flattens every import into the sequence that materialises the exports.
77

88
## The two flavors
99

@@ -56,15 +56,15 @@ The names above (`json`, `utils`, `math`) are illustrative. `json` is an [offici
5656
2. For each spec, asks the host `Resolver` to materialise as `Resolved::Native { bindings, canonical }` or `Resolved::Code { src, canonical }`.
5757
3. Natives become direct-dispatch entries; code modules parse to a fresh `SSAChunk`. Both register under the canonical spec so first-class references and `import_module()` lookups resolve uniformly. See [Syntax, Imports](/implementation/syntax).
5858

59-
Modules are singletons across the compilation unit: same canonical spec -> one `SSAChunk`, top level runs once, one `HeapObj::Module` shared by every importer. Two files importing `./util.py` see the same module, `mod is mod_alias` is true; module-attr mutations are observed by every consumer. Inside the module's top level, `__name__` is bound to the canonical spec so `if __name__ == "__main__":` skips when imported.
59+
Modules are singletons across the compilation unit: same canonical spec -> one `SSAChunk`, top level runs once, one `HeapObj::Module` shared by every importer. Two files importing `./util.py` see the same module `mod is mod_alias` is true; module-attr mutations are observed by every consumer. Inside the module's top level, `__name__` is bound to the canonical spec so `if __name__ == "__main__":` skips when imported.
6060

6161
Helpers and constants stay private: they live in the module's slot frame, reached via attribute access on the `HeapObj::Module` Val, not through the parent chunk's name table. `a.f` calling `helper` resolves through `a`'s attrs, not the importer's globals.
6262

6363
The runtime never fetches. The host (browser, WASI, embedded Rust) brings the bytes; the compiler accepts them through `Resolver`.
6464

6565
## packages.json
6666

67-
Bare-name imports resolve through an import map in `packages.json` (next to the entry script). The manifest is always `packages.json`, no `edge.json` or other variants.
67+
Bare-name imports resolve through an import map in `packages.json` (next to the entry script). The manifest is always `packages.json` no `edge.json` or other variants.
6868

6969
```json
7070
{
@@ -81,14 +81,14 @@ Schema:
8181
- Top-level value is a JSON object. Empty `{}` is valid.
8282
- `imports` (optional): alias -> spec string.
8383
- `extends` (optional): directory whose `packages.json` is consulted when an alias isn't found locally.
84-
- `host` (optional): name -> JS module URL. Read by the browser runtime's `<edge-python>` element to load [host libraries](/reference/packages#host-libraries) on the main thread (DOM, network, storage,...). The compiler itself ignores it (it's one of the silently-ignored keys below); the runtime consumes it. See the [runtime README](https://github.com/dylan-sutton-chavez/edge-python/tree/main/runtime).
84+
- `host` (optional): name -> JS module URL. Read by the browser runtime's `<edge-python>` element to load [host libraries](/reference/packages#host-libraries) on the main thread (DOM, network, storage). The compiler itself ignores it (it's one of the silently-ignored keys below); the runtime consumes it. See the [runtime README](https://github.com/dylan-sutton-chavez/edge-python/tree/main/runtime).
8585
- Unknown top-level keys silently ignored (forward-compatible).
8686
- Booleans, numbers, arrays at any level are rejected.
87-
- String escapes: `\"`, `\\`, `\/`, `\n`, `\t`, `\r`. `\uXXXX` not supported, paste UTF-8 literally.
87+
- String escapes: `\"`, `\\`, `\/`, `\n`, `\t`, `\r`. `\uXXXX` not supported paste UTF-8 literally.
8888

8989
`from utils import x` resolves to `./lib/utils.py` relative to the entry script; `from math import add` loads `.wasm` per the [wire format](/reference/wasm-abi).
9090

91-
`packages.json` is optional, scripts can use string-form paths directly without project config, and the browser runtime resolves the [official packages](/reference/packages#defaults) by bare name without it.
91+
`packages.json` is optional scripts can use string-form paths directly without project config, and the browser runtime resolves the [official packages](/reference/packages#defaults) by bare name without it.
9292

9393
### Walk-up resolution
9494

@@ -97,17 +97,17 @@ Bare-name imports resolve against the nearest `packages.json` walking up from th
9797
```
9898
my_app/
9999
├── packages.json <- root manifest
100-
├── main.py bare imports here resolve via root manifest
100+
├── main.py # bare imports here resolve via root manifest
101101
├── lib/
102102
│ ├── packages.json <- sub-package manifest
103-
│ └── helper.py bare imports here resolve via lib/ first
103+
│ └── helper.py # bare imports here resolve via lib/ first
104104
└── ...
105105
```
106106

107107
- **Bare-name imports** (`from utils import x`) walk up looking for `packages.json`. First one decides. Capped at 32 hops; over: `packages.json walk-up exceeded <cap> hops resolving '<name>'`.
108-
- **Hermetic by default**: if the nearest manifest doesn't declare the alias, compilation fails (`alias '<name>' not declared in '<manifest>'`). No silent fall-through, prevents a deep transitive dep from borrowing parent aliases.
108+
- **Hermetic by default**: if the nearest manifest doesn't declare the alias, compilation fails (`alias '<name>' not declared in '<manifest>'`). No silent fall-through prevents a deep transitive dep from borrowing parent aliases.
109109
- **`extends` opts in to inheritance**: `"extends": ".."` re-runs the search from the extended directory when the alias isn't local. Cycles detected at compile time (`circular extends chain in packages.json`).
110-
- **Quoted relative paths** (`from "./helpers.py" import f`) resolve against the importing file, transitively-imported `lib/a.py` doing `from "./b.py" import g` finds `lib/b.py`.
110+
- **Quoted relative paths** (`from "./helpers.py" import f`) resolve against the importing file; transitively-imported `lib/a.py` doing `from "./b.py" import g` finds `lib/b.py`.
111111

112112
Spec classification (handled by the resolver):
113113

@@ -169,21 +169,21 @@ Append `#sha256-<64 hex chars>` to any URL spec to require a content match:
169169
from "https://example.com/utils.py#sha256-deadbeef0123456789abcdef0123456789abcdef0123456789abcdef01234567" import normalize
170170
```
171171

172-
The compiler asks the host for raw bytes (`Resolver::fetch_bytes`), computes SHA-256, refuses to compile on mismatch, diagnostic surfaces both digests:
172+
The compiler asks the host for raw bytes (`Resolver::fetch_bytes`), computes SHA-256, refuses to compile on mismatch; the diagnostic surfaces both digests:
173173

174174
```text
175175
error: integrity check failed for 'https://example.com/utils.py'
176176
expected sha256-deadbeef0123456789abcdef0123456789abcdef0123456789abcdef01234567
177177
got sha256-feedface9876543210fedcba9876543210fedcba9876543210fedcba98765432
178178
```
179179

180-
Verification lives in the compiler, not the host, every host inherits it uniformly. Hosts without `fetch_bytes` surface a clean "not supported" error rather than silently bypassing.
180+
Verification lives in the compiler, not the host: every host inherits it uniformly. Hosts without `fetch_bytes` surface a clean "not supported" error rather than silently bypassing.
181181

182182
Only `sha256` supported. Other prefixes (`md5-...`, `sha384-...`) fail with `unrecognized integrity fragment`. The hex body must be exactly 64 chars.
183183

184184
## Lockfile and content-addressed cache
185185

186-
The browser worker auto-generates a lockfile and a content-addressed cache (both in IndexedDB) as a side-effect of running scripts that import URLs, repeat runs go to zero network round-trips and upstream drift is detected on demand.
186+
The browser worker auto-generates a lockfile and a content-addressed cache (both in IndexedDB) as a side-effect of running scripts that import URLs; repeat runs go to zero network round-trips, and upstream drift is detected on demand.
187187

188188
| File | Who writes it | Purpose |
189189
|---|---|---|
@@ -209,7 +209,7 @@ integrity drift for 'https://cdn.foo/kit/index.py'
209209

210210
Same primitive as inline `#sha256-...` integrity, applied automatically to every imported URL. Explicit hashes in source are still honoured and fail at compile time before any code runs.
211211

212-
Non-browser hosts make their own caching choices, `Resolver` sees only `(spec -> Resolved)` and `(spec -> bytes)`.
212+
Non-browser hosts make their own caching choices: `Resolver` sees only `(spec -> Resolved)` and `(spec -> bytes)`.
213213

214214
## Sandbox
215215

0 commit comments

Comments
 (0)