MCPcopy Index your code
hub / github.com/RustPython/RustPython / _load_package

Function _load_package

crates/wasm/Lib/whlimport.py:43–60  ·  view source on GitHub ↗
(pkg)

Source from the content-addressed store, hash-verified

41
42
43async def _load_package(pkg):
44 if isinstance(pkg, str) and _http_url.match(pkg):
45 urlobj = urlparse(pkg)
46 fname = posixpath.basename(urlobj.path)
47 name, url, size, deps = fname, pkg, None, []
48 else:
49 # TODO: load dependencies as well
50 name, fname, url, size, deps = await _load_info_pypi(pkg)
51 if name in _loaded_packages:
52 return
53 deps = asyncweb.spawn(asyncweb.wait_all(_load_package for dep in deps))
54 size_str = format_size(size) if size is not None else "unknown size"
55 LOG_FUNC(f"Downloading {fname} ({size_str})...")
56 zip_data = io.BytesIO(await browser.fetch(url, response_format="array_buffer"))
57 size = len(zip_data.getbuffer())
58 LOG_FUNC(f"{fname} done!")
59 _loaded_packages[name] = zipfile.ZipFile(zip_data)
60 await deps
61
62
63async def _load_info_pypi(pkg):

Callers 1

load_packageFunction · 0.85

Calls 11

getbufferMethod · 0.95
urlparseFunction · 0.90
isinstanceFunction · 0.85
_load_info_pypiFunction · 0.85
format_sizeFunction · 0.85
LOG_FUNCFunction · 0.85
lenFunction · 0.85
basenameMethod · 0.80
spawnMethod · 0.80
fetchMethod · 0.80
matchMethod · 0.45

Tested by

no test coverage detected