Skip to content

Commit 77942c4

Browse files
authored
🐛 fix(venv): seed pip into hook environments (#114)
uv venv does not install pip by default, unlike python -m venv. Hooks like mypy that internally call `python -m pip install` to fetch type stubs fail with "No module named pip" in the created environment. Passing --seed to uv venv restores pip/setuptools availability, matching standard venv behavior and fixing hooks that depend on pip at runtime. Fixes #61
1 parent 47cf4d0 commit 77942c4

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/pre_commit_uv/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def _install_environment(
7474
"--project",
7575
project_root_dir,
7676
"venv",
77+
"--seed",
7778
environment_dir(prefix, python.ENVIRONMENT_DIR, version),
7879
"-p",
7980
py,

tests/test_main.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,21 @@ def test_install(git_repo: Path, caplog: pytest.LogCaptureFixture, monkeypatch:
6868
]
6969

7070

71+
def test_install_seeds_pip(git_repo: Path, monkeypatch: pytest.MonkeyPatch) -> None:
72+
monkeypatch.setenv("FORCE_PRE_COMMIT_UV_PATCH", "1")
73+
74+
import pre_commit_uv # noqa: PLC0415
75+
76+
pre_commit_uv._patch() # noqa: SLF001
77+
main.main(["install-hooks", "-c", str(git_repo / precommit_file)])
78+
79+
env_dirs = list((git_repo / "store").rglob("py_env-*"))
80+
assert env_dirs, "expected at least one hook environment"
81+
py = next((env_dirs[0] / "bin").glob("python*"))
82+
result = check_output([str(py), "-c", "import pip"], encoding="utf-8")
83+
assert not result
84+
85+
7186
test_install_with_uv_config_cases: list[tuple[str, str]] = [
7287
(
7388
"pyproject.toml",

0 commit comments

Comments
 (0)