mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Use black to format hassfest generated files (#78794)
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
"""Generate ssdp file."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections import OrderedDict, defaultdict
|
||||
import json
|
||||
from collections import defaultdict
|
||||
|
||||
import black
|
||||
|
||||
from .model import Config, Integration
|
||||
from .serializer import to_string
|
||||
|
||||
BASE = """
|
||||
\"\"\"Automatically generated by hassfest.
|
||||
@@ -12,15 +14,13 @@ BASE = """
|
||||
To update, run python3 -m script.hassfest
|
||||
\"\"\"
|
||||
|
||||
# fmt: off
|
||||
|
||||
SSDP = {}
|
||||
""".strip()
|
||||
|
||||
|
||||
def sort_dict(value):
|
||||
"""Sort a dictionary."""
|
||||
return OrderedDict((key, value[key]) for key in sorted(value))
|
||||
return {key: value[key] for key in sorted(value)}
|
||||
|
||||
|
||||
def generate_and_validate(integrations: dict[str, Integration]):
|
||||
@@ -42,7 +42,7 @@ def generate_and_validate(integrations: dict[str, Integration]):
|
||||
for matcher in ssdp:
|
||||
data[domain].append(sort_dict(matcher))
|
||||
|
||||
return BASE.format(json.dumps(data, indent=4))
|
||||
return black.format_str(BASE.format(to_string(data)), mode=black.Mode())
|
||||
|
||||
|
||||
def validate(integrations: dict[str, Integration], config: Config):
|
||||
@@ -54,7 +54,7 @@ def validate(integrations: dict[str, Integration], config: Config):
|
||||
return
|
||||
|
||||
with open(str(ssdp_path)) as fp:
|
||||
if fp.read().strip() != content:
|
||||
if fp.read() != content:
|
||||
config.add_error(
|
||||
"ssdp",
|
||||
"File ssdp.py is not up to date. Run python3 -m script.hassfest",
|
||||
@@ -67,4 +67,4 @@ def generate(integrations: dict[str, Integration], config: Config):
|
||||
"""Generate ssdp file."""
|
||||
ssdp_path = config.root / "homeassistant/generated/ssdp.py"
|
||||
with open(str(ssdp_path), "w") as fp:
|
||||
fp.write(f"{config.cache['ssdp']}\n")
|
||||
fp.write(f"{config.cache['ssdp']}")
|
||||
|
||||
Reference in New Issue
Block a user