Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
samuelcolvin opened this issue Feb 7, 2025 · 2 comments
Open

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

samuelcolvin opened this issue Feb 7, 2025 · 2 comments

Comments

@samuelcolvin
Copy link
Contributor

samuelcolvin commented Feb 7, 2025

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
@hoodmane
Copy link
Member

hoodmane commented Feb 7, 2025

What about using add_mock_package()?

@andycloke
Copy link

@samuelcolvin thank you for this workaround! It means I can support OpenAI until the next version of Pydodide is released.

FYI, your example is missing this: from urllib.parse import urlparse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants