Retry uv pip install with an inferred Python constraint - #2396
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2396 +/- ##
==========================================
- Coverage 93.38% 93.31% -0.08%
==========================================
Files 129 129
Lines 27637 27774 +137
==========================================
+ Hits 25810 25917 +107
- Misses 1827 1857 +30 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR improves the Python hook installation flow by adding a targeted fallback when uv pip install fails due to the venv Python being too old for a (possibly transitive) dependency. It infers a minimum required Python version from uv’s resolution error output, recreates the venv using that inferred constraint, and retries dependency installation once.
Changes:
- Refactors Python dependency installation into a dedicated
install_dependencieshelper and adds a single-retry path on resolution failure. - Implements
infer_python_request(stderr)to extract the highestPython>=X.Y[.Z]bound from uv’s error output and converts it into amajor.minorPython request. - Adds unit tests validating that inference selects the highest bound and drops patch versions.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 324ee60c15
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
📦 Cargo Bloat ComparisonBinary size change: +0.34% (29.2 MiB → 29.3 MiB) Expand for cargo-bloat outputHead Branch ResultsBase Branch Results |
⚡️ Hyperfine BenchmarksSummary: 0 regressions, 0 improvements above the 10% threshold. Environment
CLI CommandsBenchmarking basic commands in the main repo:
|
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base --version |
1.8 ± 0.1 | 1.7 | 2.6 | 1.04 ± 0.10 |
prek-head --version |
1.7 ± 0.1 | 1.6 | 2.6 | 1.00 |
prek list
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base list |
8.1 ± 0.2 | 7.8 | 8.6 | 1.03 ± 0.03 |
prek-head list |
7.9 ± 0.1 | 7.6 | 8.2 | 1.00 |
prek validate-config .pre-commit-config.yaml
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base validate-config .pre-commit-config.yaml |
2.7 ± 0.1 | 2.6 | 2.9 | 1.03 ± 0.04 |
prek-head validate-config .pre-commit-config.yaml |
2.7 ± 0.1 | 2.5 | 2.9 | 1.00 |
prek sample-config
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base sample-config |
2.1 ± 0.1 | 1.9 | 2.2 | 1.01 ± 0.04 |
prek-head sample-config |
2.1 ± 0.1 | 1.9 | 2.2 | 1.00 |
Cold vs Warm Runs
Comparing first run (cold) vs subsequent runs (warm cache):
prek run --all-files (cold - no cache)
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run --all-files |
45.5 ± 1.0 | 44.0 | 47.2 | 1.00 |
prek-head run --all-files |
45.6 ± 1.2 | 43.9 | 47.6 | 1.00 ± 0.03 |
prek run --all-files (warm - with cache)
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run --all-files |
45.5 ± 0.9 | 44.0 | 47.6 | 1.00 ± 0.03 |
prek-head run --all-files |
45.4 ± 0.9 | 43.4 | 47.0 | 1.00 |
Full Hook Suite
Running the builtin hook suite on the benchmark workspace:
prek run --all-files (full builtin hook suite)
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run --all-files |
45.8 ± 0.6 | 44.7 | 46.9 | 1.00 |
prek-head run --all-files |
46.2 ± 1.1 | 44.8 | 51.1 | 1.01 ± 0.03 |
Individual Hook Performance
Benchmarking each hook individually on the test repo:
prek run trailing-whitespace --all-files
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run trailing-whitespace --all-files |
14.1 ± 0.2 | 13.8 | 14.5 | 1.00 |
prek-head run trailing-whitespace --all-files |
14.1 ± 0.4 | 13.5 | 15.0 | 1.00 ± 0.03 |
prek run end-of-file-fixer --all-files
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run end-of-file-fixer --all-files |
13.9 ± 0.4 | 13.0 | 14.9 | 1.02 ± 0.05 |
prek-head run end-of-file-fixer --all-files |
13.7 ± 0.5 | 12.7 | 14.7 | 1.00 |
prek run check-json --all-files
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run check-json --all-files |
5.8 ± 0.2 | 5.5 | 6.2 | 1.01 ± 0.05 |
prek-head run check-json --all-files |
5.8 ± 0.2 | 5.5 | 6.3 | 1.00 |
prek run check-yaml --all-files
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run check-yaml --all-files |
5.9 ± 0.1 | 5.7 | 6.2 | 1.02 ± 0.04 |
prek-head run check-yaml --all-files |
5.8 ± 0.2 | 5.5 | 6.1 | 1.00 |
prek run check-toml --all-files
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run check-toml --all-files |
5.8 ± 0.2 | 5.3 | 6.2 | 1.03 ± 0.05 |
prek-head run check-toml --all-files |
5.7 ± 0.2 | 5.2 | 6.1 | 1.00 |
prek run check-xml --all-files
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run check-xml --all-files |
5.7 ± 0.2 | 5.4 | 6.0 | 1.01 ± 0.04 |
prek-head run check-xml --all-files |
5.6 ± 0.2 | 5.3 | 6.0 | 1.00 |
prek run detect-private-key --all-files
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run detect-private-key --all-files |
8.3 ± 0.5 | 7.4 | 9.9 | 1.05 ± 0.08 |
prek-head run detect-private-key --all-files |
7.9 ± 0.4 | 7.4 | 8.6 | 1.00 |
prek run fix-byte-order-marker --all-files
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run fix-byte-order-marker --all-files |
13.7 ± 0.4 | 13.1 | 14.6 | 1.00 |
prek-head run fix-byte-order-marker --all-files |
13.7 ± 0.5 | 12.8 | 14.5 | 1.00 ± 0.04 |
Installation Performance
Benchmarking hook installation (fast path hooks skip Python setup):
prek install-hooks (cold - no cache)
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base install-hooks |
3.7 ± 0.1 | 3.7 | 3.8 | 1.00 |
prek-head install-hooks |
3.9 ± 0.2 | 3.7 | 4.1 | 1.04 ± 0.05 |
prek install-hooks (warm - with cache)
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base install-hooks |
3.7 ± 0.1 | 3.6 | 3.8 | 1.02 ± 0.04 |
prek-head install-hooks |
3.6 ± 0.1 | 3.6 | 3.9 | 1.00 |
File Filtering/Scoping Performance
Testing different file selection modes:
prek run (staged files only)
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run |
25.8 ± 0.4 | 25.0 | 26.4 | 1.01 ± 0.02 |
prek-head run |
25.7 ± 0.4 | 25.2 | 26.6 | 1.00 |
prek run --files '*.json' (specific file type)
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run --files '*.json' |
5.9 ± 0.1 | 5.7 | 6.1 | 1.02 ± 0.02 |
prek-head run --files '*.json' |
5.8 ± 0.1 | 5.6 | 6.0 | 1.00 |
Workspace Discovery & Initialization
Benchmarking hook discovery and initialization overhead:
prek run --dry-run --all-files (measures init overhead)
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run --dry-run --all-files |
5.3 ± 0.2 | 5.1 | 5.7 | 1.01 ± 0.04 |
prek-head run --dry-run --all-files |
5.3 ± 0.1 | 5.1 | 5.4 | 1.00 |
Meta Hooks Performance
Benchmarking meta hooks separately:
prek run check-hooks-apply --all-files
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run check-hooks-apply --all-files |
8.9 ± 0.2 | 8.6 | 9.3 | 1.00 ± 0.03 |
prek-head run check-hooks-apply --all-files |
8.9 ± 0.2 | 8.7 | 9.2 | 1.00 |
prek run check-useless-excludes --all-files
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run check-useless-excludes --all-files |
8.6 ± 0.4 | 8.1 | 9.0 | 1.06 ± 0.05 |
prek-head run check-useless-excludes --all-files |
8.1 ± 0.1 | 7.9 | 8.3 | 1.00 |
prek run identity --all-files
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
prek-base run identity --all-files |
7.4 ± 0.1 | 7.3 | 7.6 | 1.00 |
prek-head run identity --all-files |
7.5 ± 0.2 | 7.3 | 7.8 | 1.01 ± 0.02 |
324ee60 to
4eb0dbb
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4eb0dbb3af
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
4eb0dbb to
c1dc7ef
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c1dc7efc01
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
c1dc7ef to
54a7ae3
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 54a7ae32af
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
54a7ae3 to
141471d
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 141471deb6
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
When `uv pip install` fails to resolve because the venv's Python is too old for a (possibly transitive) dependency, parse the required Python version from uv's error, recreate the venv with that constraint, and retry once. Closes j178#1618.
141471d to
b426e22
Compare
| // `request_permits` only accepts an exact-pin original when `bound` already equals it. | ||
| LanguageRequest::Python(PythonRequest::MajorMinorPatch(..)) => { | ||
| comparators = vec![format!("={bound}")]; | ||
| } |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b426e2282e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| /// compatibility check against the hook's original request stays sound (e.g. against `<3.11.2`). | ||
| fn infer_python_request(stderr: &[u8]) -> Option<semver::Version> { | ||
| static PYTHON_BOUND: LazyLock<Regex> = | ||
| LazyLock::new(|| Regex::new(r"Python\s*>=?\s*(\d+\.\d+(?:\.\d+)?)").unwrap()); |
There was a problem hiding this comment.
Preserve strict Python lower bounds on retry
When uv reports a strict lower bound such as Python>3.10.20, this pattern matches it but only captures the version; the retry request is then built as >=3.10.20. If the failed interpreter is exactly 3.10.20 and remains discoverable, recreating the venv can succeed with the same interpreter, so the second pip install fails again instead of selecting or downloading a Python that actually satisfies the dependency.
Useful? React with 👍 / 👎.
When
uv pip installfails to resolve because the venv's Python is too old for a (possibly transitive) dependency, parse the required Python version from uv's error, recreate the venv with that constraint, and retry once.Closes #1618.