pyodide / micropip

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

Option to skip selected dependencies #22

Closed joemarshall closed 1 year ago

joemarshall commented 1 year ago

Many packages include dependencies which are only used in some cases. e.g. I've got some packages which include a load of jupyter server stuff as deps, which can be ignored in pyodide.

This patch lets you skip some dependencies if you don't want to get them, whilst still getting other deps with micropip.

ryanking13 commented 1 year ago

Thanks, @joemarshall! I am a bit undecided about this PR. We have deps option which exists for a similar purpose. But I agree that it would be convenient to have options to ignore specific dependencies if a package has tons of dependencies. So if @rth or @hoodmane is okay with this. I have no objections to merging this.

rth commented 1 year ago

Yes, this would be useful, thanks @joemarshall ! This was also requested by @bollwyvl in point 3 in https://github.com/pyodide/micropip/issues/16. The only thing I'm not certain is in terms of API whether it would be better to have,

  1. this skip_deps passed to each install call
  2. a API such as micropip.add_noop_package(package_name: str | list[str]) as proposed in the linked issue. Which could be provided once. Later, it could also take as an optional argument whether the package needs to be mocked (in case it's a nonrelevant package but imported somewhere in the dependencies). The name of this function remains to be determined.

    WDYT?

ryanking13 commented 1 year ago

add_noop_package API looks good to me, as third-party Pyodide-based application developers can specify packages that can be ignored, and users who use it doesn't have to be aware of what is happening in the background (I think it is why jupyterlite team wants this feature?).

joemarshall commented 1 year ago

Ooh, that is a super idea. Maybe even add_mock_package, with an option to pass in a module object or leave it for a noop. I'll close this pr.

joemarshall commented 1 year ago

I have a neat little class which makes a module from itself, with class members becoming module members, with add_mock_package, I could just chuck those straight into micropip and they'd only get into the sys namespace when micropip install was called on something with them as a dependency