1
0
mirror of https://github.com/home-assistant/core synced 2024-07-03 08:18:59 +00:00

Add packaging as default requirement (#97712)

This commit is contained in:
Marc Mueller 2023-08-04 12:29:18 +02:00 committed by GitHub
parent 6adb06956b
commit 447479d0a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 10 deletions

View File

@ -31,6 +31,7 @@ Jinja2==3.1.2
lru-dict==1.2.0
mutagen==1.46.0
orjson==3.9.2
packaging>=23.1
paho-mqtt==1.6.1
Pillow==10.0.0
pip>=21.3.1

View File

@ -11,6 +11,8 @@ import threading
import traceback
from typing import Any
import packaging.tags
from . import bootstrap
from .core import callback
from .helpers.frame import warn_use
@ -29,7 +31,6 @@ from .util.thread import deadlock_safe_shutdown
#
MAX_EXECUTOR_WORKERS = 64
TASK_CANCELATION_TIMEOUT = 5
ALPINE_RELEASE_FILE = "/etc/alpine-release"
_LOGGER = logging.getLogger(__name__)
@ -164,8 +165,9 @@ def _enable_posix_spawn() -> None:
# The subprocess module does not know about Alpine Linux/musl
# and will use fork() instead of posix_spawn() which significantly
# less efficient. This is a workaround to force posix_spawn()
# on Alpine Linux which is supported by musl.
subprocess._USE_POSIX_SPAWN = os.path.exists(ALPINE_RELEASE_FILE)
# when using musl since cpython is not aware its supported.
tag = next(packaging.tags.sys_tags())
subprocess._USE_POSIX_SPAWN = "musllinux" in tag.platform
def run(runtime_config: RuntimeConfig) -> int:

View File

@ -45,6 +45,7 @@ dependencies = [
# pyOpenSSL 23.2.0 is required to work with cryptography 41+
"pyOpenSSL==23.2.0",
"orjson==3.9.2",
"packaging>=23.1",
"pip>=21.3.1",
"python-slugify==4.0.1",
"PyYAML==6.0.1",

View File

@ -19,6 +19,7 @@ PyJWT==2.8.0
cryptography==41.0.3
pyOpenSSL==23.2.0
orjson==3.9.2
packaging>=23.1
pip>=21.3.1
python-slugify==4.0.1
PyYAML==6.0.1

View File

@ -1,8 +1,10 @@
"""Test the runner."""
import asyncio
from collections.abc import Iterator
import threading
from unittest.mock import patch
import packaging.tags
import py
import pytest
@ -147,19 +149,22 @@ async def test_unhandled_exception_traceback(
def test__enable_posix_spawn() -> None:
"""Test that we can enable posix_spawn on Alpine."""
"""Test that we can enable posix_spawn on musllinux."""
def _mock_alpine_exists(path):
return path == "/etc/alpine-release"
def _mock_sys_tags_any() -> Iterator[packaging.tags.Tag]:
yield from packaging.tags.parse_tag("py3-none-any")
with patch.object(runner.subprocess, "_USE_POSIX_SPAWN", False), patch.object(
runner.os.path, "exists", _mock_alpine_exists
def _mock_sys_tags_musl() -> Iterator[packaging.tags.Tag]:
yield from packaging.tags.parse_tag("cp311-cp311-musllinux_1_1_x86_64")
with patch.object(runner.subprocess, "_USE_POSIX_SPAWN", False), patch(
"homeassistant.runner.packaging.tags.sys_tags", side_effect=_mock_sys_tags_musl
):
runner._enable_posix_spawn()
assert runner.subprocess._USE_POSIX_SPAWN is True
with patch.object(runner.subprocess, "_USE_POSIX_SPAWN", False), patch.object(
runner.os.path, "exists", return_value=False
with patch.object(runner.subprocess, "_USE_POSIX_SPAWN", False), patch(
"homeassistant.runner.packaging.tags.sys_tags", side_effect=_mock_sys_tags_any
):
runner._enable_posix_spawn()
assert runner.subprocess._USE_POSIX_SPAWN is False