mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Add plugin option [hassfest] (#65024)
This commit is contained in:
parent
2325cacb04
commit
f6c679699f
2
mypy.ini
2
mypy.ini
@ -1,6 +1,6 @@
|
||||
# Automatically generated by hassfest.
|
||||
#
|
||||
# To update, run python3 -m script.hassfest
|
||||
# To update, run python3 -m script.hassfest -p mypy_config
|
||||
|
||||
[mypy]
|
||||
python_version = 3.9
|
||||
|
@ -43,6 +43,11 @@ HASS_PLUGINS = [
|
||||
mypy_config,
|
||||
]
|
||||
|
||||
ALL_PLUGIN_NAMES = [
|
||||
plugin.__name__.rsplit(".", maxsplit=1)[-1]
|
||||
for plugin in (*INTEGRATION_PLUGINS, *HASS_PLUGINS)
|
||||
]
|
||||
|
||||
|
||||
def valid_integration_path(integration_path):
|
||||
"""Test if it's a valid integration."""
|
||||
@ -53,6 +58,17 @@ def valid_integration_path(integration_path):
|
||||
return path
|
||||
|
||||
|
||||
def validate_plugins(plugin_names: str) -> list[str]:
|
||||
"""Split and validate plugin names."""
|
||||
all_plugin_names = set(ALL_PLUGIN_NAMES)
|
||||
plugins = plugin_names.split(",")
|
||||
for plugin in plugins:
|
||||
if plugin not in all_plugin_names:
|
||||
raise argparse.ArgumentTypeError(f"{plugin} is not a valid plugin name")
|
||||
|
||||
return plugins
|
||||
|
||||
|
||||
def get_config() -> Config:
|
||||
"""Return config."""
|
||||
parser = argparse.ArgumentParser(description="Hassfest")
|
||||
@ -70,6 +86,13 @@ def get_config() -> Config:
|
||||
action="store_true",
|
||||
help="Validate requirements",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-p",
|
||||
"--plugins",
|
||||
type=validate_plugins,
|
||||
default=ALL_PLUGIN_NAMES,
|
||||
help="Comma-separate list of plugins to run. Valid plugin names: %(default)s",
|
||||
)
|
||||
parsed = parser.parse_args()
|
||||
|
||||
if parsed.action is None:
|
||||
@ -91,6 +114,7 @@ def get_config() -> Config:
|
||||
specific_integrations=parsed.integration_path,
|
||||
action=parsed.action,
|
||||
requirements=parsed.requirements,
|
||||
plugins=set(parsed.plugins),
|
||||
)
|
||||
|
||||
|
||||
@ -117,9 +141,12 @@ def main():
|
||||
plugins += HASS_PLUGINS
|
||||
|
||||
for plugin in plugins:
|
||||
plugin_name = plugin.__name__.rsplit(".", maxsplit=1)[-1]
|
||||
if plugin_name not in config.plugins:
|
||||
continue
|
||||
try:
|
||||
start = monotonic()
|
||||
print(f"Validating {plugin.__name__.split('.')[-1]}...", end="", flush=True)
|
||||
print(f"Validating {plugin_name}...", end="", flush=True)
|
||||
if (
|
||||
plugin is requirements
|
||||
and config.requirements
|
||||
@ -161,6 +188,9 @@ def main():
|
||||
|
||||
if config.action == "generate":
|
||||
for plugin in plugins:
|
||||
plugin_name = plugin.__name__.rsplit(".", maxsplit=1)[-1]
|
||||
if plugin_name not in config.plugins:
|
||||
continue
|
||||
if hasattr(plugin, "generate"):
|
||||
plugin.generate(integrations, config)
|
||||
return 0
|
||||
|
@ -32,6 +32,7 @@ class Config:
|
||||
requirements: bool = attr.ib()
|
||||
errors: list[Error] = attr.ib(factory=list)
|
||||
cache: dict[str, Any] = attr.ib(factory=dict)
|
||||
plugins: set[str] = attr.ib(factory=set)
|
||||
|
||||
def add_error(self, *args: Any, **kwargs: Any) -> None:
|
||||
"""Add an error."""
|
||||
|
@ -90,7 +90,7 @@ NO_IMPLICIT_REEXPORT_MODULES: set[str] = {
|
||||
HEADER: Final = """
|
||||
# Automatically generated by hassfest.
|
||||
#
|
||||
# To update, run python3 -m script.hassfest
|
||||
# To update, run python3 -m script.hassfest -p mypy_config
|
||||
|
||||
""".lstrip()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user