|
31 | 31 | "cell_type": "markdown", |
32 | 32 | "metadata": {}, |
33 | 33 | "source": [ |
34 | | - "One of my favorite tools is [pre-commit](https://pre-commit.com). It allows you to drive almost any \"fixer\" or \"linter\" available, all from one place. It handles environments and caching and even updates for you.\n", |
| 34 | + "One of my favorite tools is [pre-commit](https://pre-commit.com) / [prek](https://prek.j178.dev) (faster). It allows you to drive almost any \"fixer\" or \"linter\" available, all from one place. It handles environments and caching and even updates for you.\n", |
35 | 35 | "\n", |
36 | 36 | "To configure, add a `.pre-commit-config.yaml` file like this:\n", |
37 | 37 | "\n", |
38 | 38 | "```yaml\n", |
39 | 39 | "repos:\n", |
40 | 40 | "# Some \"common\" checks useful for almost any repo\n", |
41 | 41 | "- repo: https://github.com/pre-commit/pre-commit-hooks\n", |
42 | | - " rev: v4.4.0\n", |
| 42 | + " rev: \"v6.0.0\"\n", |
43 | 43 | " hooks:\n", |
44 | 44 | " - id: check-added-large-files\n", |
45 | 45 | " - id: check-case-conflict\n", |
|
53 | 53 | " - id: trailing-whitespace\n", |
54 | 54 | "\n", |
55 | 55 | "# Automatically format Python code\n", |
56 | | - "- repo: https://github.com/psf/black\n", |
57 | | - " rev: \"23.7.0\"\n", |
| 56 | + "- repo: https://github.com/astral-sh/ruff-pre-commit\n", |
| 57 | + " rev: \"v0.14.11\"\n", |
58 | 58 | " hooks:\n", |
59 | | - " - id: black\n", |
| 59 | + " - id: ruff-format\n", |
60 | 60 | "```\n", |
61 | 61 | "\n", |
62 | 62 | "The file has a list of repos (local checks can be written too). Each repo contains pre-commit hooks that you can run and configure. You should put modifying \"fixer\" checks before the \"linter\" checks, just in case they fix something that then gets linted." |
|
66 | 66 | "cell_type": "markdown", |
67 | 67 | "metadata": {}, |
68 | 68 | "source": [ |
69 | | - "You can install pre-commit from `brew` (macOS), or via `pipx`/`pip` for anything with Python.\n", |
| 69 | + "You can install pre-commit or prek from `brew` (macOS), or via `uv`/`pipx`/`pip` for anything with Python.\n", |
70 | 70 | "\n", |
71 | 71 | "You can then run it like this:\n", |
72 | 72 | "\n", |
73 | 73 | "```bash\n", |
| 74 | + "# Pick one\n", |
74 | 75 | "pre-commit run -a\n", |
| 76 | + "prek -a\n", |
75 | 77 | "```\n", |
76 | 78 | "\n", |
77 | 79 | "That will check everything. You don't need to know anything about how to run the checkers or linters, it's a single standard interface for all projects. Each hook gets a unique, cached environment, so the next time you run it, it's lightning fast. If you leave off the `-a`, it _only checks the changed files in your staging area, even partially staged ones!_.\n", |
78 | 80 | "\n", |
79 | 81 | "If you want to update to the latest versions of all your hooks, run:\n", |
80 | 82 | "\n", |
81 | 83 | "```bash\n", |
| 84 | + "# Pick one\n", |
82 | 85 | "pre-commit autoupdate\n", |
| 86 | + "prek auto-update\n", |
83 | 87 | "```\n", |
84 | 88 | "\n", |
85 | 89 | "If you want to use it in the namesake \"pre-commit\" mode, then run:\n", |
86 | 90 | "\n", |
87 | 91 | "```bash\n", |
| 92 | + "# Pick one\n", |
88 | 93 | "pre-commit install\n", |
| 94 | + "prek install\n", |
89 | 95 | "```\n", |
90 | 96 | "\n", |
91 | 97 | "Now it runs before every commit, and you'll never check in \"bad\" code again! Use `-n` to skip the pre-commit check when committing for emergencies.\n", |
|
126 | 132 | " runs-on: [ubuntu-latest, macos-latest, windows-latest]\n", |
127 | 133 | "\n", |
128 | 134 | " steps:\n", |
129 | | - " - uses: actions/checkout@v3\n", |
| 135 | + " - uses: actions/checkout@v6\n", |
130 | 136 | " \n", |
131 | | - " - name: actions/setup-python@v4\n", |
| 137 | + " - name: actions/setup-python@v6\n", |
132 | 138 | " with:\n", |
133 | 139 | " python-version: ${{ matrix.python-version }}\n", |
134 | 140 | " \n", |
135 | 141 | " - name: Install with dev requirements\n", |
136 | | - " run: pip install -e .[dev]\n", |
| 142 | + " run: pip install -e . --group=dev\n", |
137 | 143 | "\n", |
138 | 144 | " - name: Test with pytest\n", |
139 | 145 | " run: pytest\n", |
|
0 commit comments