mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 18:27:51 +00:00
Adjust hassfest.manifest based on config.action (#100577)
This commit is contained in:
parent
7c4f08e6b3
commit
2ad0fd1ce1
@ -366,15 +366,19 @@ def _sort_manifest_keys(key: str) -> str:
|
|||||||
return _SORT_KEYS.get(key, key)
|
return _SORT_KEYS.get(key, key)
|
||||||
|
|
||||||
|
|
||||||
def sort_manifest(integration: Integration) -> bool:
|
def sort_manifest(integration: Integration, config: Config) -> bool:
|
||||||
"""Sort manifest."""
|
"""Sort manifest."""
|
||||||
keys = list(integration.manifest.keys())
|
keys = list(integration.manifest.keys())
|
||||||
if (keys_sorted := sorted(keys, key=_sort_manifest_keys)) != keys:
|
if (keys_sorted := sorted(keys, key=_sort_manifest_keys)) != keys:
|
||||||
manifest = {key: integration.manifest[key] for key in keys_sorted}
|
manifest = {key: integration.manifest[key] for key in keys_sorted}
|
||||||
|
if config.action == "generate":
|
||||||
integration.manifest_path.write_text(json.dumps(manifest, indent=2))
|
integration.manifest_path.write_text(json.dumps(manifest, indent=2))
|
||||||
|
text = "have been sorted"
|
||||||
|
else:
|
||||||
|
text = "are not sorted correctly"
|
||||||
integration.add_error(
|
integration.add_error(
|
||||||
"manifest",
|
"manifest",
|
||||||
"Manifest keys have been sorted: domain, name, then alphabetical order",
|
f"Manifest keys {text}: domain, name, then alphabetical order",
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
@ -387,9 +391,9 @@ def validate(integrations: dict[str, Integration], config: Config) -> None:
|
|||||||
for integration in integrations.values():
|
for integration in integrations.values():
|
||||||
validate_manifest(integration, core_components_dir)
|
validate_manifest(integration, core_components_dir)
|
||||||
if not integration.errors:
|
if not integration.errors:
|
||||||
if sort_manifest(integration):
|
if sort_manifest(integration, config):
|
||||||
manifests_resorted.append(integration.manifest_path)
|
manifests_resorted.append(integration.manifest_path)
|
||||||
if manifests_resorted:
|
if config.action == "generate" and manifests_resorted:
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
["pre-commit", "run", "--hook-stage", "manual", "prettier", "--files"]
|
["pre-commit", "run", "--hook-stage", "manual", "prettier", "--files"]
|
||||||
+ manifests_resorted,
|
+ manifests_resorted,
|
||||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
import json
|
import json
|
||||||
import pathlib
|
import pathlib
|
||||||
from typing import Any
|
from typing import Any, Literal
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -26,7 +26,7 @@ class Config:
|
|||||||
|
|
||||||
specific_integrations: list[pathlib.Path] | None
|
specific_integrations: list[pathlib.Path] | None
|
||||||
root: pathlib.Path
|
root: pathlib.Path
|
||||||
action: str
|
action: Literal["validate", "generate"]
|
||||||
requirements: bool
|
requirements: bool
|
||||||
errors: list[Error] = field(default_factory=list)
|
errors: list[Error] = field(default_factory=list)
|
||||||
cache: dict[str, Any] = field(default_factory=dict)
|
cache: dict[str, Any] = field(default_factory=dict)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user