Feature request: Support installing hooks from pypi #1925
Copy link
Copy link
Closed
Labels
ideaJust an ideaJust an idea
Description
Activity
Interesting idea, but it’d take a fair bit of refactoring. I’ll think it through.
Reacted by Stephen Finucane, Sean Mooney and Marco Edward GorelliThanks for taking a look at this 🙏 Would you be open to a PR (or rather, series of PRs) that attempted to tackle this? My rust-fu is still so-so, but I believe virtually all of the required functionality (mainly creating and caching Python venvs) is already implemented or would be easy to do with the
uvwrappers (inspecting data files), meaning this would mainly be a refactoring exercise. I think this could be broken up into a few steps:- Rename the
Repoenum incrates/prek/src/hook.rstoPlugin, then rename theRemotevariant toGitandRemoteRepostruct toGitPlugin. Also rename the other*Repostructs to*Plugin. - Add a new helper to install a package and extract the hooks.
I don't know if this should go in e.g.crates/prek/src/languages/python/pypi_package.rsalongside other Python/uv'y things or in the root src dir atcrates/prek/src/pypi.rslikegit.rs. We could also create a new directory likecrates/prek/src/plugin_loadersand movegit.rshere? - Add a new
Plugin::PypiPackage(PypiPackagePlugin)variant. To avoid reworking existing.pre-commit-config.yaml/pryk.tomlfiles this could initially be exposed via a newpypi_package:prefix, e.g.Note that we'll only accept exact package versions to ease caching and make things deterministic.- repo: pypi_package:ruff rev: "0.16.0" hooks: - id: ruff-format
- Add caching support. We can cache on the package name and rev. Ditto for auto-update, which can be implemented using
uv.
I believe the changes to
pryk.yaml(and.pre-commit-hooks.yaml? I'm not sure if we plan to evolve this in the long-term) could be done in parallel/isolation.- Rename the
- Repository owner locked and limited conversation to collaborators
on Aug 9, 2026
Metadata
Metadata
Assignees
Labels
ideaJust an ideaJust an idea
prek, likepre-commit, uses git repos as the main "distribution mechanism" for.pre-commit-hooks.yamlfiles. The main disadvantage of this approach is that git repos don't generally contain built source. Instead, you must build the binary yourself. How this is achieved varies depending on the package.Python packages on PyPI can be used to distribute non-Python binaries (e.g. cmake). This appears to be specific to PyPI and the likes of Cargo or Maven don't appear to support this. Binaries provided this way don't need to be built, avoiding the need for hacks like https://github.com/astral-sh/ruff-pre-commit/. In addition, Python packages provide the ability to distribute files like
.pre-commit-hooks.yaml(via data files).Would it be possible to support installation of hooks from PyPI, perhaps with changes to
prek.tomllike below?We may wish to build on this further to add support for distributing plugins via other mechanisms that are well suited to binary distribution (GitHub Releases?) but that's out-of-scope for here.