Skip to content

Commit 863a8f2

Browse files
committed
Add ty type checking to CI and pre-commit
- Add ty to the dev dependency group (pinned via uv.lock at 0.0.51). - lint.yml: new parallel `ty` job running `uv run ty check custom_components/` so ty type-checks against the integration's installed dependencies (the fast `uvx ruff` job stays project-sync-free). - .pre-commit-config.yaml: add ty as a local hook (`uv run ty check`) using the same project env; the official ty-pre-commit hook runs in an isolated env without the project's deps and would report false unresolved imports.
1 parent d91fe1b commit 863a8f2

4 files changed

Lines changed: 58 additions & 0 deletions

File tree

.github/workflows/lint.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,21 @@ jobs:
3030

3131
- name: Format
3232
run: uvx ruff format . --check
33+
34+
ty:
35+
name: "ty"
36+
runs-on: "ubuntu-latest"
37+
steps:
38+
- name: Checkout the repository
39+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
40+
41+
- name: Set up uv
42+
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
43+
with:
44+
enable-cache: true
45+
46+
# ty needs the integration's dependencies to resolve imports, so run it
47+
# through `uv run` (which syncs the project's .venv first). The version is
48+
# pinned via the dev dependency group in uv.lock.
49+
- name: Type check
50+
run: uv run ty check custom_components/

.pre-commit-config.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,15 @@ repos:
77
- id: ruff-check
88
args: ["--fix", "--unsafe-fixes", "--show-fixes"]
99
- id: ruff-format
10+
- repo: local
11+
hooks:
12+
- id: ty
13+
name: ty
14+
# Run ty from the uv project so it type-checks against the
15+
# integration's installed dependencies (resolved via .venv). Uses the
16+
# ty version pinned in the dev dependency group / uv.lock.
17+
entry: uv run ty check custom_components/
18+
language: system
19+
types: [python]
20+
pass_filenames: false
21+
require_serial: true

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dev = [
1919
"pip>=21.3.1",
2020
"pre-commit>=4.5.0",
2121
"ruff>=0.15",
22+
"ty>=0.0.51",
2223
]
2324

2425
# This is a Home Assistant / HACS integration, not a Python package: HACS ships

uv.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)