1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Use regex instead of partition to section package definition (#58278)

This commit is contained in:
Joakim Sørensen
2021-10-23 13:19:56 +02:00
committed by GitHub
parent e38754a836
commit 2a7192167d
2 changed files with 14 additions and 6 deletions

View File

@@ -22,7 +22,9 @@ from .model import Config, Integration
IGNORE_PACKAGES = {
commented.lower().replace("_", "-") for commented in COMMENT_REQUIREMENTS
}
PACKAGE_REGEX = re.compile(r"^(?:--.+\s)?([-_\.\w\d]+).*==.+$")
PACKAGE_REGEX = re.compile(
r"^(?:--.+\s)?([-_\.\w\d\[\]]+)(==|>=|<=|~=|!=|<|>|===)*(.*)$"
)
PIP_REGEX = re.compile(r"^(--.+\s)?([-_\.\w\d]+.*(?:==|>=|<=|~=|!=|<|>|===)?.*$)")
SUPPORTED_PYTHON_TUPLES = [
REQUIRED_PYTHON_VER[:2],
@@ -84,16 +86,19 @@ def validate_requirements_format(integration: Integration) -> bool:
)
continue
pkg, sep, version = req.partition("==")
pkg, sep, version = PACKAGE_REGEX.match(req).groups()
if not sep and integration.core:
if integration.core and sep != "==":
integration.add_error(
"requirements",
f'Requirement {req} need to be pinned "<pkg name>==<version>".',
)
continue
if AwesomeVersion(version).strategy == AwesomeVersionStrategy.UNKNOWN:
if (
version
and AwesomeVersion(version).strategy == AwesomeVersionStrategy.UNKNOWN
):
integration.add_error(
"requirements",
f"Unable to parse package version ({version}) for {pkg}.",