From edfb8c3423da4152aec56a51fdfac5829d9af275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Mon, 25 Jan 2021 13:31:14 +0100 Subject: [PATCH] Add version to hassfest for custom integrations (#45523) Co-authored-by: Paulus Schoutsen --- requirements_test.txt | 1 + script/hassfest/__main__.py | 2 +- script/hassfest/manifest.py | 47 ++++++++++++++++++++++++++++++++++--- script/hassfest/model.py | 5 ++++ 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/requirements_test.txt b/requirements_test.txt index 3bd4ff8c479..d5b7264655b 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -13,6 +13,7 @@ pre-commit==2.9.3 pylint==2.6.0 astroid==2.4.2 pipdeptree==1.0.0 +awesomeversion==21.1.3 pylint-strict-informational==0.1 pytest-aiohttp==0.3.0 pytest-cov==2.10.1 diff --git a/script/hassfest/__main__.py b/script/hassfest/__main__.py index 6e88efa2177..6901622bfb3 100644 --- a/script/hassfest/__main__.py +++ b/script/hassfest/__main__.py @@ -183,7 +183,7 @@ def print_integrations_status(config, integrations, *, show_fixable_errors=True) print(f"Integration {integration.domain}{extra}:") for error in integration.errors: if show_fixable_errors or not error.fixable: - print("*", error) + print("*", "[ERROR]", error) for warning in integration.warnings: print("*", "[WARNING]", warning) print() diff --git a/script/hassfest/manifest.py b/script/hassfest/manifest.py index af483c3c5e7..e02df86f4e1 100644 --- a/script/hassfest/manifest.py +++ b/script/hassfest/manifest.py @@ -2,6 +2,8 @@ from typing import Dict from urllib.parse import urlparse +from awesomeversion import AwesomeVersion +from awesomeversion.strategy import AwesomeVersionStrategy import voluptuous as vol from voluptuous.humanize import humanize_error @@ -49,6 +51,21 @@ def verify_uppercase(value: str): return value +def verify_version(value: str): + """Verify the version.""" + version = AwesomeVersion(value) + if version.strategy not in [ + AwesomeVersionStrategy.CALVER, + AwesomeVersionStrategy.SEMVER, + AwesomeVersionStrategy.SIMPLEVER, + AwesomeVersionStrategy.BUILDVER, + ]: + raise vol.Invalid( + f"'{version}' is not a valid version. This will cause a future version of Home Assistant to block this integration.", + ) + return value + + MANIFEST_SCHEMA = vol.Schema( { vol.Required("domain"): str, @@ -94,21 +111,45 @@ MANIFEST_SCHEMA = vol.Schema( } ) +CUSTOM_INTEGRATION_MANIFEST_SCHEMA = MANIFEST_SCHEMA.extend( + { + vol.Optional("version"): vol.All(str, verify_version), + } +) + + +def validate_version(integration: Integration): + """ + Validate the version of the integration. + + Will be removed when the version key is no longer optional for custom integrations. + """ + if not integration.manifest.get("version"): + integration.add_warning( + "manifest", + "No 'version' key in the manifest file. This will cause a future version of Home Assistant to block this integration.", + ) + return + def validate_manifest(integration: Integration): """Validate manifest.""" try: - MANIFEST_SCHEMA(integration.manifest) + if integration.core: + MANIFEST_SCHEMA(integration.manifest) + else: + CUSTOM_INTEGRATION_MANIFEST_SCHEMA(integration.manifest) except vol.Invalid as err: integration.add_error( "manifest", f"Invalid manifest: {humanize_error(integration.manifest, err)}" ) - integration.manifest = None - return if integration.manifest["domain"] != integration.path.name: integration.add_error("manifest", "Domain does not match dir name") + if not integration.core: + validate_version(integration) + def validate(integrations: Dict[str, Integration], config): """Handle all integrations manifests.""" diff --git a/script/hassfest/model.py b/script/hassfest/model.py index 8c55c2818f1..0750ef10b6c 100644 --- a/script/hassfest/model.py +++ b/script/hassfest/model.py @@ -74,6 +74,11 @@ class Integration: """Integration domain.""" return self.path.name + @property + def core(self) -> bool: + """Core integration.""" + return self.path.as_posix().startswith("homeassistant/components") + @property def disabled(self) -> Optional[str]: """List of disabled."""