mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 04:50:05 +00:00
Use black to format hassfest generated files (#78794)
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
"""Generate config flow file."""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import black
|
||||
|
||||
from .model import Config, Integration
|
||||
from .serializer import to_string
|
||||
|
||||
BASE = """
|
||||
\"\"\"Automatically generated by hassfest.
|
||||
@@ -11,8 +12,6 @@ BASE = """
|
||||
To update, run python3 -m script.hassfest
|
||||
\"\"\"
|
||||
|
||||
# fmt: off
|
||||
|
||||
FLOWS = {}
|
||||
""".strip()
|
||||
|
||||
@@ -85,7 +84,7 @@ def generate_and_validate(integrations: dict[str, Integration], config: Config):
|
||||
|
||||
domains[integration.integration_type].append(domain)
|
||||
|
||||
return BASE.format(json.dumps(domains, indent=4))
|
||||
return black.format_str(BASE.format(to_string(domains)), mode=black.Mode())
|
||||
|
||||
|
||||
def validate(integrations: dict[str, Integration], config: Config):
|
||||
@@ -97,7 +96,7 @@ def validate(integrations: dict[str, Integration], config: Config):
|
||||
return
|
||||
|
||||
with open(str(config_flow_path)) as fp:
|
||||
if fp.read().strip() != content:
|
||||
if fp.read() != content:
|
||||
config.add_error(
|
||||
"config_flow",
|
||||
"File config_flows.py is not up to date. "
|
||||
@@ -111,4 +110,4 @@ def generate(integrations: dict[str, Integration], config: Config):
|
||||
"""Generate config flow file."""
|
||||
config_flow_path = config.root / "homeassistant/generated/config_flows.py"
|
||||
with open(str(config_flow_path), "w") as fp:
|
||||
fp.write(f"{config.cache['config_flow']}\n")
|
||||
fp.write(f"{config.cache['config_flow']}")
|
||||
|
||||
Reference in New Issue
Block a user