Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build hassfest docker image and pushlish it on beta/stable releases #124706

Merged
merged 11 commits into from
Aug 28, 2024
20 changes: 17 additions & 3 deletions script/gen_requirements_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from typing import Any

from homeassistant.util.yaml.loader import load_yaml
from script.hassfest.model import Integration
from script.hassfest.model import Config, Integration

# Requirements which can't be installed on all systems because they rely on additional
# system packages. Requirements listed in EXCLUDED_REQUIREMENTS_ALL will be commented-out
Expand Down Expand Up @@ -276,7 +276,9 @@ def gather_recursive_requirements(
seen = set()

seen.add(domain)
integration = Integration(Path(f"homeassistant/components/{domain}"))
integration = Integration(
Path(f"homeassistant/components/{domain}"), _get_hassfest_config()
)
integration.load_manifest()
reqs = {x for x in integration.requirements if x not in CONSTRAINT_BASE}
for dep_domain in integration.dependencies:
Expand Down Expand Up @@ -342,7 +344,8 @@ def gather_requirements_from_manifests(
errors: list[str], reqs: dict[str, list[str]]
) -> None:
"""Gather all of the requirements from manifests."""
integrations = Integration.load_dir(Path("homeassistant/components"))
config = _get_hassfest_config()
integrations = Integration.load_dir(config.core_integrations_path, config)
for domain in sorted(integrations):
integration = integrations[domain]

Expand Down Expand Up @@ -590,6 +593,17 @@ def main(validate: bool, ci: bool) -> int:
return 0


def _get_hassfest_config() -> Config:
"""Get hassfest config."""
return Config(
root=Path(".").absolute(),
specific_integrations=None,
action="validate",
requirements=True,
core_integrations_path=Path("homeassistant/components"),
)


if __name__ == "__main__":
_VAL = sys.argv[-1] == "validate"
_CI = sys.argv[-1] == "ci"
Expand Down
11 changes: 9 additions & 2 deletions script/hassfest/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ def get_config() -> Config:
default=ALL_PLUGIN_NAMES,
help="Comma-separate list of plugins to run. Valid plugin names: %(default)s",
)
parser.add_argument(
"--core-integrations-path",
type=pathlib.Path,
default=pathlib.Path("homeassistant/components"),
help="Path to core integrations",
)
parsed = parser.parse_args()

if parsed.action is None:
Expand All @@ -129,6 +135,7 @@ def get_config() -> Config:
action=parsed.action,
requirements=parsed.requirements,
plugins=set(parsed.plugins),
core_integrations_path=parsed.core_integrations_path,
)


Expand All @@ -146,12 +153,12 @@ def main() -> int:
integrations = {}

for int_path in config.specific_integrations:
integration = Integration(int_path)
integration = Integration(int_path, config)
integration.load_manifest()
integrations[integration.domain] = integration

else:
integrations = Integration.load_dir(pathlib.Path("homeassistant/components"))
integrations = Integration.load_dir(config.core_integrations_path, config)
plugins += HASS_PLUGINS

for plugin in plugins:
Expand Down
10 changes: 7 additions & 3 deletions script/hassfest/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Config:
root: pathlib.Path
action: Literal["validate", "generate"]
requirements: bool
core_integrations_path: pathlib.Path
errors: list[Error] = field(default_factory=list)
cache: dict[str, Any] = field(default_factory=dict)
plugins: set[str] = field(default_factory=set)
Expand Down Expand Up @@ -105,7 +106,7 @@ class Integration:
"""Represent an integration in our validator."""

@classmethod
def load_dir(cls, path: pathlib.Path) -> dict[str, Integration]:
def load_dir(cls, path: pathlib.Path, config: Config) -> dict[str, Integration]:
"""Load all integrations in a directory."""
assert path.is_dir()
integrations: dict[str, Integration] = {}
Expand All @@ -123,13 +124,14 @@ def load_dir(cls, path: pathlib.Path) -> dict[str, Integration]:
)
continue

integration = cls(fil)
integration = cls(fil, config)
integration.load_manifest()
integrations[integration.domain] = integration

return integrations

path: pathlib.Path
_config: Config
_manifest: dict[str, Any] | None = None
manifest_path: pathlib.Path | None = None
errors: list[Error] = field(default_factory=list)
Expand All @@ -150,7 +152,9 @@ def domain(self) -> str:
@property
def core(self) -> bool:
"""Core integration."""
return self.path.as_posix().startswith("homeassistant/components")
return self.path.as_posix().startswith(
self._config.core_integrations_path.as_posix()
)

@property
def disabled(self) -> str | None:
Expand Down
Loading