Skip to content

Commit ea7e94b

Browse files
authored
Replace pre-commit by prek (#160427)
1 parent cc30add commit ea7e94b

10 files changed

Lines changed: 34 additions & 169 deletions

File tree

.github/copilot-instructions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,8 +847,8 @@ rules:
847847
## Development Commands
848848

849849
### Code Quality & Linting
850-
- **Run all linters on all files**: `pre-commit run --all-files`
851-
- **Run linters on staged files only**: `pre-commit run`
850+
- **Run all linters on all files**: `prek run --all-files`
851+
- **Run linters on staged files only**: `prek run`
852852
- **PyLint on everything** (slow): `pylint homeassistant`
853853
- **PyLint on specific folder**: `pylint homeassistant/components/my_integration`
854854
- **MyPy type checking (whole project)**: `mypy homeassistant/`

.github/workflows/ci.yaml

Lines changed: 22 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ env:
5959
# 15 is the latest version
6060
# - 15.2 is the latest (as of 9 Feb 2023)
6161
POSTGRESQL_VERSIONS: "['postgres:12.14','postgres:15.2']"
62-
PRE_COMMIT_CACHE: ~/.cache/pre-commit
6362
UV_CACHE_DIR: /tmp/uv-cache
6463
APT_CACHE_BASE: /home/runner/work/apt
6564
APT_CACHE_DIR: /home/runner/work/apt/cache
@@ -83,7 +82,6 @@ jobs:
8382
integrations_glob: ${{ steps.info.outputs.integrations_glob }}
8483
integrations: ${{ steps.integrations.outputs.changes }}
8584
apt_cache_key: ${{ steps.generate_apt_cache_key.outputs.key }}
86-
pre-commit_cache_key: ${{ steps.generate_pre-commit_cache_key.outputs.key }}
8785
python_cache_key: ${{ steps.generate_python_cache_key.outputs.key }}
8886
requirements: ${{ steps.core.outputs.requirements }}
8987
mariadb_groups: ${{ steps.info.outputs.mariadb_groups }}
@@ -111,11 +109,6 @@ jobs:
111109
hashFiles('requirements_all.txt') }}-${{
112110
hashFiles('homeassistant/package_constraints.txt') }}-${{
113111
hashFiles('script/gen_requirements_all.py') }}" >> $GITHUB_OUTPUT
114-
- name: Generate partial pre-commit restore key
115-
id: generate_pre-commit_cache_key
116-
run: >-
117-
echo "key=pre-commit-${{ env.CACHE_VERSION }}-${{
118-
hashFiles('.pre-commit-config.yaml') }}" >> $GITHUB_OUTPUT
119112
- name: Generate partial apt restore key
120113
id: generate_apt_cache_key
121114
run: |
@@ -244,8 +237,8 @@ jobs:
244237
echo "skip_coverage: ${skip_coverage}"
245238
echo "skip_coverage=${skip_coverage}" >> $GITHUB_OUTPUT
246239
247-
pre-commit:
248-
name: Prepare pre-commit base
240+
prek:
241+
name: Run prek checks
249242
runs-on: *runs-on-ubuntu
250243
needs: [info]
251244
if: |
@@ -254,147 +247,23 @@ jobs:
254247
&& github.event.inputs.audit-licenses-only != 'true'
255248
steps:
256249
- *checkout
257-
- &setup-python-default
258-
name: Set up Python ${{ env.DEFAULT_PYTHON }}
259-
id: python
260-
uses: &actions-setup-python actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
261-
with:
262-
python-version: ${{ env.DEFAULT_PYTHON }}
263-
check-latest: true
264-
- name: Restore base Python virtual environment
265-
id: cache-venv
266-
uses: &actions-cache actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
267-
with:
268-
path: venv
269-
key: &key-pre-commit-venv >-
270-
${{ runner.os }}-${{ runner.arch }}-${{ steps.python.outputs.python-version }}-venv-${{
271-
needs.info.outputs.pre-commit_cache_key }}
272-
- name: Create Python virtual environment
273-
if: steps.cache-venv.outputs.cache-hit != 'true'
274-
run: |
275-
python -m venv venv
276-
. venv/bin/activate
277-
python --version
278-
pip install "$(grep '^uv' < requirements.txt)"
279-
uv pip install "$(cat requirements_test.txt | grep pre-commit)"
280-
- name: Restore pre-commit environment from cache
281-
id: cache-precommit
282-
uses: *actions-cache
283-
with:
284-
path: ${{ env.PRE_COMMIT_CACHE }}
285-
lookup-only: true
286-
key: &key-pre-commit-env >-
287-
${{ runner.os }}-${{ runner.arch }}-${{ steps.python.outputs.python-version }}-${{
288-
needs.info.outputs.pre-commit_cache_key }}
289-
- name: Install pre-commit dependencies
290-
if: steps.cache-precommit.outputs.cache-hit != 'true'
291-
run: |
292-
. venv/bin/activate
293-
pre-commit install-hooks
294-
295-
lint-ruff-format:
296-
name: Check ruff-format
297-
runs-on: *runs-on-ubuntu
298-
needs: &needs-pre-commit
299-
- info
300-
- pre-commit
301-
steps:
302-
- *checkout
303-
- *setup-python-default
304-
- &cache-restore-pre-commit-venv
305-
name: Restore base Python virtual environment
306-
id: cache-venv
307-
uses: &actions-cache-restore actions/cache/restore@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
308-
with:
309-
path: venv
310-
fail-on-cache-miss: true
311-
key: *key-pre-commit-venv
312-
- &cache-restore-pre-commit-env
313-
name: Restore pre-commit environment from cache
314-
id: cache-precommit
315-
uses: *actions-cache-restore
316-
with:
317-
path: ${{ env.PRE_COMMIT_CACHE }}
318-
fail-on-cache-miss: true
319-
key: *key-pre-commit-env
320-
- name: Run ruff-format
321-
run: |
322-
. venv/bin/activate
323-
pre-commit run --hook-stage manual ruff-format --all-files --show-diff-on-failure
324-
env:
325-
RUFF_OUTPUT_FORMAT: github
326-
327-
lint-ruff:
328-
name: Check ruff
329-
runs-on: *runs-on-ubuntu
330-
needs: *needs-pre-commit
331-
steps:
332-
- *checkout
333-
- *setup-python-default
334-
- *cache-restore-pre-commit-venv
335-
- *cache-restore-pre-commit-env
336-
- name: Run ruff
337-
run: |
338-
. venv/bin/activate
339-
pre-commit run --hook-stage manual ruff-check --all-files --show-diff-on-failure
340-
env:
341-
RUFF_OUTPUT_FORMAT: github
342-
343-
lint-other:
344-
name: Check other linters
345-
runs-on: *runs-on-ubuntu
346-
needs: *needs-pre-commit
347-
steps:
348-
- *checkout
349-
- *setup-python-default
350-
- *cache-restore-pre-commit-venv
351-
- *cache-restore-pre-commit-env
352-
353250
- name: Register yamllint problem matcher
354251
run: |
355252
echo "::add-matcher::.github/workflows/matchers/yamllint.json"
356-
- name: Run yamllint
357-
run: |
358-
. venv/bin/activate
359-
pre-commit run --hook-stage manual yamllint --all-files --show-diff-on-failure
360-
361253
- name: Register check-json problem matcher
362254
run: |
363255
echo "::add-matcher::.github/workflows/matchers/check-json.json"
364-
- name: Run check-json
365-
run: |
366-
. venv/bin/activate
367-
pre-commit run --hook-stage manual check-json --all-files --show-diff-on-failure
368-
369-
- name: Run prettier (fully)
370-
if: needs.info.outputs.test_full_suite == 'true'
371-
run: |
372-
. venv/bin/activate
373-
pre-commit run --hook-stage manual prettier --all-files --show-diff-on-failure
374-
375-
- name: Run prettier (partially)
376-
if: needs.info.outputs.test_full_suite == 'false'
377-
shell: bash
378-
run: |
379-
. venv/bin/activate
380-
shopt -s globstar
381-
pre-commit run --hook-stage manual prettier --show-diff-on-failure --files {homeassistant,tests}/components/${{ needs.info.outputs.integrations_glob }}/{*,**/*}
382-
383256
- name: Register check executables problem matcher
384257
run: |
385258
echo "::add-matcher::.github/workflows/matchers/check-executables-have-shebangs.json"
386-
- name: Run executables check
387-
run: |
388-
. venv/bin/activate
389-
pre-commit run --hook-stage manual check-executables-have-shebangs --all-files --show-diff-on-failure
390-
391259
- name: Register codespell problem matcher
392260
run: |
393261
echo "::add-matcher::.github/workflows/matchers/codespell.json"
394-
- name: Run codespell
395-
run: |
396-
. venv/bin/activate
397-
pre-commit run --show-diff-on-failure --hook-stage manual codespell --all-files
262+
- name: Run prek
263+
uses: j178/prek-action@91fd7d7cf70ae1dee9f4f44e7dfa5d1073fe6623 # v1.0.11
264+
env:
265+
PREK_SKIP: no-commit-to-branch,mypy,pylint,gen_requirements_all,hassfest,hassfest-metadata,hassfest-mypy-config
266+
RUFF_OUTPUT_FORMAT: github
398267

399268
lint-hadolint:
400269
name: Check ${{ matrix.file }}
@@ -434,7 +303,7 @@ jobs:
434303
- &setup-python-matrix
435304
name: Set up Python ${{ matrix.python-version }}
436305
id: python
437-
uses: *actions-setup-python
306+
uses: &actions-setup-python actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
438307
with:
439308
python-version: ${{ matrix.python-version }}
440309
check-latest: true
@@ -447,7 +316,7 @@ jobs:
447316
env.HA_SHORT_VERSION }}-$(date -u '+%Y-%m-%dT%H:%M:%s')" >> $GITHUB_OUTPUT
448317
- name: Restore base Python virtual environment
449318
id: cache-venv
450-
uses: *actions-cache
319+
uses: &actions-cache actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
451320
with:
452321
path: venv
453322
key: &key-python-venv >-
@@ -562,7 +431,7 @@ jobs:
562431
steps:
563432
- &cache-restore-apt
564433
name: Restore apt cache
565-
uses: *actions-cache-restore
434+
uses: &actions-cache-restore actions/cache/restore@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
566435
with:
567436
path: *path-apt-cache
568437
fail-on-cache-miss: true
@@ -579,7 +448,13 @@ jobs:
579448
-o Dir::State::Lists=${{ env.APT_LIST_CACHE_DIR }} \
580449
libturbojpeg
581450
- *checkout
582-
- *setup-python-default
451+
- &setup-python-default
452+
name: Set up Python ${{ env.DEFAULT_PYTHON }}
453+
id: python
454+
uses: *actions-setup-python
455+
with:
456+
python-version: ${{ env.DEFAULT_PYTHON }}
457+
check-latest: true
583458
- &cache-restore-python-default
584459
name: Restore full Python ${{ env.DEFAULT_PYTHON }} virtual environment
585460
id: cache-venv
@@ -782,9 +657,7 @@ jobs:
782657
- base
783658
- gen-requirements-all
784659
- hassfest
785-
- lint-other
786-
- lint-ruff
787-
- lint-ruff-format
660+
- prek
788661
- mypy
789662
steps:
790663
- *cache-restore-apt
@@ -823,9 +696,7 @@ jobs:
823696
- base
824697
- gen-requirements-all
825698
- hassfest
826-
- lint-other
827-
- lint-ruff
828-
- lint-ruff-format
699+
- prek
829700
- mypy
830701
- prepare-pytest-full
831702
if: |
@@ -949,9 +820,7 @@ jobs:
949820
- base
950821
- gen-requirements-all
951822
- hassfest
952-
- lint-other
953-
- lint-ruff
954-
- lint-ruff-format
823+
- prek
955824
- mypy
956825
if: |
957826
needs.info.outputs.lint_only != 'true'
@@ -1066,9 +935,7 @@ jobs:
1066935
- base
1067936
- gen-requirements-all
1068937
- hassfest
1069-
- lint-other
1070-
- lint-ruff
1071-
- lint-ruff-format
938+
- prek
1072939
- mypy
1073940
if: |
1074941
needs.info.outputs.lint_only != 'true'
@@ -1202,9 +1069,7 @@ jobs:
12021069
- base
12031070
- gen-requirements-all
12041071
- hassfest
1205-
- lint-other
1206-
- lint-ruff
1207-
- lint-ruff-format
1072+
- prek
12081073
- mypy
12091074
if: |
12101075
needs.info.outputs.lint_only != 'true'

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ repos:
4646
# Run `python-typing-update` hook manually from time to time
4747
# to update python typing syntax.
4848
# Will require manual work, before submitting changes!
49-
# pre-commit run --hook-stage manual python-typing-update --all-files
49+
# prek run --hook-stage manual python-typing-update --all-files
5050
- id: python-typing-update
5151
stages: [manual]
5252
args:

.vscode/tasks.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
{
4646
"label": "Ruff",
4747
"type": "shell",
48-
"command": "pre-commit run ruff-check --all-files",
48+
"command": "prek run ruff-check --all-files",
4949
"group": {
5050
"kind": "test",
5151
"isDefault": true
@@ -57,9 +57,9 @@
5757
"problemMatcher": []
5858
},
5959
{
60-
"label": "Pre-commit",
60+
"label": "Prek",
6161
"type": "shell",
62-
"command": "pre-commit run --show-diff-on-failure",
62+
"command": "prek run --show-diff-on-failure",
6363
"group": {
6464
"kind": "test",
6565
"isDefault": true

pylint/plugins/hass_enforce_type_hints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
if TYPE_CHECKING:
1818
# InferenceResult is available only from astroid >= 2.12.0
19-
# pre-commit should still work on out of date environments
19+
# prek should still work on out of date environments
2020
from astroid.typing import InferenceResult
2121

2222
_COMMON_ARGUMENTS: dict[str, list[str]] = {

requirements_test.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ librt==0.2.1
1515
license-expression==30.4.3
1616
mock-open==1.4.0
1717
mypy-dev==1.19.0a4
18-
pre-commit==4.2.0
18+
prek==0.2.26
1919
pydantic==2.12.2
2020
pylint==4.0.1
2121
pylint-per-file-ignores==1.4.0

script/hassfest/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ def validate(integrations: dict[str, Integration], config: Config) -> None:
427427
if config.action == "generate" and manifests_resorted:
428428
subprocess.run(
429429
[
430-
"pre-commit",
430+
"prek",
431431
"run",
432432
"--hook-stage",
433433
"manual",

script/lint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ printf "%s\n" $files
1515
echo "=============="
1616
echo "LINT with ruff"
1717
echo "=============="
18-
pre-commit run ruff-check --files $files
18+
prek run ruff-check --files $files
1919
echo "================"
2020
echo "LINT with pylint"
2121
echo "================"

script/lint_and_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ async def pylint(files):
119119

120120
async def ruff(files):
121121
"""Exec ruff."""
122-
_, log = await async_exec("pre-commit", "run", "ruff", "--files", *files)
122+
_, log = await async_exec("prek", "run", "ruff", "--files", *files)
123123
res = []
124124
for line in log.splitlines():
125125
line = line.split(":")

script/setup

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fi
3131

3232
script/bootstrap
3333

34-
pre-commit install
34+
prek install
3535

3636
hass --script ensure_config -c config
3737

0 commit comments

Comments
 (0)