Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
repos:
- repo: local
hooks:
- id: sync-ha-version
name: Sync HA version from hacs.json
entry: python scripts/sync_ha_version.py
language: system
pass_filenames: false
files: ^(hacs\.json|requirements_dev\.txt)$
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
Expand Down
2 changes: 1 addition & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-r requirements.txt
homeassistant==2022.7.7
homeassistant==2024.12.0b0
black
isort
flake8
Expand Down
28 changes: 28 additions & 0 deletions scripts/sync_ha_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python3
"""Sync homeassistant version in requirements_dev.txt to hacs.json."""
import json
import re
from pathlib import Path


def main() -> int:
root = Path(__file__).parent.parent

with open(root / "hacs.json") as f:
expected = json.load(f)["homeassistant"]

req_path = root / "requirements_dev.txt"
with open(req_path) as f:
req_text = f.read()
new_req = re.sub(r"^homeassistant==.+$", f"homeassistant=={expected}", req_text, flags=re.MULTILINE)
if new_req != req_text:
with open(req_path, "w") as f:
f.write(new_req)
print(f"Fixed requirements_dev.txt homeassistant -> {expected}")
return 1

return 0


if __name__ == "__main__":
raise SystemExit(main())
Loading