python 3.11 fixes

This commit is contained in:
Maxim Devaev 2023-05-04 12:37:05 +03:00
parent b5d6731497
commit b5353e63cd
8 changed files with 37 additions and 22 deletions

View File

@ -39,11 +39,11 @@ url="https://github.com/pikvm/kvmd"
license=(GPL) license=(GPL)
arch=(any) arch=(any)
depends=( depends=(
"python>=3.10" "python>=3.11"
"python<3.11" "python<3.12"
python-yaml python-yaml
"python-aiohttp>=3.7.4.post0-1.1" python-aiohttp
"python-aiofiles>=23.1.0-1" python-aiofiles
python-passlib python-passlib
python-pyotp python-pyotp
python-qrcode python-qrcode
@ -60,7 +60,7 @@ depends=(
python-pygments python-pygments
python-pyghmi python-pyghmi
python-pam python-pam
"python-pillow>=8.3.1-1" python-pillow
python-xlib python-xlib
libxkbcommon libxkbcommon
python-hidapi python-hidapi

View File

@ -202,7 +202,7 @@ async def wait_infinite() -> None:
await asyncio.sleep(3600) await asyncio.sleep(3600)
async def wait_first(*aws: Awaitable) -> tuple[set[asyncio.Task], set[asyncio.Task]]: async def wait_first(*aws: (asyncio.Future | asyncio.Task)) -> tuple[set[asyncio.Task], set[asyncio.Task]]:
return (await asyncio.wait(list(aws), return_when=asyncio.FIRST_COMPLETED)) return (await asyncio.wait(list(aws), return_when=asyncio.FIRST_COMPLETED))
@ -242,7 +242,10 @@ class AioNotifier:
await self.__queue.get() await self.__queue.get()
else: else:
try: try:
await asyncio.wait_for(self.__queue.get(), timeout=timeout) await asyncio.wait_for(
asyncio.ensure_future(self.__queue.get()),
timeout=timeout,
)
except asyncio.TimeoutError: except asyncio.TimeoutError:
return # False return # False
while not self.__queue.empty(): while not self.__queue.empty():

View File

@ -329,7 +329,10 @@ class Streamer: # pylint: disable=too-many-instance-attributes
if waiter_task is None: if waiter_task is None:
waiter_task = asyncio.create_task(self.__notifier.wait()) waiter_task = asyncio.create_task(self.__notifier.wait())
if waiter_task in (await aiotools.wait_first(asyncio.sleep(self.__state_poll), waiter_task))[0]: if waiter_task in (await aiotools.wait_first(
asyncio.ensure_future(asyncio.sleep(self.__state_poll)),
waiter_task,
))[0]:
waiter_task = None waiter_task = None
# ===== # =====

View File

@ -215,7 +215,10 @@ class Inotify:
async def get_event(self, timeout: float) -> (InotifyEvent | None): async def get_event(self, timeout: float) -> (InotifyEvent | None):
assert timeout > 0 assert timeout > 0
try: try:
return (await asyncio.wait_for(self.__events_queue.get(), timeout=timeout)) return (await asyncio.wait_for(
asyncio.ensure_future(self.__events_queue.get()),
timeout=timeout,
))
except asyncio.TimeoutError: except asyncio.TimeoutError:
return None return None

View File

@ -137,8 +137,14 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute
assert self.__writer is not None assert self.__writer is not None
try: try:
self.__writer.write(b"\xAA\xBB\x03%s\xEE" % (cmd)) self.__writer.write(b"\xAA\xBB\x03%s\xEE" % (cmd))
await asyncio.wait_for(self.__writer.drain(), timeout=self.__timeout) await asyncio.wait_for(
return (await asyncio.wait_for(self.__reader.readexactly(6), timeout=self.__timeout))[4] asyncio.ensure_future(self.__writer.drain()),
timeout=self.__timeout,
)
return (await asyncio.wait_for(
asyncio.ensure_future(self.__reader.readexactly(6)),
timeout=self.__timeout,
))[4]
except Exception as err: except Exception as err:
get_logger(0).error("Can't send command to TESmart KVM [%s]:%d: %s", get_logger(0).error("Can't send command to TESmart KVM [%s]:%d: %s",
self.__host, self.__port, tools.efmt(err)) self.__host, self.__port, tools.efmt(err))
@ -155,7 +161,7 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute
async def __ensure_device_net(self) -> None: async def __ensure_device_net(self) -> None:
try: try:
(self.__reader, self.__writer) = await asyncio.wait_for( (self.__reader, self.__writer) = await asyncio.wait_for(
asyncio.open_connection(self.__host, self.__port), asyncio.ensure_future(asyncio.open_connection(self.__host, self.__port)),
timeout=self.__timeout, timeout=self.__timeout,
) )
except Exception as err: except Exception as err:

View File

@ -145,7 +145,7 @@ def main() -> None:
classifiers=[ classifiers=[
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"Development Status :: 5 - Production/Stable", "Development Status :: 5 - Production/Stable",
"Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11",
"Topic :: System :: Systems Administration", "Topic :: System :: Systems Administration",
"Operating System :: POSIX :: Linux", "Operating System :: POSIX :: Linux",
"Intended Audience :: System Administrators", "Intended Audience :: System Administrators",

View File

@ -1,5 +1,5 @@
[mypy] [mypy]
python_version = 3.10 python_version = 3.11
ignore_missing_imports = true ignore_missing_imports = true
disallow_untyped_defs = true disallow_untyped_defs = true
strict_optional = true strict_optional = true

View File

@ -3,12 +3,12 @@ envlist = flake8, pylint, mypy, vulture, pytest, eslint, htmlhint, shellcheck
skipsdist = true skipsdist = true
[testenv] [testenv]
basepython = python3.10 basepython = python3.11
sitepackages = true sitepackages = true
changedir = /src changedir = /src
[testenv:flake8] [testenv:flake8]
whitelist_externals = bash allowlist_externals = bash
commands = bash -c 'flake8 --config=testenv/linters/flake8.ini kvmd testenv/tests *.py' commands = bash -c 'flake8 --config=testenv/linters/flake8.ini kvmd testenv/tests *.py'
deps = deps =
flake8==5.0.4 flake8==5.0.4
@ -16,7 +16,7 @@ deps =
-rrequirements.txt -rrequirements.txt
[testenv:pylint] [testenv:pylint]
whitelist_externals = bash allowlist_externals = bash
commands = bash -c 'pylint -j0 --rcfile=testenv/linters/pylint.ini --output-format=colorized --reports=no kvmd testenv/tests *.py' commands = bash -c 'pylint -j0 --rcfile=testenv/linters/pylint.ini --output-format=colorized --reports=no kvmd testenv/tests *.py'
deps = deps =
pylint pylint
@ -26,14 +26,14 @@ deps =
-rrequirements.txt -rrequirements.txt
[testenv:mypy] [testenv:mypy]
whitelist_externals = bash allowlist_externals = bash
commands = bash -c 'mypy --config-file=testenv/linters/mypy.ini --cache-dir=testenv/.mypy_cache kvmd testenv/tests *.py' commands = bash -c 'mypy --config-file=testenv/linters/mypy.ini --cache-dir=testenv/.mypy_cache kvmd testenv/tests *.py'
deps = deps =
mypy mypy
-rrequirements.txt -rrequirements.txt
[testenv:vulture] [testenv:vulture]
whitelist_externals = bash allowlist_externals = bash
commands = bash -c 'vulture --ignore-names=_format_P,Plugin --ignore-decorators=@exposed_http,@exposed_ws,@pytest.fixture kvmd testenv/tests *.py testenv/linters/vulture-wl.py' commands = bash -c 'vulture --ignore-names=_format_P,Plugin --ignore-decorators=@exposed_http,@exposed_ws,@pytest.fixture kvmd testenv/tests *.py testenv/linters/vulture-wl.py'
deps = deps =
vulture vulture
@ -53,13 +53,13 @@ deps =
-rrequirements.txt -rrequirements.txt
[testenv:eslint] [testenv:eslint]
whitelist_externals = eslint allowlist_externals = eslint
commands = eslint --cache-location=/tmp --config=testenv/linters/eslintrc.yaml --color --ext .js web/share/js commands = eslint --cache-location=/tmp --config=testenv/linters/eslintrc.yaml --color --ext .js web/share/js
[testenv:htmlhint] [testenv:htmlhint]
whitelist_externals = htmlhint allowlist_externals = htmlhint
commands = htmlhint --config=testenv/linters/htmlhint.json web/*.html web/*/*.html commands = htmlhint --config=testenv/linters/htmlhint.json web/*.html web/*/*.html
[testenv:shellcheck] [testenv:shellcheck]
whitelist_externals = bash allowlist_externals = bash
commands = bash -c 'shellcheck --color=always kvmd.install scripts/*' commands = bash -c 'shellcheck --color=always kvmd.install scripts/*'