mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Adjust hassfest.manifest based on config.action (#100577)
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user