You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's not super pretty and the pre-commit configuration is very verbose but this is the best i could think of when using pre-commit.
IMO it's still better this way as I strongly believe that pre-commit is the wrong tool to think about your linter dependency versions.
I'm thinking about creating a pre-commit replacement (independent of pixi, though) at some point in the future that makes it easier to define language: system hooks.
Hey @pavelzw, I like the idea, but it's not a great look with the required pixi install requirement. Would you be okay with removing the documentation from this pr. Then I think we can merge the PR and add it back through another when #1482 is fixed. I like to dogfood but I wouldn't recommend this use case to everyone yet as it requires some understanding of the limitations of pixi.
part: pixi
title: Pre-commit
description: Using pre-commit with pixi
Pre-commit is a tool for managing and maintaining tools that run before a commit is made.
It is widely used to ensure that code is formatted correctly, that there are no syntax errors, and that the code is linted.
Pre-commit uses a configuration file called .pre-commit-config.yaml to define all pre-commit hooks that should be run.
They usually point to a repository that contains the hook and the version of the hook that should be used.
Since pixi already handles your dependencies, it might make sense for you to instead use pixi in combination with pixi run to manage your pre-commit hooks.
For this, you can define a local repository and specify the hook you want to use there.
Pre-commit doesn't take .gitignore into account when running pre-commit run -a.
This hook is a workaround for an issue with pixi. It ensures that the pixi environments are up to date before running the other hooks.
For more information, see #1482.
This has the advantage that you only have one place where you specify your dependency versions instead of having to manage them in multiple places.
Thus, you don't have to worry about keeping the .pre-commit-config.yaml up to date with the latest versions of the hooks since pixi update can do that for you.
Since you use a local repository, you also don't need to rely on downloading the hook definitions from the internet which can be useful in corporate environments.
Also, this doesn't require pre-commit to first install isolated environments for each hook, which can be time-consuming.
!!!tip "Adding new hooks"
When you want to convert a "classical" pre-commit hook (i.e. defined in some repository) to a pixi hook, you can use the following steps:
1. Open the URL of the repository of this hook, for example <https://github.com/astral-sh/ruff-pre-commit>.
2. Take a look at `.pre-commit-hooks.yaml`.
3. Copy the hook that you want to use and prefix the `entry` with `pixi run -e lint`. Also, change the `language` from `python`, `conda`, etc. to `system` to ensure that pre-commit doesn't try to install an isolated environment for this hook.
4. Ensure that the dependencies needed (e.g. `ruff`) are specified in your `pixi.toml` in the `lint` feature.
For these hooks to be available, you need to specify them in your pixi.toml:
You can install the pre-commit hooks by running pixi run pre-commit-install and manually run them using pixi run pre-commit-run.
Running pre-commit hooks in CI
As this workflow requires pixi to be installed, you cannot use it in combination with pre-commit.ci.
Instead, you can use the following script to run the pre-commit hooks in your CI:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It's not super pretty and the pre-commit configuration is very verbose but this is the best i could think of when using pre-commit.
IMO it's still better this way as I strongly believe that pre-commit is the wrong tool to think about your linter dependency versions.
I'm thinking about creating a pre-commit replacement (independent of pixi, though) at some point in the future that makes it easier to define
language: systemhooks.xref #1482