Skip to content

fallback method to call when micropip can't find a package. #199

@samuelcolvin

Description

@samuelcolvin

It would be nice if there was a fallback method to provide a URL while micropip is unable to find a pure Python wheel.

Currently (while waiting for pyodide/pyodide#5388 to be released), I'm having to do

from packaging.tags import parse_tag  # noqa
from packaging.version import Version  # noqa

import micropip  # noqa
from micropip import transaction  # noqa
from micropip.wheelinfo import WheelInfo  # noqa
real_find_wheel = transaction.find_wheel


def custom_find_wheel(metadata: Any, req: Any) -> Any:
    if metadata.name == 'jiter':
        known_version = Version('0.8.2')
        if known_version in metadata.releases:
            tag = 'cp312-cp312-emscripten_3_1_58_wasm32'
            filename = f'{metadata.name}-{known_version}-{tag}.whl'
            url = f'https://files.pydantic.run/{filename}'
            return WheelInfo(
                name=metadata.name,
                version=known_version,
                filename=filename,
                build=(),
                tags=frozenset({parse_tag(tag)}),
                url=url,
                parsed_url=urlparse(url),
            )
    return real_find_wheel(metadata, req)


transaction.find_wheel = custom_find_wheel

Which seems excessively ugly.

I know I could use an index_url, but then:

  1. I think it would stop micropip consulting the pyodide lock file first
  2. would require more infra than I want to setup

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions