Skip to content

ENH Add extra_index_urls and index_strategy parameters to micropip.install(<...>) #224

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

agriyakhetarpal
Copy link
Member

Closes #223

@agriyakhetarpal
Copy link
Member Author

This PR has also been ready for review, and I can work on it further so that we can include it in an upcoming 0.10.0 release. I'll re-trigger the tests now. If I remember correctly, the test failures I had encountered were simple to fix – I would love feedback on the API design.

Please note that the behaviour deviates from pip and is closer to that of uv, because they have aligned themselves with security considerations better – see https://docs.astral.sh/uv/concepts/indexes/#searching-across-multiple-indexes for more information.

Therefore, I think it makes sense for us to be security-aware as well, given the inherent security model for running WASM in browsers and the fact that WASM as a format in general has been proven not to be particularly effective against, say, cryptocurrency mining malware.

@agriyakhetarpal agriyakhetarpal changed the title ENH Add extra_index_urls and index_strategy parameters (DRAFT] ENH Add extra_index_urls and index_strategy parameters Jun 26, 2025
@agriyakhetarpal agriyakhetarpal changed the title ENH Add extra_index_urls and index_strategy parameters ENH Add extra_index_urls and index_strategy parameters to micropip.install(<...>) Jun 26, 2025
Copy link
Member

@ryanking13 ryanking13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this Agriya!

I am not sure about the extra_index_urls parameter, but having index_strategy sounds good to me. So how about separating the PR into two?

Also, I am not sure the current implementation is regarding the index strategy is correct, I left a comment about it,

name: str,
index_urls: list[str] | str,
fetch_kwargs: dict[str, Any] | None = None,
strategy: str = "first-index",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For betting typing, how about using Literal type?

@@ -132,6 +136,29 @@ async def install(
- If a list of URLs is provided, micropip will try each URL in order until \
it finds a package. If no package is found, an error will be raised.

extra_index_urls:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if we need to separate extra_index_urls as we already support multiple index_urls.

How about exposing an API to get the current index URLs for micropip instead?

For example,

micropip.install("...", extra_index_urls=["A", "B", "C"])

can be replaced with

current_index_urls = micropip.get_index_urls()
micropip.install("...", index_urls=current_index_urls + ["A", "B", "C"])


# With "first-index" strategy, we'll return the first match we find
# without checking the other indexes at all.
if strategy == "first-index":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each strategy has duplicate logics, so I think we can separate this with multiple functions, extracting out common parts.

raise ValueError(f"Error trying to decode url: {url}") from e
return parser(metadata)
# With "unsafe-first-match" or "unsafe-best-match", we need to check all indexes
else:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is still better to check the strategy string, as people might pass some strange value here.
Or, we can probably check the value early and failfast.

Comment on lines +382 to +383
if strategy == "unsafe-first-match":
return projects_info[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it the right implementation? If the projects_info[0] does not have the compatible version, I think we should fallback to other indices.

The compatibility check is not handled in this function (at least in the current implementation). So I think so support this strategy, we'll need to modify the Transaction as well.

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

Successfully merging this pull request may close these issues.

Ability to have the pip --extra-index-urls behaviour
2 participants