def install(requirements: Union[str, List[str]]): """Install the given package and all of its dependencies. This only works for pure Python wheels or for packages built in pyodide. If a package is not found in the pyodide repository it will be loaded from PyPi. Parameters ---------- requirements a requirements or a list of requirements to install. Can be composed either of - package names, as defined in pyodide repository or on PyPi - URLs pointing to pure Python wheels. The file name of such wheels end with ``none-any.whl``. Returns ------- a Promise that resolves when all packages have downloaded and installed. """ def do_install(resolve, reject): PACKAGE_MANAGER.install(requirements, resolve=resolve, reject=reject) importlib.invalidate_caches() return Promise.new(do_install)
def install(requirements: Union[str, List[str]]): """Install the given package and all of its dependencies. See :ref:`loading packages <loading_packages>` for more information. This only works for packages that are either pure Python or for packages with C extensions that are built in pyodide. If a pure Python package is not found in the pyodide repository it will be loaded from PyPi. Parameters ---------- requirements A requirement or list of requirements to install. Each requirement is a string. - If the requirement ends in ".whl", the file will be interpreted as a url. The file must be a wheel named in compliance with the [PEP 427 naming convention](https://www.python.org/dev/peps/pep-0427/#file-format) - A package name. A package by this name must either be present in the pyodide repository at `languagePluginUrl` or on PyPi. Returns ------- A Promise that resolves when all packages have been downloaded and installed. """ def do_install(resolve, reject): PACKAGE_MANAGER.install(requirements, resolve=resolve, reject=reject) importlib.invalidate_caches() return Promise.new(do_install)
def get_url(url): def run_promise(resolve, reject): def callback(data): resolve(data) _get_url_async(url, callback) return Promise.new(run_promise)
def install(requirements): """ Install the given package and all of its dependencies. Returns a Promise that resolves when all packages have downloaded and installed. """ def do_install(resolve, reject): PACKAGE_MANAGER.install(requirements, resolve=resolve, reject=reject) importlib.invalidate_caches() return Promise.new(do_install)
def get_package(url): def do_install(resolve, reject): def run_promise(wheel): try: extract_wheel(wheel) except Exception as e: reject(str(e)) else: resolve() get_url(url).then(run_promise) importlib.invalidate_caches() return Promise.new(do_install)
def call(self, this, *args): # todo handle args to coroutine? def _promise_func(resolve, reject): task = asyncio.create_task( self._method(this, *chain(self.args, args))) def done(future): exception = task.exception() if task.exception(): reject(exception) else: resolve(task.result()) task.add_done_callback(done) if asyncio.iscoroutinefunction(self._method): return Promise.new(_promise_func) return self._method(this, *chain(self.args, args))
def load_and_copy_wheels(base_url, index_url): def run_promise(resolve, reject): def extract_all_wheels(wheel_index_json): wheel_index = json.load(wheel_index_json) for wheel in wheel_index: wheel_name = wheel.split("/")[-1].split("-")[0] print("Loading {} from python-wheels".format(wheel_name)) urls = ["{}{}".format(base_url, wheel) for wheel in wheel_index] promises = [] for url in urls: promises.append(get_package(url)) Promise.all(promises).then(resolve) get_url(index_url).then(extract_all_wheels) return Promise.new(run_promise)
def install(requirements): """ Install the given package and all of its dependencies. Returns a Promise that resolves when all packages have downloaded and installed. **IMPORTANT:** Since the packages hosted at `files.pythonhosted.org` don't support CORS requests, we use a CORS proxy at `cors-anywhere.herokuapp.com` to get package contents. This makes a man-in-the-middle attack on the package contents possible. However, this threat is minimized by the fact that the integrity of each package is checked using a hash obtained directly from `pypi.org`. We hope to have this improved in the future, but for now, understand the risks and don't use any sensitive data with the packages installed using this method. """ def do_install(resolve, reject): PACKAGE_MANAGER.install(requirements, resolve=resolve, reject=reject) importlib.invalidate_caches() return Promise.new(do_install)