Fix scaffolding integration generation (#138247)

* fix(scaffold): integration generation

Fix script.scaffold integration generation which was failing due to
hassfest quality check.

Add the required `quality_scale` to the generated integration
manifest.json.

Use the new `--skip-plugins` flag to skip the hassfest quality check
when generating integrations, as the quality scale rules are marked as
todo, and only run against the generated integration.

Correct typo in help for hassfest command `--plugins` flag.

Update Integration.core method to use absolute path to ensure it returns
the true if the integration is a core integration, which was causing
other checks to fail, as the integration was not being marked as core.

Always output subprocess output as it contains the error message when a
command fails, without this the user would not know why the command
failed.

Fixes: #128639

* Adjust comment language

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
Steven Hartland 2025-02-11 15:24:04 +00:00 committed by GitHub
parent 8b3421deb7
commit 1a4738b1d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 33 additions and 10 deletions

View File

@ -107,7 +107,13 @@ def get_config() -> Config:
"--plugins",
type=validate_plugins,
default=ALL_PLUGIN_NAMES,
help="Comma-separate list of plugins to run. Valid plugin names: %(default)s",
help="Comma-separated list of plugins to run. Valid plugin names: %(default)s",
)
parser.add_argument(
"--skip-plugins",
type=validate_plugins,
default=[],
help=f"Comma-separated list of plugins to skip. Valid plugin names: {ALL_PLUGIN_NAMES}",
)
parser.add_argument(
"--core-path",
@ -131,6 +137,9 @@ def get_config() -> Config:
):
raise RuntimeError("Run from Home Assistant root")
if parsed.skip_plugins:
parsed.plugins = set(parsed.plugins) - set(parsed.skip_plugins)
return Config(
root=parsed.core_path.absolute(),
specific_integrations=parsed.integration_path,

View File

@ -157,8 +157,10 @@ class Integration:
@property
def core(self) -> bool:
"""Core integration."""
return self.path.as_posix().startswith(
self._config.core_integrations_path.as_posix()
return (
self.path.absolute()
.as_posix()
.startswith(self._config.core_integrations_path.as_posix())
)
@property

View File

@ -60,20 +60,32 @@ def main() -> int:
generate.generate(template, info)
hassfest_args = [
"python",
"-m",
"script.hassfest",
]
# If we wanted a new integration, we've already done our work.
if args.template != "integration":
generate.generate(args.template, info)
else:
hassfest_args.extend(
[
"--integration-path",
info.integration_dir,
"--skip-plugins",
"quality_scale", # Skip quality scale as it will fail for newly generated integrations.
]
)
pipe_null = {} if args.develop else {"stdout": subprocess.DEVNULL}
# Always output sub commands as the output will contain useful information if a command fails.
print("Running hassfest to pick up new information.")
subprocess.run(["python", "-m", "script.hassfest"], **pipe_null, check=True)
subprocess.run(hassfest_args, check=True)
print()
print("Running gen_requirements_all to pick up new information.")
subprocess.run(
["python", "-m", "script.gen_requirements_all"], **pipe_null, check=True
)
subprocess.run(["python", "-m", "script.gen_requirements_all"], check=True)
print()
print("Running script/translations_develop to pick up new translation strings.")
@ -86,7 +98,6 @@ def main() -> int:
"--integration",
info.domain,
],
**pipe_null,
check=True,
)
print()

View File

@ -7,6 +7,7 @@
"documentation": "https://www.home-assistant.io/integrations/NEW_DOMAIN",
"homekit": {},
"iot_class": "IOT_CLASS",
"quality_scale": "bronze",
"requirements": [],
"ssdp": [],
"zeroconf": []