Whole-string match reqs in comment_requirement (#55192)
Co-authored-by: Franck Nijhof <frenck@frenck.nl> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
parent
cbc68e45cd
commit
de5a22953d
2 changed files with 24 additions and 15 deletions
|
@ -45,6 +45,10 @@ COMMENT_REQUIREMENTS = (
|
||||||
"VL53L1X2",
|
"VL53L1X2",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
COMMENT_REQUIREMENTS_NORMALIZED = {
|
||||||
|
commented.lower().replace("_", "-") for commented in COMMENT_REQUIREMENTS
|
||||||
|
}
|
||||||
|
|
||||||
IGNORE_PIN = ("colorlog>2.1,<3", "urllib3")
|
IGNORE_PIN = ("colorlog>2.1,<3", "urllib3")
|
||||||
|
|
||||||
URL_PIN = (
|
URL_PIN = (
|
||||||
|
@ -108,6 +112,8 @@ IGNORE_PRE_COMMIT_HOOK_ID = (
|
||||||
"python-typing-update",
|
"python-typing-update",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
PACKAGE_REGEX = re.compile(r"^(?:--.+\s)?([-_\.\w\d]+).*==.+$")
|
||||||
|
|
||||||
|
|
||||||
def has_tests(module: str):
|
def has_tests(module: str):
|
||||||
"""Test if a module has tests.
|
"""Test if a module has tests.
|
||||||
|
@ -171,9 +177,24 @@ def gather_recursive_requirements(domain, seen=None):
|
||||||
return reqs
|
return reqs
|
||||||
|
|
||||||
|
|
||||||
|
def normalize_package_name(requirement: str) -> str:
|
||||||
|
"""Return a normalized package name from a requirement string."""
|
||||||
|
# This function is also used in hassfest.
|
||||||
|
match = PACKAGE_REGEX.search(requirement)
|
||||||
|
if not match:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
# pipdeptree needs lowercase and dash instead of underscore as separator
|
||||||
|
package = match.group(1).lower().replace("_", "-")
|
||||||
|
|
||||||
|
return package
|
||||||
|
|
||||||
|
|
||||||
def comment_requirement(req):
|
def comment_requirement(req):
|
||||||
"""Comment out requirement. Some don't install on all systems."""
|
"""Comment out requirement. Some don't install on all systems."""
|
||||||
return any(ign.lower() in req.lower() for ign in COMMENT_REQUIREMENTS)
|
return any(
|
||||||
|
normalize_package_name(req) == ign for ign in COMMENT_REQUIREMENTS_NORMALIZED
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def gather_modules():
|
def gather_modules():
|
||||||
|
|
|
@ -15,7 +15,7 @@ from tqdm import tqdm
|
||||||
|
|
||||||
from homeassistant.const import REQUIRED_PYTHON_VER
|
from homeassistant.const import REQUIRED_PYTHON_VER
|
||||||
import homeassistant.util.package as pkg_util
|
import homeassistant.util.package as pkg_util
|
||||||
from script.gen_requirements_all import COMMENT_REQUIREMENTS
|
from script.gen_requirements_all import COMMENT_REQUIREMENTS, normalize_package_name
|
||||||
|
|
||||||
from .model import Config, Integration
|
from .model import Config, Integration
|
||||||
|
|
||||||
|
@ -48,18 +48,6 @@ IGNORE_VIOLATIONS = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def normalize_package_name(requirement: str) -> str:
|
|
||||||
"""Return a normalized package name from a requirement string."""
|
|
||||||
match = PACKAGE_REGEX.search(requirement)
|
|
||||||
if not match:
|
|
||||||
return ""
|
|
||||||
|
|
||||||
# pipdeptree needs lowercase and dash instead of underscore as separator
|
|
||||||
package = match.group(1).lower().replace("_", "-")
|
|
||||||
|
|
||||||
return package
|
|
||||||
|
|
||||||
|
|
||||||
def validate(integrations: dict[str, Integration], config: Config):
|
def validate(integrations: dict[str, Integration], config: Config):
|
||||||
"""Handle requirements for integrations."""
|
"""Handle requirements for integrations."""
|
||||||
# Check if we are doing format-only validation.
|
# Check if we are doing format-only validation.
|
||||||
|
@ -134,7 +122,7 @@ def validate_requirements(integration: Integration):
|
||||||
f"Failed to normalize package name from requirement {req}",
|
f"Failed to normalize package name from requirement {req}",
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
if package in IGNORE_PACKAGES:
|
if (package == ign for ign in IGNORE_PACKAGES):
|
||||||
continue
|
continue
|
||||||
integration_requirements.add(req)
|
integration_requirements.add(req)
|
||||||
integration_packages.add(package)
|
integration_packages.add(package)
|
||||||
|
|
Loading…
Add table
Reference in a new issue