async def install(self, requirements: Union[str, List[str]], ctx=None): if isinstance(requirements, str): requirements = [requirements] transaction: Dict[str, Any] = { "wheels": [], "pyodide_packages": [], "locked": dict(self.installed_packages), } requirement_promises = [] for requirement in requirements: requirement_promises.append( self.add_requirement(requirement, ctx, transaction)) await gather(*requirement_promises) wheel_promises = [] # Install built-in packages pyodide_packages = transaction["pyodide_packages"] if len(pyodide_packages): # Note: branch never happens in out-of-browser testing because in # that case builtin_packages is empty. self.installed_packages.update(pyodide_packages) wheel_promises.append( asyncio.ensure_future( pyodide_js.loadPackage( to_js([name for [name, _] in pyodide_packages])))) # Now install PyPI packages for name, wheel, ver in transaction["wheels"]: wheel_promises.append(_install_wheel(name, wheel)) self.installed_packages[name] = ver await gather(*wheel_promises)
async def install(self, requirements: str | list[str], ctx=None, keep_going: bool = False): async def _install(install_func, done_callback): await install_func done_callback() transaction = await self.gather_requirements(requirements, ctx, keep_going) if transaction["failed"]: failed_requirements = ", ".join( [f"'{req}'" for req in transaction["failed"]]) raise ValueError( f"Couldn't find a pure Python 3 wheel for: {failed_requirements}" ) wheel_promises = [] # Install built-in packages pyodide_packages = transaction["pyodide_packages"] if len(pyodide_packages): # Note: branch never happens in out-of-browser testing because in # that case BUILTIN_PACKAGES is empty. wheel_promises.append( _install( asyncio.ensure_future( pyodide_js.loadPackage( to_js([name for [name, _, _] in pyodide_packages]))), functools.partial( self.installed_packages.update, {pkg.name: pkg for pkg in pyodide_packages}, ), )) # Now install PyPI packages for name, wheel, ver in transaction["wheels"]: # detect whether the wheel metadata is from PyPI or from custom location # wheel metadata from PyPI has SHA256 checksum digest. wheel_source = "pypi" if wheel["digests"] is not None else wheel[ "url"] wheel_promises.append( _install( _install_wheel(name, wheel), functools.partial( self.installed_packages.update, {name: PackageMetadata(name, str(ver), wheel_source)}, ), )) await gather(*wheel_promises)
async def install(self, requirements: Union[str, List[str]], ctx=None): transaction = await self.gather_requirements(requirements, ctx) wheel_promises = [] # Install built-in packages pyodide_packages = transaction["pyodide_packages"] if len(pyodide_packages): # Note: branch never happens in out-of-browser testing because in # that case builtin_packages is empty. self.installed_packages.update(pyodide_packages) wheel_promises.append( asyncio.ensure_future( pyodide_js.loadPackage( to_js([name for [name, _] in pyodide_packages])))) # Now install PyPI packages for name, wheel, ver in transaction["wheels"]: wheel_promises.append(_install_wheel(name, wheel)) self.installed_packages[name] = ver await gather(*wheel_promises)
async def install(self, requirements: Union[str, List[str]], ctx=None): if ctx is None: ctx = {"extra": None} complete_ctx = dict(markers.DEFAULT_CONTEXT) complete_ctx.update(ctx) if isinstance(requirements, str): requirements = [requirements] transaction: Dict[str, Any] = { "wheels": [], "pyodide_packages": set(), "locked": dict(self.installed_packages), } requirement_promises = [] for requirement in requirements: requirement_promises.append( self.add_requirement(requirement, complete_ctx, transaction)) await gather(*requirement_promises) wheel_promises = [] # Install built-in packages pyodide_packages = transaction["pyodide_packages"] if len(pyodide_packages): # Note: branch never happens in out-of-browser testing because we # report that all dependencies are empty. self.installed_packages.update( dict((k, None) for k in pyodide_packages)) wheel_promises.append( pyodide_js.loadPackage(list(pyodide_packages))) # Now install PyPI packages for name, wheel, ver in transaction["wheels"]: wheel_promises.append(_install_wheel(name, wheel)) self.installed_packages[name] = ver await gather(*wheel_promises) return f'Installed {", ".join(self.installed_packages.keys())}'