Skip to content

Commit 893f93d

Browse files
authored
Merge pull request #23 from Jajcus/modern_python
update for modern Python versions (3.9 - 3.14)
2 parents 06e8322 + dddc7c4 commit 893f93d

30 files changed

Lines changed: 64 additions & 76 deletions

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
strategy:
4343
fail-fast: false
4444
matrix:
45-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
45+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
4646

4747
steps:
4848
- uses: actions/checkout@v3
@@ -110,10 +110,10 @@ jobs:
110110
with:
111111
fetch-depth: 0
112112

113-
- name: Set up Python 3.8
113+
- name: Set up Python 3.9
114114
uses: actions/setup-python@v4
115115
with:
116-
python-version: 3.8
116+
python-version: 3.9
117117

118118
- name: Install dependencies
119119
run: |

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
repos:
22
- repo: https://github.com/pycqa/flake8
3-
rev: '7.0.0'
3+
rev: '7.3.0'
44
hooks:
55
- id: flake8
66
exclude: pbx_api_client/v1
77
- repo: https://github.com/pycqa/isort
8-
rev: 5.13.2
8+
rev: '7.0.0'
99
hooks:
1010
- id: isort
1111
name: isort (python)

alsa_midi/address.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
21
from collections import namedtuple
3-
from typing import TYPE_CHECKING, Any, Tuple, Union, overload
2+
from typing import TYPE_CHECKING, Any, Union, overload
43

54
from ._ffi import alsa, ffi
65
from .util import _check_alsa_error
@@ -10,7 +9,7 @@
109
from .port import Port, PortInfo
1110

1211

13-
AddressType = Union['Address', 'Port', 'PortInfo', Tuple[int, int]]
12+
AddressType = Union['Address', 'Port', 'PortInfo', tuple[int, int]]
1413

1514

1615
class Address(namedtuple("Address", "client_id port_id")):
@@ -79,7 +78,7 @@ def __new__(cls,
7978
return tuple.__new__(cls, tple)
8079

8180
@staticmethod
82-
def _parse(arg: str) -> Tuple[int, int]:
81+
def _parse(arg: str) -> tuple[int, int]:
8382
addr_p = ffi.new("snd_seq_addr_t *")
8483
result = alsa.snd_seq_parse_address(ffi.NULL, addr_p, arg.encode())
8584
_check_alsa_error(result)

alsa_midi/client.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
21
import asyncio
32
import errno
43
import select
54
import time
5+
from collections.abc import MutableMapping
66
from dataclasses import dataclass, field
77
from enum import IntEnum, IntFlag
88
from functools import partial
9-
from typing import (Any, Callable, List, MutableMapping, NewType, Optional, Set, Tuple, Union,
10-
overload)
9+
from typing import Any, Callable, NewType, Optional, Union, overload
1110
from weakref import WeakValueDictionary
1211

1312
from ._ffi import alsa, ffi
@@ -21,7 +20,7 @@
2120
from .util import _check_alsa_error
2221

2322
_snd_seq_t = NewType("_snd_seq_t", object)
24-
_snd_seq_t_p = NewType("_snd_seq_t_p", Tuple[_snd_seq_t])
23+
_snd_seq_t_p = NewType("_snd_seq_t_p", tuple[_snd_seq_t])
2524
_snd_midi_event_t = NewType("_snd_midi_event_t", object)
2625

2726

@@ -90,7 +89,7 @@ class ClientInfo:
9089
pid: Optional[int] = None
9190
num_ports: int = 0
9291
event_lost: int = 0
93-
event_filter: Optional[Set[EventType]] = None
92+
event_filter: Optional[set[EventType]] = None
9493

9594
@classmethod
9695
def _from_alsa(cls, info: _snd_seq_client_info_t):
@@ -661,7 +660,7 @@ def drop_output_buffer(self):
661660
err = alsa.snd_seq_drop_output_buffer(self.handle)
662661
_check_alsa_error(err)
663662

664-
def _event_input(self, prefer_bytes: bool = False) -> Tuple[int, Optional[Event]]:
663+
def _event_input(self, prefer_bytes: bool = False) -> tuple[int, Optional[Event]]:
665664
buf = ffi.new("snd_seq_event_t**", ffi.NULL)
666665
result = alsa.snd_seq_event_input(self.handle, buf)
667666
if result < 0:
@@ -730,7 +729,7 @@ def _prepare_event(self,
730729
queue: Union['Queue', int] = None,
731730
port: Union['Port', int] = None,
732731
dest: AddressType = None,
733-
remainder: Optional[Any] = None) -> Tuple[_snd_seq_event_t, Any]:
732+
remainder: Optional[Any] = None) -> tuple[_snd_seq_event_t, Any]:
734733
"""Prepare ALSA :alsa:`snd_seq_event_t` for given `event` object for output.
735734
736735
For :class:`alsa_midi.MidiBytesEvent` may need to be called more than
@@ -780,7 +779,7 @@ def _event_output(self,
780779
queue: Union['Queue', int] = None,
781780
port: Union['Port', int] = None,
782781
dest: AddressType = None,
783-
remainder: Optional[Any] = None) -> Tuple[int, Any]:
782+
remainder: Optional[Any] = None) -> tuple[int, Any]:
784783
alsa_event, remainder = self._prepare_event(event,
785784
queue=queue, port=port, dest=dest,
786785
remainder=remainder)
@@ -864,7 +863,7 @@ def _event_output_direct(self,
864863
queue: Union['Queue', int] = None,
865864
port: Union['Port', int] = None,
866865
dest: AddressType = None,
867-
remainder: Optional[Any] = None) -> Tuple[int, Any]:
866+
remainder: Optional[Any] = None) -> tuple[int, Any]:
868867
alsa_event, remainder = self._prepare_event(event,
869868
queue=queue, port=port, dest=dest,
870869
remainder=remainder)
@@ -1114,7 +1113,7 @@ def list_ports(self, *,
11141113
include_no_export: bool = True,
11151114
only_connectable: bool = True,
11161115
sort: Union[bool, Callable[[PortInfo], Any]] = True,
1117-
) -> List[PortInfo]:
1116+
) -> list[PortInfo]:
11181117
"""More friendly interface to list available ports.
11191118
11201119
Queries ALSA for all clients and ports and returns those matching the selected criteria.
@@ -1327,7 +1326,7 @@ def query_port_subscribers(self,
13271326
def list_port_subscribers(self,
13281327
port: AddressType,
13291328
type: Optional[SubscriptionQueryType] = None,
1330-
) -> List[SubscriptionQuery]:
1329+
) -> list[SubscriptionQuery]:
13311330
"""Lists subscribers accessing a port.
13321331
13331332
Wraps :alsa:`snd_seq_query_port_subscribers`.

alsa_midi/event.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
1+
from collections.abc import Iterable
22
from enum import IntEnum, IntFlag
33
from functools import total_ordering
4-
from typing import TYPE_CHECKING, Any, Iterable, NewType, Optional, Union
4+
from typing import TYPE_CHECKING, Any, NewType, Optional, Union
55

66
from ._ffi import alsa, ffi
77
from .address import Address, AddressType

alsa_midi/mido_backend.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
import queue
1414
import sys
1515
import threading
16-
from typing import Any, Callable, List, MutableMapping, Optional
16+
from collections.abc import MutableMapping
17+
from typing import Any, Callable, Optional
1718
from weakref import WeakValueDictionary
1819

1920
from mido.messages import Message
@@ -92,7 +93,7 @@ def get_devices(*args, **kwargs):
9293
return client.get_devices(*args, **kwargs)
9394

9495

95-
def _find_port(ports: List[alsa_midi.PortInfo], name: str) -> alsa_midi.PortInfo:
96+
def _find_port(ports: list[alsa_midi.PortInfo], name: str) -> alsa_midi.PortInfo:
9697
try:
9798
addr = alsa_midi.Address(name)
9899
except (ValueError, alsa_midi.exceptions.ALSAError):
@@ -104,7 +105,7 @@ def _find_port(ports: List[alsa_midi.PortInfo], name: str) -> alsa_midi.PortInfo
104105
if addr == alsa_midi.Address(port):
105106
return port
106107
else:
107-
raise IOError(f"unknown port {name!r}")
108+
raise OSError(f"unknown port {name!r}")
108109

109110
# check for exact match with name from get_devices()
110111
for port in ports:
@@ -128,10 +129,10 @@ def _find_port(ports: List[alsa_midi.PortInfo], name: str) -> alsa_midi.PortInfo
128129
if name == port.name:
129130
return port
130131

131-
raise IOError(f"unknown port {name!r}")
132+
raise OSError(f"unknown port {name!r}")
132133

133134

134-
class PortCommon(object):
135+
class PortCommon:
135136
_last_num = 0
136137
_name_prefix = "inout"
137138
_caps = alsa_midi.PortCaps.READ | alsa_midi.PortCaps.WRITE
@@ -182,7 +183,7 @@ def _open(self, virtual=False, **kwargs):
182183
ports = client.client.list_ports(input=self._for_input, output=self._for_output)
183184

184185
if not ports:
185-
raise IOError('no ports available')
186+
raise OSError('no ports available')
186187

187188
if self.name is None:
188189
dest_port = ports[0]
@@ -200,9 +201,9 @@ def _open(self, virtual=False, **kwargs):
200201
self._dest_port = dest_port
201202

202203
api = 'seq'
203-
self._device_type = 'AlsaMidi/{}'.format(api)
204+
self._device_type = f'AlsaMidi/{api}'
204205
if virtual:
205-
self._device_type = 'virtual {}'.format(self._device_type)
206+
self._device_type = f'virtual {self._device_type}'
206207

207208
client.ports[self._port.port_id] = self
208209

alsa_midi/port.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
21
from dataclasses import InitVar, dataclass, field
32
from enum import IntFlag
4-
from typing import TYPE_CHECKING, Any, Callable, List, NewType, Optional
3+
from typing import TYPE_CHECKING, Any, Callable, NewType, Optional
54

65
from ._ffi import alsa, ffi
76
from .address import Address, AddressType
@@ -176,7 +175,7 @@ def set_info(self, info: 'PortInfo'):
176175
raise StateError("Already closed")
177176
return self.client.set_port_info(self, info)
178177

179-
def list_subscribers(self, type: 'SubscriptionQueryType' = None) -> List['SubscriptionQuery']:
178+
def list_subscribers(self, type: 'SubscriptionQueryType' = None) -> list['SubscriptionQuery']:
180179
"""Lists subscribers accessing a port.
181180
182181
Wraps :alsa:`snd_seq_query_port_subscribers`.
@@ -286,7 +285,7 @@ def _to_alsa(self) -> _snd_seq_port_info_t:
286285
return info
287286

288287

289-
def get_port_info_sort_key(preferred_types: List[PortType] = []
288+
def get_port_info_sort_key(preferred_types: list[PortType] = []
290289
) -> Callable[[PortInfo], Any]:
291290
"""Return a :class:`PortInfo` sorting key function for given type
292291
preference."""

alsa_midi/queue.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
from dataclasses import dataclass, field
32
from enum import IntEnum
43
from typing import TYPE_CHECKING, NamedTuple, NewType, Optional, Union

alsa_midi/util.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
from ._ffi import alsa, ffi
32
from .exceptions import ALSAError
43

build-wheels.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ fi
5757
git config --global --add safe.directory "$GITHUB_WORKSPACE"
5858

5959
# Compile wheels
60-
for PYBIN in /opt/python/cp{37,38,39,310,311}*/bin; do
60+
for PYBIN in /opt/python/cp{39,310,311,312,313,314}*/bin; do
6161
[ -d "$PYBIN" ] || continue
62+
if [[ "$PYBIN" =~ 313t ]] ; then
63+
echo "Skipping 313t variant, as it is incompatible with cffi"
64+
continue
65+
fi
6266
"${PYBIN}/pip" install --upgrade pip setuptools
6367
"${PYBIN}/pip" install -r "$GITHUB_WORKSPACE/requirements.txt"
6468

@@ -76,8 +80,12 @@ rm wheelhouse/*-linux_*.whl
7680

7781
# Install packages and test
7882
cd /
79-
for PYBIN in /opt/python/cp{37,38,39,310,311}*/bin/; do
83+
for PYBIN in /opt/python/cp{39,310,311,312,313,314}*/bin/; do
8084
[ -d "$PYBIN" ] || continue
85+
if [[ "$PYBIN" =~ 313t ]] ; then
86+
echo "Skipping 313t variant, as it is incompatible with cffi"
87+
continue
88+
fi
8189

8290
"${PYBIN}/pip" install pytest pytest-asyncio
8391
"${PYBIN}/pip" install alsa-midi --no-index -f "$GITHUB_WORKSPACE/wheelhouse/"

0 commit comments

Comments
 (0)