Add upgrade suggestion option in config#1490
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1490 +/- ##
==========================================
- Coverage 91.51% 91.41% -0.10%
==========================================
Files 87 87
Lines 18153 18210 +57
==========================================
+ Hits 16612 16647 +35
- Misses 1541 1563 +22 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
📦 Cargo Bloat ComparisonBinary size change: +0.00% (22.5 MiB → 22.5 MiB) Expand for cargo-bloat outputHead Branch ResultsBase Branch Results |
|
Thanks for working on this. We’re pretty careful about adding new options, and I don’t think |
|
Makes sense that you don't want to bloat prek with new options here. Maybe to clarify the motivation a bit. When using prek on a large project, you typically have a well defined and automated way to setup a developers's environment. With that, we exactly know how developers have installed prek, so being able to give them a concrete command to run would be very useful. Now if we think about "the config writer doesn’t actually know how prek is installed on the user’s side", would it be possible to get to know this? Because if we would know this somehow, we would not need the |
We could try using a heuristic to detect it — for example, if the current executable is in something like |
|
If you run The main motivation here is that if prek is managed by some repository automation, developers might not know how prek was installed. So if the minimum prek version gets increased they have to figure out first how to update prek. One alternative to adding this to the config would be an environment variable, but not sure if this is an improvement to the current approach 🤔 . |
|
I tried adding an optional upgrade hint after the version using a semicolon in #1536 , like this: minimum_prek_version: '0.2.0; Use `brew upgrade` to upgrade prek'What do you think? |
@j178 I like it. This option also came to my mind, but I was not sure if I could propose it or if it seems too much of an abuse of the version. So let's do that then. Thanks you! |
|
I think we should revert #1536. By modifying the type and behavior of The purpose of MRE: minimum_prek_version: '0.2.0; Use brew upgrade to upgrade prek'
repos:
- repo: local
hooks:
- id: test
name: test
entry: echo hi
language: system$ uvx [email protected] run -a
error: Failed to parse `.pre-commit-config.yaml`
caused by: unexpected character ';' after patch version numberNote that prek 0.3.0 is greater than In summary:
More broadly, I agree with @j178's earlier point:
@hofbi I do agree this is a meaningful issue; I think we all can make the experience a bit better: Individual projects:
Hook maintainers:
prek itself:
uv, for example, detects Homebrew installations by inspecting the executable path for $ uv self update
error: uv was installed through an external package manager and cannot update itself.
hint: You installed uv using Homebrew. To update uv, run `brew update && brew upgrade uv`prek could take a similar approach. When $ prek self update
error: prek was installed through an external package manager, and self-update is not available.
Please use your package manager to update prek.We could enhance this to detect Homebrew and suggest $ prek run -a
error: Required minimum prek version `0.4.0` is greater than current version `0.3.1`.
Please consider updating prek.We could further suggest the appropriate upgrade command based on detected install method. We could start conservatively with path heuristics (e.g., |
|
I will try to get started on a PR for Homebrew and cargo detection... |
Detects how prek was installed (Homebrew or Cargo) by inspecting the executable path, then provides actionable upgrade hints when: - `prek self update` fails because prek wasn't installed via standalone scripts - `minimum_prek_version` isn't satisfied Based largely on the approach uv implemented in [astral-sh/uv#16838](astral-sh/uv#16838). Detection heuristics: - Homebrew: path contains `/Cellar/prek/` - Cargo: path contains `/.cargo/bin/` Example output: ```console error: prek was installed via an external package manager and cannot self-update. hint: You installed prek via Homebrew. To update, run brew update && brew upgrade prek ``` See discussion in #1490 for further context. --------- Co-authored-by: Jo <[email protected]>
Currently if the minimum prek version does not match, a user sees something like
It would be nice to give the user a more concrete action to fix this error. To do so, I am adding an optional filed to the config named
prek_upgrade_suggestion. This allows specifying an extra message likePlease run 'uv tool install prek'orPlease run prek self upgradewhich is shown on top of the error message above.