Skip to content

Commit 103c6fe

Browse files
authored
Raise a helpful error for VCS URLs in install() (#277)
Closes #77.
1 parent 821b437 commit 103c6fe

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## Unreleased
88

9+
### Changed
10+
11+
- `install` now raises a helpful `ValueError` when given a VCS URL
12+
(`git+`, `hg+`, `svn+`, `bzr+`) instead of an opaque parser error,
13+
explaining that micropip only installs prebuilt wheels.
14+
[#77](https://github.com/pyodide/micropip/issues/77)
15+
916
## [0.11.1] - 2026/04/02
1017

1118
### Fixed

micropip/transaction.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626

2727
logger = logging.getLogger("micropip")
2828

29+
_VCS_URL_PREFIXES = ("git+", "hg+", "svn+", "bzr+")
30+
31+
32+
def _looks_like_vcs_url(req: str) -> bool:
33+
return req.startswith(_VCS_URL_PREFIXES)
34+
2935

3036
@dataclass
3137
class Transaction:
@@ -77,6 +83,14 @@ async def add_requirement(self, req: str | Requirement) -> None:
7783
if isinstance(req, Requirement):
7884
return await self.add_requirement_inner(req)
7985

86+
if isinstance(req, str) and _looks_like_vcs_url(req):
87+
raise ValueError(
88+
f"Cannot install {req!r}: micropip only installs prebuilt wheels "
89+
"and does not support installing from a VCS URL "
90+
"(git+, hg+, svn+, bzr+). Provide a wheel URL or a package name "
91+
"available on a configured index."
92+
)
93+
8094
try:
8195
as_req = constrain_requirement(Requirement(req), self.constrained_reqs)
8296

tests/test_transaction.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,25 @@ async def test_install_non_pure_python_wheel(host_compat_layer):
154154
await transaction.add_requirement(url)
155155

156156

157+
@pytest.mark.parametrize(
158+
"url",
159+
[
160+
"git+https://github.com/example/example.git",
161+
"git+https://github.com/example/example.git@v1.0.0",
162+
"hg+https://example.com/repo",
163+
"svn+https://example.com/repo",
164+
"bzr+https://example.com/repo",
165+
],
166+
)
167+
@pytest.mark.asyncio
168+
async def test_add_requirement_vcs_url_helpful_error(url, host_compat_layer):
169+
from micropip.transaction import Transaction
170+
171+
transaction = create_transaction(Transaction, host_compat_layer)
172+
with pytest.raises(ValueError, match="does not support installing from a VCS URL"):
173+
await transaction.add_requirement(url)
174+
175+
157176
def _pypi_metadata(package, versions_to_tags):
158177
# Build package release metadata as would be returned from
159178
# https://pypi.org/pypi/{pkgname}/json

0 commit comments

Comments
 (0)