Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Changed

- `install` now raises a helpful `ValueError` when given a VCS URL
(`git+`, `hg+`, `svn+`, `bzr+`) instead of an opaque parser error,
explaining that micropip only installs prebuilt wheels.
[#77](https://github.com/pyodide/micropip/issues/77)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
[#77](https://github.com/pyodide/micropip/issues/77)
[#277](https://github.com/pyodide/micropip/pull/277)


## [0.11.1] - 2026/04/02

### Fixed
Expand Down
14 changes: 14 additions & 0 deletions micropip/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@

logger = logging.getLogger("micropip")

_VCS_URL_PREFIXES = ("git+", "hg+", "svn+", "bzr+")


def _looks_like_vcs_url(req: str) -> bool:
return req.startswith(_VCS_URL_PREFIXES)


@dataclass
class Transaction:
Expand Down Expand Up @@ -77,6 +83,14 @@ async def add_requirement(self, req: str | Requirement) -> None:
if isinstance(req, Requirement):
return await self.add_requirement_inner(req)

if isinstance(req, str) and _looks_like_vcs_url(req):
raise ValueError(
f"Cannot install {req!r}: micropip only installs prebuilt wheels "
"and does not support installing from a VCS URL "
"(git+, hg+, svn+, bzr+). Provide a wheel URL or a package name "
"available on a configured index."
)
Comment on lines +86 to +92

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if isinstance(req, str) and _looks_like_vcs_url(req):
raise ValueError(
f"Cannot install {req!r}: micropip only installs prebuilt wheels "
"and does not support installing from a VCS URL "
"(git+, hg+, svn+, bzr+). Provide a wheel URL or a package name "
"available on a configured index."
)
if isinstance(req, str) and _looks_like_vcs_url(req):
raise ValueError(
f"Cannot install {req!r}: micropip only installs prebuilt wheels "
"and does not support installing from a VCS URL "
"(git+, hg+, svn+, bzr+). Provide a URL pointing to a wheel "
"or a package name available on a configured index."
)

(nit: sorry, I know) – I think this would be a bit cleaner!


try:
as_req = constrain_requirement(Requirement(req), self.constrained_reqs)

Expand Down
19 changes: 19 additions & 0 deletions tests/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,25 @@ async def test_install_non_pure_python_wheel(host_compat_layer):
await transaction.add_requirement(url)


@pytest.mark.parametrize(
"url",
[
"git+https://github.com/example/example.git",
"git+https://github.com/example/example.git@v1.0.0",
"hg+https://example.com/repo",
"svn+https://example.com/repo",
"bzr+https://example.com/repo",
],
)
@pytest.mark.asyncio
async def test_add_requirement_vcs_url_helpful_error(url, host_compat_layer):
from micropip.transaction import Transaction

transaction = create_transaction(Transaction, host_compat_layer)
with pytest.raises(ValueError, match="does not support installing from a VCS URL"):
await transaction.add_requirement(url)


def _pypi_metadata(package, versions_to_tags):
# Build package release metadata as would be returned from
# https://pypi.org/pypi/{pkgname}/json
Expand Down
Loading