Skip to content

Commit

Permalink
Allow github requirements specs in hassfest for non-core integrations (
Browse files Browse the repository at this point in the history
…home-assistant#124925)

* allow all requirements specs

* remove unnecessary tests

* Revert "remove unnecessary tests"

This reverts commit 0a2af03.

* Revert "allow all requirements specs"

This reverts commit d15cd27.

* be lenient only for custom integrations

* don't allow blanks as requested

---------

Co-authored-by: Martin Hjelmare <[email protected]>
  • Loading branch information
2 people authored and sarog committed Sep 20, 2024
1 parent e018343 commit dd7e2eb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
25 changes: 13 additions & 12 deletions script/hassfest/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,19 @@ def validate_requirements_format(integration: Integration) -> bool:
if not version:
continue

for part in version.split(";", 1)[0].split(","):
version_part = PIP_VERSION_RANGE_SEPARATOR.match(part)
if (
version_part
and AwesomeVersion(version_part.group(2)).strategy
== AwesomeVersionStrategy.UNKNOWN
):
integration.add_error(
"requirements",
f"Unable to parse package version ({version}) for {pkg}.",
)
continue
if integration.core:
for part in version.split(";", 1)[0].split(","):
version_part = PIP_VERSION_RANGE_SEPARATOR.match(part)
if (
version_part
and AwesomeVersion(version_part.group(2)).strategy
== AwesomeVersionStrategy.UNKNOWN
):
integration.add_error(
"requirements",
f"Unable to parse package version ({version}) for {pkg}.",
)
continue

return len(integration.errors) == start_errors

Expand Down
19 changes: 19 additions & 0 deletions tests/hassfest/test_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,22 @@ def test_validate_requirements_format_successful(integration: Integration) -> No
]
assert validate_requirements_format(integration)
assert len(integration.errors) == 0


def test_validate_requirements_format_github_core(integration: Integration) -> None:
"""Test requirement that points to github fails with core component."""
integration.manifest["requirements"] = [
"git+https://github.com/user/[email protected]",
]
assert not validate_requirements_format(integration)
assert len(integration.errors) == 1


def test_validate_requirements_format_github_custom(integration: Integration) -> None:
"""Test requirement that points to github succeeds with custom component."""
integration.manifest["requirements"] = [
"git+https://github.com/user/[email protected]",
]
integration.path = Path("")
assert validate_requirements_format(integration)
assert len(integration.errors) == 0

0 comments on commit dd7e2eb

Please sign in to comment.