Update HACS

This commit is contained in:
root
2022-05-23 17:48:47 -07:00
parent 3bdb8638a8
commit 1d83dd0c31
163 changed files with 862 additions and 11844 deletions

View File

@@ -7,8 +7,7 @@ This is where the validation rules that run against the various repository categ
- There is one file pr. rule.
- All rule needs tests to verify every possible outcome for the rule.
- It's better with multiple files than a big rule.
- All rules uses `ValidationBase` or `ActionValidationBase` as the base class.
- The `ActionValidationBase` are for checks that will breaks compatibility with with existing repositories (default), so these are only run in github actions.
- All rules uses `ActionValidationBase` as the base class.
- Only use `validate` or `async_validate` methods to define validation rules.
- If a rule should fail, raise `ValidationException` with the failure message.
@@ -22,12 +21,6 @@ from .base import (
ValidationException,
)
class AwesomeRepository(ValidationBase):
def validate(self):
if self.repository != "awesome":
raise ValidationException("The repository is not awesome")
class SuperAwesomeRepository(ActionValidationBase):
category = "integration"

View File

@@ -14,10 +14,9 @@ class ValidationException(HacsException):
"""Raise when there is a validation issue."""
class ValidationBase:
"""Base class for validation."""
class ActionValidationBase:
"""Base class for action validation."""
action_only: bool = False
category: str = "common"
def __init__(self, repository: HacsRepository) -> None:
@@ -30,29 +29,23 @@ class ValidationBase:
"""Return the check slug."""
return self.__class__.__module__.rsplit(".", maxsplit=1)[-1]
async def async_validate(self) -> None:
"""Validate the repository."""
async def execute_validation(self, *_, **__) -> None:
"""Execute the task defined in subclass."""
self.hacs.log.debug("Validation<%s> Starting validation", self.slug)
self.hacs.log.info("<Validation %s> Starting validation", self.slug)
start_time = monotonic()
self.failed = False
try:
if task := getattr(self, "validate", None):
await self.hacs.hass.async_add_executor_job(task)
elif task := getattr(self, "async_validate", None):
await task() # pylint: disable=not-callable
await self.async_validate()
except ValidationException as exception:
self.failed = True
self.hacs.log.error("Validation<%s> failed: %s", self.slug, exception)
self.hacs.log.error("<Validation %s> failed: %s", self.slug, exception)
else:
self.hacs.log.debug(
"Validation<%s> took %.3f seconds to complete", self.slug, monotonic() - start_time
"<Validation %s> took %.3f seconds to complete", self.slug, monotonic() - start_time
)
class ActionValidationBase(ValidationBase):
"""Base class for action validation."""
action_only = True

View File

@@ -11,6 +11,9 @@ async def async_setup_validator(repository: HacsRepository) -> Validator:
class Validator(ActionValidationBase):
def validate(self):
"""Validate the repository."""
async def async_validate(self):
"""Validate the repository."""
if RepositoryFile.HACS_JSON not in [x.filename for x in self.repository.tree]:
raise ValidationException(f"The repository has no '{RepositoryFile.HACS_JSON}' file")

View File

@@ -11,9 +11,12 @@ async def async_setup_validator(repository: HacsRepository) -> Validator:
class Validator(ActionValidationBase):
"""Validate the repository."""
category = "integration"
def validate(self):
async def async_validate(self):
"""Validate the repository."""
if RepositoryFile.MAINIFEST_JSON not in [x.filename for x in self.repository.tree]:
raise ValidationException(
f"The repository has no '{RepositoryFile.MAINIFEST_JSON}' file"

View File

@@ -10,7 +10,7 @@ from homeassistant.core import HomeAssistant
from custom_components.hacs.repositories.base import HacsRepository
from .base import ValidationBase
from .base import ActionValidationBase
if TYPE_CHECKING:
from ..base import HacsBase
@@ -23,10 +23,10 @@ class ValidationManager:
"""Initialize the setup manager class."""
self.hacs = hacs
self.hass = hass
self._validatiors: dict[str, ValidationBase] = {}
self._validatiors: dict[str, ActionValidationBase] = {}
@property
def validatiors(self) -> dict[str, ValidationBase]:
def validatiors(self) -> dict[str, ActionValidationBase]:
"""Return all list of all tasks."""
return list(self._validatiors.values())
@@ -50,7 +50,7 @@ class ValidationManager:
async def async_run_repository_checks(self, repository: HacsRepository) -> None:
"""Run all validators for a repository."""
if not self.hacs.system.running:
if not self.hacs.system.action:
return
await self.async_load(repository)
@@ -59,19 +59,17 @@ class ValidationManager:
*[
validator.execute_validation()
for validator in self.validatiors or []
if (self.hacs.system.action or not validator.action_only)
and (
if (
validator.category == "common" or validator.category == repository.data.category
)
]
)
total = len([x for x in self.validatiors if self.hacs.system.action or not x.action_only])
total = len(self.validatiors)
failed = len([x for x in self.validatiors if x.failed])
if failed != 0:
repository.logger.error("%s %s/%s checks failed", repository.string, failed, total)
if self.hacs.system.action:
exit(1)
exit(1)
else:
repository.logger.debug("%s All (%s) checks passed", repository.string, total)

View File

@@ -10,6 +10,9 @@ async def async_setup_validator(repository: HacsRepository) -> Validator:
class Validator(ActionValidationBase):
def validate(self):
"""Validate the repository."""
async def async_validate(self):
"""Validate the repository."""
if not self.repository.data.description:
raise ValidationException("The repository has no description")

View File

@@ -10,7 +10,10 @@ async def async_setup_validator(repository: HacsRepository) -> Validator:
class Validator(ActionValidationBase):
"""Validate the repository."""
async def async_validate(self):
"""Validate the repository."""
filenames = [x.filename.lower() for x in self.repository.tree]
if "readme" in filenames:
pass

View File

@@ -10,6 +10,9 @@ async def async_setup_validator(repository: HacsRepository) -> Validator:
class Validator(ActionValidationBase):
def validate(self):
"""Validate the repository."""
async def async_validate(self):
"""Validate the repository."""
if not self.repository.data.topics:
raise ValidationException("The repository has no topics")