From 72065768f334243e9e72bdabe1eb0c0ff6fd606e Mon Sep 17 00:00:00 2001 From: Marc-Philip Date: Fri, 20 Sep 2024 00:36:31 +0200 Subject: [PATCH] Allow github requirements specs in hassfest for non-core integrations (#124925) * allow all requirements specs * remove unnecessary tests * Revert "remove unnecessary tests" This reverts commit 0a2af0318d59f2a7edbd9496ab12bd5a56f5afaa. * Revert "allow all requirements specs" This reverts commit d15cd27f7b7c95b176a3eccb747b6ebff8acffda. * be lenient only for custom integrations * don't allow blanks as requested --------- Co-authored-by: Martin Hjelmare --- script/hassfest/requirements.py | 25 +++++++++++++------------ tests/hassfest/test_requirements.py | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/script/hassfest/requirements.py b/script/hassfest/requirements.py index d35d96121c522..3df25f3284a8a 100644 --- a/script/hassfest/requirements.py +++ b/script/hassfest/requirements.py @@ -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 diff --git a/tests/hassfest/test_requirements.py b/tests/hassfest/test_requirements.py index 433e63d904c5f..e70bee104c90c 100644 --- a/tests/hassfest/test_requirements.py +++ b/tests/hassfest/test_requirements.py @@ -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/project.git@1.2.3", + ] + 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/project.git@1.2.3", + ] + integration.path = Path("") + assert validate_requirements_format(integration) + assert len(integration.errors) == 0