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