Black
This commit is contained in:
parent
da05dfe708
commit
4de97abc3a
2676 changed files with 163166 additions and 140084 deletions
|
@ -6,8 +6,7 @@ from typing import Set, Dict
|
|||
from .model import Integration
|
||||
|
||||
|
||||
def grep_dir(path: pathlib.Path, glob_pattern: str, search_pattern: str) \
|
||||
-> Set[str]:
|
||||
def grep_dir(path: pathlib.Path, glob_pattern: str, search_pattern: str) -> Set[str]:
|
||||
"""Recursively go through a dir and it's children and find the regex."""
|
||||
pattern = re.compile(search_pattern)
|
||||
found = set()
|
||||
|
@ -24,29 +23,30 @@ def grep_dir(path: pathlib.Path, glob_pattern: str, search_pattern: str) \
|
|||
|
||||
ALLOWED_USED_COMPONENTS = {
|
||||
# This component will always be set up
|
||||
'persistent_notification',
|
||||
"persistent_notification",
|
||||
# These allow to register things without being set up
|
||||
'conversation',
|
||||
'frontend',
|
||||
'hassio',
|
||||
'system_health',
|
||||
'websocket_api',
|
||||
"conversation",
|
||||
"frontend",
|
||||
"hassio",
|
||||
"system_health",
|
||||
"websocket_api",
|
||||
}
|
||||
|
||||
|
||||
def validate_dependencies(integration: Integration):
|
||||
"""Validate all dependencies."""
|
||||
# Find usage of hass.components
|
||||
referenced = grep_dir(integration.path, "**/*.py",
|
||||
r"hass\.components\.(\w+)")
|
||||
referenced = grep_dir(integration.path, "**/*.py", r"hass\.components\.(\w+)")
|
||||
referenced -= ALLOWED_USED_COMPONENTS
|
||||
referenced -= set(integration.manifest['dependencies'])
|
||||
referenced -= set(integration.manifest.get('after_dependencies', []))
|
||||
referenced -= set(integration.manifest["dependencies"])
|
||||
referenced -= set(integration.manifest.get("after_dependencies", []))
|
||||
|
||||
if referenced:
|
||||
for domain in sorted(referenced):
|
||||
print("Warning: {} references integration {} but it's not a "
|
||||
"dependency".format(integration.domain, domain))
|
||||
print(
|
||||
"Warning: {} references integration {} but it's not a "
|
||||
"dependency".format(integration.domain, domain)
|
||||
)
|
||||
# Not enforced yet.
|
||||
# integration.add_error(
|
||||
# 'dependencies',
|
||||
|
@ -64,9 +64,8 @@ def validate(integrations: Dict[str, Integration], config):
|
|||
validate_dependencies(integration)
|
||||
|
||||
# check that all referenced dependencies exist
|
||||
for dep in integration.manifest['dependencies']:
|
||||
for dep in integration.manifest["dependencies"]:
|
||||
if dep not in integrations:
|
||||
integration.add_error(
|
||||
'dependencies',
|
||||
"Dependency {} does not exist".format(dep)
|
||||
"dependencies", "Dependency {} does not exist".format(dep)
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue