Invalidate import caches after installing plugin dependencies #2494
All Vouch review confidence checks passed
Residual risk 0.23 = Change Risk (0.40) × (1 − Review Confidence (0.43)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 319 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.345
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #2494"
general
weight: 0.35
cjames23
Fixes #2493
Cause
ensure_plugin_dependencieschecks the requirements withInstalledDistributions, which goes throughimportlib.metadata. That caches the listing of eachsys.pathdirectory, keyed on the directory's mtime. Afteruv pip install, pluggy'sload_setuptools_entrypointsreads the same cache, so if the mtime ofsite-packagesdid not change, the new plugin stays invisible until the next run.On macOS, uv's default link mode is
clone, and cloning files into a directory on APFS does not update the directory's mtime. uv then sets the mtime itself, but that needs ownership of the directory, and a python.org framework install has aroot:admin, group-writablesite-packages. The call fails and uv only logs it at debug level (Failed to update mtime ... Permission deniedwithuv -v). pip always changed the mtime, which is why this started in 1.18.0.Fix
Call
importlib.invalidate_caches()after the install. It only clears theimportlib.metadatacache from Python 3.11, so on 3.10 it also callsMetadataPathFinder().invalidate_caches()(on an instance, because in 3.10 that method is not a classmethod).The new test in
tests/cli/env/test_find.pyhas the mocked install write a module and a.dist-infothat registers a new environment type into a directory onsys.path, then restores the directory's mtime.hatch env findhas to find the new type on the first run.Verification
pyproject.tomlfrom the issue, using an ACL sosite-packagesis writable but its times can't be set (chmod +a "user:$(whoami) deny writeattr" .../site-packages). hatch 1.18.2 and master (893fa13) fail the first run with `Environmentdefaulthas unknown type: pip-compileon Python 3.13 and 3.10. This branch works on both.tests that need Docker, andtest_new_selected_pythonandtest_creation_allow_system_packages, which fail the same way on master on my machine (a python.org 2.7 ispythononPATH).andhatch run types:check` pass.Changelog entry added under Unreleased.
AI disclosure
Made with Claude Code (Anthropic). It traced the cause, reproduced the bug, wrote the fix, the test, the changelog entry and this description, and ran the checks. I went through the cause and the change before submitting.
🤖 Generated with Claude Code