pyodide / micropip

A lightweight Python package installer for Pyodide
https://micropip.pyodide.org
Mozilla Public License 2.0
68 stars 16 forks source link

Custom PYPI? #43

Closed zachcp closed 1 year ago

zachcp commented 1 year ago

Hi Team Pyodide,

This is beautiful work. Is it possible to specify a private PYPI-compatible repository?

zach cp

hoodmane commented 1 year ago

It's not explicitly supported. I think you could do it by monkey patching _micropip._get_pypi_json:

async def _get_pypi_json(pkgname: str, fetch_kwargs: dict[str, str]) -> Any:
    url = f"https://pypi.org/pypi/{pkgname}/json"
    try:
        metadata = await fetch_string(url, fetch_kwargs)
    except OSError as e:
        raise ValueError(
            f"Can't fetch metadata for '{pkgname}' from PyPI. "
            "Please make sure you have entered a correct package name."
        ) from e
    return json.loads(metadata)

https://github.com/pyodide/micropip/blob/main/micropip/_micropip.py#L45

hoodmane commented 1 year ago

A PR to add support for this would be welcome if you are interested.

zachcp commented 1 year ago

So, it looks like the internal pypi instance I was interested in using doesn't use the json endpoint and I believe this is due to the differences between pypi s fully featured Warehouse tool vs the pypiserver we are using which has some known limitations.

So at least for my use case this is not trivial and a simple string substitution is unlikely to be useful for many private repos. However, I should be able to retrieve whl files directly via the URL.

Thanks again for your great work.