MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / vendor_packages

Function vendor_packages

cli/src/build.rs:151–175  ·  view source on GitHub ↗

For each imported name, resolve via the shared registry, fetch, and stash under dist/vendor/.

(
    manifest: &Manifest,
    imports: &BTreeSet<String>,
    out_dir: &Path,
)

Source from the content-addressed store, hash-verified

149
150/// For each imported name, resolve via the shared registry, fetch, and stash under dist/vendor/.
151fn vendor_packages(
152 manifest: &Manifest,
153 imports: &BTreeSet<String>,
154 out_dir: &Path,
155) -> Result<(BTreeMap<String, String>, BTreeMap<String, String>)> {
156 let mut std_local = BTreeMap::new();
157 let mut host_local = BTreeMap::new();
158
159 for name in imports {
160 // Unknown names are project-local .py modules; let the runtime resolve them at run time.
161 let Some((kind, url)) = pkg::resolve(name, manifest) else { continue };
162 let bytes = fetch(&url).with_context(|| format!("fetching {url}"))?;
163 let local = match kind {
164 // std packages are .wasm, except pure-Python ones (test) served as .py; preserve the real extension.
165 Kind::Std => format!("vendor/{name}.{}", if url.ends_with(".py") { "py" } else { "wasm" }),
166 Kind::Host => format!("vendor/{name}/index.js"),
167 };
168 write_under(out_dir, &local, &bytes)?;
169 match kind {
170 Kind::Std => { std_local.insert(name.clone(), local); }
171 Kind::Host => { host_local.insert(name.clone(), local); }
172 }
173 }
174 Ok((std_local, host_local))
175}
176
177fn write_under(root: &Path, rel: &str, bytes: &[u8]) -> Result<()> {
178 let path = root.join(rel);

Callers 1

runFunction · 0.85

Calls 4

fetchFunction · 0.85
write_underFunction · 0.85
insertMethod · 0.80
resolveFunction · 0.70

Tested by

no test coverage detected