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 lru-dict==1.2.0
mutagen==1.46.0 mutagen==1.46.0
orjson==3.9.2 orjson==3.9.2
packaging>=23.1
paho-mqtt==1.6.1 paho-mqtt==1.6.1
Pillow==10.0.0 Pillow==10.0.0
pip>=21.3.1 pip>=21.3.1

View File

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

View File

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

View File

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