mirror of
https://github.com/home-assistant/core.git
synced 2026-12-03 04:08:19 -04:00
Declare and synchronize pytest-home-assistant dependencies (#187088)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
import difflib
|
||||
import importlib
|
||||
import json
|
||||
from operator import itemgetter
|
||||
from pathlib import Path
|
||||
import pkgutil
|
||||
@@ -271,6 +272,8 @@ GENERATED_MESSAGE = (
|
||||
f"# Automatically generated by {Path(__file__).name}, do not edit\n\n"
|
||||
)
|
||||
|
||||
PYTEST_PACKAGE_PATH = Path("packages/pytest-home-assistant/pyproject.toml")
|
||||
|
||||
MAP_HOOK_ID_TO_PACKAGE = {
|
||||
"ruff-check": "ruff",
|
||||
}
|
||||
@@ -558,6 +561,38 @@ def requirements_pre_commit_output() -> str:
|
||||
return "\n".join(output) + "\n"
|
||||
|
||||
|
||||
def pytest_package_output(reqs: dict[str, list[str]]) -> str:
|
||||
"""Keep pytest helper dependencies aligned with Core and test requirements."""
|
||||
test_requirements = [
|
||||
line
|
||||
for line in Path("requirements_test.txt").read_text().splitlines()
|
||||
if line and not line.startswith(("#", "-"))
|
||||
]
|
||||
versions = {}
|
||||
for value in [*reqs, *core_requirements(), *test_requirements]:
|
||||
requirement = Requirement(value)
|
||||
versions[canonicalize_name(requirement.name)] = requirement.specifier
|
||||
content = PYTEST_PACKAGE_PATH.read_text()
|
||||
project = tomllib.loads(content)["project"]
|
||||
dependencies = [
|
||||
*project["dependencies"],
|
||||
*(
|
||||
dependency
|
||||
for extra in project["optional-dependencies"].values()
|
||||
for dependency in extra
|
||||
),
|
||||
]
|
||||
for dependency in dependencies:
|
||||
requirement = Requirement(dependency)
|
||||
name = canonicalize_name(requirement.name)
|
||||
if name == "homeassistant":
|
||||
# The matching Home Assistant version is set when publishing.
|
||||
continue
|
||||
requirement.specifier = versions[name]
|
||||
content = content.replace(json.dumps(dependency), json.dumps(str(requirement)))
|
||||
return content
|
||||
|
||||
|
||||
def gather_constraints() -> str:
|
||||
"""Construct output for constraint file."""
|
||||
return (
|
||||
@@ -618,6 +653,7 @@ def main(validate: bool, ci: bool) -> int:
|
||||
("requirements_all.txt", reqs_all_file),
|
||||
("requirements_test_pre_commit.txt", reqs_pre_commit_file),
|
||||
("homeassistant/package_constraints.txt", constraints),
|
||||
(str(PYTEST_PACKAGE_PATH), pytest_package_output(data)),
|
||||
]
|
||||
if ci:
|
||||
files.extend(
|
||||
|
||||
Reference in New Issue
Block a user