mirror of
https://github.com/home-assistant/core.git
synced 2025-07-30 02:38:10 +02:00
Allow hassfest to validate specific integrations (#34277)
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
"""Validate manifests."""
|
||||
import argparse
|
||||
import pathlib
|
||||
import sys
|
||||
from time import monotonic
|
||||
@ -16,10 +17,9 @@ from . import (
|
||||
)
|
||||
from .model import Config, Integration
|
||||
|
||||
PLUGINS = [
|
||||
INTEGRATION_PLUGINS = [
|
||||
codeowners,
|
||||
config_flow,
|
||||
coverage,
|
||||
dependencies,
|
||||
manifest,
|
||||
services,
|
||||
@ -27,16 +27,52 @@ PLUGINS = [
|
||||
translations,
|
||||
zeroconf,
|
||||
]
|
||||
HASS_PLUGINS = [
|
||||
coverage,
|
||||
]
|
||||
|
||||
|
||||
def valid_integration_path(integration_path):
|
||||
"""Test if it's a valid integration."""
|
||||
path = pathlib.Path(integration_path)
|
||||
if not path.is_dir():
|
||||
raise argparse.ArgumentTypeError(f"{integration_path} is not a directory.")
|
||||
|
||||
return path
|
||||
|
||||
|
||||
def get_config() -> Config:
|
||||
"""Return config."""
|
||||
if not pathlib.Path("requirements_all.txt").is_file():
|
||||
raise RuntimeError("Run from project root")
|
||||
parser = argparse.ArgumentParser(description="Hassfest")
|
||||
parser.add_argument(
|
||||
"--action", type=str, choices=["validate", "generate"], default=None
|
||||
)
|
||||
parser.add_argument(
|
||||
"--integration-path",
|
||||
action="append",
|
||||
type=valid_integration_path,
|
||||
help="Validate a single integration",
|
||||
)
|
||||
parsed = parser.parse_args()
|
||||
|
||||
if parsed.action is None:
|
||||
parsed.action = "validate" if parsed.integration_path else "generate"
|
||||
|
||||
if parsed.action == "generate" and parsed.integration_path:
|
||||
raise RuntimeError(
|
||||
"Generate is not allowed when limiting to specific integrations"
|
||||
)
|
||||
|
||||
if (
|
||||
not parsed.integration_path
|
||||
and not pathlib.Path("requirements_all.txt").is_file()
|
||||
):
|
||||
raise RuntimeError("Run from Home Assistant root")
|
||||
|
||||
return Config(
|
||||
root=pathlib.Path(".").absolute(),
|
||||
action="validate" if sys.argv[-1] == "validate" else "generate",
|
||||
specific_integrations=parsed.integration_path,
|
||||
action=parsed.action,
|
||||
)
|
||||
|
||||
|
||||
@ -48,9 +84,21 @@ def main():
|
||||
print(err)
|
||||
return 1
|
||||
|
||||
integrations = Integration.load_dir(pathlib.Path("homeassistant/components"))
|
||||
plugins = INTEGRATION_PLUGINS
|
||||
|
||||
for plugin in PLUGINS:
|
||||
if config.specific_integrations:
|
||||
integrations = {}
|
||||
|
||||
for int_path in config.specific_integrations:
|
||||
integration = Integration(int_path)
|
||||
integration.load_manifest()
|
||||
integrations[integration.domain] = integration
|
||||
|
||||
else:
|
||||
integrations = Integration.load_dir(pathlib.Path("homeassistant/components"))
|
||||
plugins += HASS_PLUGINS
|
||||
|
||||
for plugin in plugins:
|
||||
try:
|
||||
start = monotonic()
|
||||
print(f"Validating {plugin.__name__.split('.')[-1]}...", end="", flush=True)
|
||||
@ -77,14 +125,15 @@ def main():
|
||||
general_errors = config.errors
|
||||
invalid_itg = [itg for itg in integrations.values() if itg.errors]
|
||||
|
||||
print()
|
||||
print("Integrations:", len(integrations))
|
||||
print("Invalid integrations:", len(invalid_itg))
|
||||
|
||||
if not invalid_itg and not general_errors:
|
||||
for plugin in PLUGINS:
|
||||
if hasattr(plugin, "generate"):
|
||||
plugin.generate(integrations, config)
|
||||
|
||||
if config.action == "generate":
|
||||
for plugin in plugins:
|
||||
if hasattr(plugin, "generate"):
|
||||
plugin.generate(integrations, config)
|
||||
return 0
|
||||
|
||||
print()
|
||||
@ -99,7 +148,8 @@ def main():
|
||||
print()
|
||||
|
||||
for integration in sorted(invalid_itg, key=lambda itg: itg.domain):
|
||||
print(f"Integration {integration.domain}:")
|
||||
extra = f" - {integration.path}" if config.specific_integrations else ""
|
||||
print(f"Integration {integration.domain}{extra}:")
|
||||
for error in integration.errors:
|
||||
print("*", error)
|
||||
print()
|
||||
|
Reference in New Issue
Block a user