Compare commits

..

2 Commits

Author SHA1 Message Date
ce5936b740 lint fixes
ruff added to dev dependencies

ruff badge added to readme
2023-10-29 09:40:10 +00:00
2e1916eeaa moves timeout login into decorator function
patch bump
2023-10-29 09:20:56 +00:00
10 changed files with 169 additions and 30 deletions

View File

@ -3,6 +3,7 @@
[![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/) [![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/) [![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
![Tests Status](./tests/basic.svg?dummy=8484744) ![Tests Status](./tests/basic.svg?dummy=8484744)
![Tests Status](./tests/banana.svg?dummy=8484744) ![Tests Status](./tests/banana.svg?dummy=8484744)
![Tests Status](./tests/potato.svg?dummy=8484744) ![Tests Status](./tests/potato.svg?dummy=8484744)

28
poetry.lock generated
View File

@ -281,6 +281,32 @@ files = [
[package.dependencies] [package.dependencies]
pytest = ">=3.6" pytest = ">=3.6"
[[package]]
name = "ruff"
version = "0.1.3"
description = "An extremely fast Python linter, written in Rust."
optional = false
python-versions = ">=3.7"
files = [
{file = "ruff-0.1.3-py3-none-macosx_10_7_x86_64.whl", hash = "sha256:b46d43d51f7061652eeadb426a9e3caa1e0002470229ab2fc19de8a7b0766901"},
{file = "ruff-0.1.3-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:b8afeb9abd26b4029c72adc9921b8363374f4e7edb78385ffaa80278313a15f9"},
{file = "ruff-0.1.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ca3cf365bf32e9ba7e6db3f48a4d3e2c446cd19ebee04f05338bc3910114528b"},
{file = "ruff-0.1.3-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:4874c165f96c14a00590dcc727a04dca0cfd110334c24b039458c06cf78a672e"},
{file = "ruff-0.1.3-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:eec2dd31eed114e48ea42dbffc443e9b7221976554a504767ceaee3dd38edeb8"},
{file = "ruff-0.1.3-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:dc3ec4edb3b73f21b4aa51337e16674c752f1d76a4a543af56d7d04e97769613"},
{file = "ruff-0.1.3-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:2e3de9ed2e39160800281848ff4670e1698037ca039bda7b9274f849258d26ce"},
{file = "ruff-0.1.3-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:1c595193881922cc0556a90f3af99b1c5681f0c552e7a2a189956141d8666fe8"},
{file = "ruff-0.1.3-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0f75e670d529aa2288cd00fc0e9b9287603d95e1536d7a7e0cafe00f75e0dd9d"},
{file = "ruff-0.1.3-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:76dd49f6cd945d82d9d4a9a6622c54a994689d8d7b22fa1322983389b4892e20"},
{file = "ruff-0.1.3-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:918b454bc4f8874a616f0d725590277c42949431ceb303950e87fef7a7d94cb3"},
{file = "ruff-0.1.3-py3-none-musllinux_1_2_i686.whl", hash = "sha256:d8859605e729cd5e53aa38275568dbbdb4fe882d2ea2714c5453b678dca83784"},
{file = "ruff-0.1.3-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:0b6c55f5ef8d9dd05b230bb6ab80bc4381ecb60ae56db0330f660ea240cb0d4a"},
{file = "ruff-0.1.3-py3-none-win32.whl", hash = "sha256:3e7afcbdcfbe3399c34e0f6370c30f6e529193c731b885316c5a09c9e4317eef"},
{file = "ruff-0.1.3-py3-none-win_amd64.whl", hash = "sha256:7a18df6638cec4a5bd75350639b2bb2a2366e01222825562c7346674bdceb7ea"},
{file = "ruff-0.1.3-py3-none-win_arm64.whl", hash = "sha256:12fd53696c83a194a2db7f9a46337ce06445fb9aa7d25ea6f293cf75b21aca9f"},
{file = "ruff-0.1.3.tar.gz", hash = "sha256:3ba6145369a151401d5db79f0a47d50e470384d0d89d0d6f7fab0b589ad07c34"},
]
[[package]] [[package]]
name = "tomli" name = "tomli"
version = "2.0.1" version = "2.0.1"
@ -342,4 +368,4 @@ test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "^3.10" python-versions = "^3.10"
content-hash = "4989717c148629166e597e8eea82d3f036f3dfd2e0ed15882260a621eff331aa" content-hash = "bbd3efdc7021e984366e10de75444d9ae83c1af56840421250e83f93e4e7dfb0"

View File

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "voicemeeter-api" name = "voicemeeter-api"
version = "2.5.1" version = "2.5.2"
description = "A Python wrapper for the Voiceemeter API" description = "A Python wrapper for the Voiceemeter API"
authors = ["onyx-and-iris <code@onyxandiris.online>"] authors = ["onyx-and-iris <code@onyxandiris.online>"]
license = "MIT" license = "MIT"
@ -20,6 +20,7 @@ pytest-repeat = "^0.9.1"
black = "^22.3.0" black = "^22.3.0"
isort = "^5.10.1" isort = "^5.10.1"
tox = "^4.6.3" tox = "^4.6.3"
ruff = "^0.1.3"
[build-system] [build-system]
requires = ["poetry-core>=1.0.0"] requires = ["poetry-core>=1.0.0"]
@ -49,3 +50,97 @@ commands =
poetry install -v poetry install -v
poetry run pytest tests/ poetry run pytest tests/
""" """
[tool.black]
line-length = 88
[tool.ruff]
select = [
"E",
"F",
]
ignore = [
"E501",
]
fixable = [
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"I",
"N",
"Q",
"S",
"T",
"W",
"ANN",
"ARG",
"BLE",
"COM",
"DJ",
"DTZ",
"EM",
"ERA",
"EXE",
"FBT",
"ICN",
"INP",
"ISC",
"NPY",
"PD",
"PGH",
"PIE",
"PL",
"PT",
"PTH",
"PYI",
"RET",
"RSE",
"RUF",
"SIM",
"SLF",
"TCH",
"TID",
"TRY",
"UP",
"YTT",
]
unfixable = []
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
]
line-length = 88
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
target-version = "py310"
[tool.ruff.mccabe]
max-complexity = 10
[tool.ruff.per-file-ignores]
"__init__.py" = [
"E402",
"F401",
]

View File

@ -16,7 +16,7 @@ class Event:
if self.any(): if self.any():
info += (f"now listening for {', '.join(self.get())} events",) info += (f"now listening for {', '.join(self.get())} events",)
else: else:
info += (f"not listening for any events",) info += ("not listening for any events",)
self.logger.info(", ".join(info)) self.logger.info(", ".join(info))
@property @property

View File

@ -37,7 +37,7 @@ def get_vmpath():
try: try:
vm_parent = Path(get_vmpath()).parent vm_parent = Path(get_vmpath()).parent
except FileNotFoundError as e: except FileNotFoundError as e:
raise InstallError(f"Unable to fetch DLL path from the registry") from e raise InstallError("Unable to fetch DLL path from the registry") from e
DLL_NAME = f'VoicemeeterRemote{"64" if bits == 64 else ""}.dll' DLL_NAME = f'VoicemeeterRemote{"64" if bits == 64 else ""}.dll'

View File

@ -70,7 +70,7 @@ class Patch(IRemote):
@property @property
def identifier(self) -> str: def identifier(self) -> str:
return f"patch" return "patch"
@property @property
def postfadercomp(self) -> bool: def postfadercomp(self) -> bool:
@ -92,7 +92,7 @@ class Patch(IRemote):
class Asio(IRemote): class Asio(IRemote):
@property @property
def identifier(self) -> str: def identifier(self) -> str:
return f"patch" return "patch"
class AsioIn(Asio): class AsioIn(Asio):

View File

@ -126,7 +126,7 @@ class Recorder(IRemote):
time_str = str(time_str) # coerce the type time_str = str(time_str) # coerce the type
if ( if (
match := re.match( re.match(
r"^(?:[01]\d|2[0123]):(?:[012345]\d):(?:[012345]\d)$", r"^(?:[01]\d|2[0123]):(?:[012345]\d):(?:[012345]\d)$",
time_str, time_str,
) )
@ -135,7 +135,7 @@ class Recorder(IRemote):
self.setter("goto", get_sec()) self.setter("goto", get_sec())
else: else:
self.logger.warning( self.logger.warning(
f"goto expects a string that matches the format 'hh:mm:ss'" "goto expects a string that matches the format 'hh:mm:ss'"
) )
def filetype(self, val: str): def filetype(self, val: str):

View File

@ -14,7 +14,7 @@ from .kinds import KindId
from .misc import Midi, VmGui from .misc import Midi, VmGui
from .subject import Subject from .subject import Subject
from .updater import Producer, Updater from .updater import Producer, Updater
from .util import deep_merge, grouper, polling, script from .util import deep_merge, grouper, polling, script, timeout
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -67,6 +67,7 @@ class Remote(CBindings):
def stopped(self): def stopped(self):
return self.stop_event is None or self.stop_event.is_set() return self.stop_event is None or self.stop_event.is_set()
@timeout
def login(self) -> None: def login(self) -> None:
"""Login to the API, initialize dirty parameters""" """Login to the API, initialize dirty parameters"""
self.gui.launched = self.call(self.bind_login, ok=(0, 1)) == 0 self.gui.launched = self.call(self.bind_login, ok=(0, 1)) == 0
@ -76,24 +77,6 @@ class Remote(CBindings):
) )
self.run_voicemeeter(self.kind.name) self.run_voicemeeter(self.kind.name)
err = None
start = time.time()
while time.time() < start + self.timeout:
try:
time.sleep(0.1) # ensure at least 0.1 delay before clearing dirty
self.logger.info(
f"{type(self).__name__}: Successfully logged into {self} version {self.version}"
)
self.logger.debug(f"login time: {round(time.time() - start, 2)}")
err = None
break
except CAPIError as e:
err = e
continue
if err:
raise VMError("Timeout logging into the api")
self.clear_dirty()
def run_voicemeeter(self, kind_id: str) -> None: def run_voicemeeter(self, kind_id: str) -> None:
if kind_id not in (kind.name.lower() for kind in KindId): if kind_id not in (kind.name.lower() for kind in KindId):
raise VMError(f"Unexpected Voicemeeter type: '{kind_id}'") raise VMError(f"Unexpected Voicemeeter type: '{kind_id}'")

View File

@ -90,7 +90,7 @@ class PhysicalStrip(Strip):
""" """
EFFECTS_cls = _make_effects_mixins(is_phys)[remote.kind.name] EFFECTS_cls = _make_effects_mixins(is_phys)[remote.kind.name]
return type( return type(
f"PhysicalStrip", "PhysicalStrip",
(cls, EFFECTS_cls), (cls, EFFECTS_cls),
{ {
"comp": StripComp(remote, i), "comp": StripComp(remote, i),
@ -337,7 +337,7 @@ class VirtualStrip(Strip):
""" """
EFFECTS_cls = _make_effects_mixins(is_phys)[remote.kind.name] EFFECTS_cls = _make_effects_mixins(is_phys)[remote.kind.name]
return type( return type(
f"VirtualStrip", "VirtualStrip",
(cls, EFFECTS_cls), (cls, EFFECTS_cls),
{}, {},
) )
@ -491,7 +491,7 @@ class GainLayer(IRemote):
def _make_gainlayer_mixin(remote, index): def _make_gainlayer_mixin(remote, index):
"""Creates a GainLayer mixin""" """Creates a GainLayer mixin"""
return type( return type(
f"GainlayerMixin", "GainlayerMixin",
(), (),
{ {
"gainlayer": tuple( "gainlayer": tuple(

View File

@ -1,7 +1,41 @@
import functools import functools
import time
from itertools import zip_longest from itertools import zip_longest
from typing import Iterator from typing import Iterator
from .error import CAPIError, VMError
def timeout(func):
"""
Times out the login function once time elapsed exceeds remote.timeout.
"""
@functools.wraps(func)
def wrapper(*args, **kwargs):
remote, *_ = args
func(*args, **kwargs)
err = None
start = time.time()
while time.time() < start + remote.timeout:
try:
time.sleep(0.1) # ensure at least 0.1 delay before clearing dirty
remote.logger.info(
f"{type(remote).__name__}: Successfully logged into {remote} version {remote.version}"
)
remote.logger.debug(f"login time: {round(time.time() - start, 2)}")
err = None
break
except CAPIError as e:
err = e
continue
if err:
raise VMError("Timeout logging into the api")
remote.clear_dirty()
return wrapper
def polling(func): def polling(func):
""" """