6.1 pre-commit, in the group lint

Build it yourself. Read the tutorial is the other way to read this part.

This walk goes through rahuldave/cheesecracker on GitHub. This part starts from the code at step-05. The code before this part

This part does not start where the part before it ends, because the walk skips some changes. This command puts the files that this part starts from in place of yours. Run it, and then go on:

git fetch --quiet --tags --force origin; git restore --source 9662828462ba --staged -- :/ && git restore --source step-05 --staged --worktree -- :/

If you start at this part, make your clone as Get the project says, and then run this command. It puts in your clone the files that this part starts from. A file that the project deleted before this part stays, so delete it if git check lists it:

git fetch --quiet --tags --force origin; git rm -rq --cached --ignore-unmatch -- :/ && git restore --source step-05 --staged --worktree -- :/
just setup

The whole tutorial then sets up ruff, and fixes the code with it. pre-commit runs the checks before every commit, so it joins ruff in the group lint.

6.1 pre-commit, in the group lint

pre-commit runs checks on the files of a commit, before git makes it. pre-commit calls each check a hook. git has hooks of its own, scripts that it runs before a commit, and a later move installs one of them to start pre-commit.

.pre-commit-config.yaml names the repository that each hook comes from, and the exact version to use. The first time pre-commit runs, it downloads each hook and installs it in a folder of its own. A failed check stops the commit. If a hook fixes a file, the commit stops too, and the fixed file waits for git add before the next try.

pre-commit checks the code, and the server does not need it to run. So it goes into the group lint, with ruff.

uv add --group lint pre-commit
uv run pre-commit --version

uv prints the version of pre-commit.

Check your files against this move. The command prints nothing when they match, and otherwise shows what differs:

git check f3ad230bf911

If you are stuck, this command puts the files of this move in place of yours. A file that you made yourself stays:

git fetch --quiet --tags --force origin; git restore --source step-05 --staged -- :/ && git restore --source f3ad230bf911 --staged --worktree -- :/

What changed

  • pyproject.toml: pre-commit, in the group lint. 1 line added. It comes from uv add --group lint pre-commit. The file
    • look at "pre-commit>=4.7.0",
  • uv.lock: the exact versions of pre-commit, and of the packages that it needs. 149 lines added, 1 removed. It comes from uv add --group lint pre-commit. The file

The diff that uv add --group lint pre-commit makes in pyproject.toml
@@ -17,6 +17,7 @@ default-groups = "all"
 
 [dependency-groups]
 lint = [
+    "pre-commit>=4.7.0",
     "ruff>=0.17.1",
 ]
 test = [

This change on GitHub

This part ends at the code at f3ad230bf911, partway through step-06. The code after this part