Skip to content

Commit 281dd60

Browse files
rtuck99ndevenish
andauthored
Update python minimum to 3.10, remove pkg_resources (#184)
Remove pkg_resources dependency, and update minimum required python to 3.10 so that we get the stable API for importlib.metadata. Update CI to reflect new minimum version and run pyupgrade/ruff safe fixes for migrating to the new minimum support level. Fixes #180. Co-authored-by: Nicholas Devenish <[email protected]>
1 parent 5872b45 commit 281dd60

File tree

17 files changed

+108
-91
lines changed

17 files changed

+108
-91
lines changed

.github/workflows/python.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
runs-on: ubuntu-latest
2727
strategy:
2828
matrix:
29-
python-version: ["3.9", "3.10", "3.11", "3.12"]
29+
python-version: ["3.10", "3.11", "3.12"]
3030

3131
steps:
3232
- uses: actions/checkout@v4
@@ -57,9 +57,9 @@ jobs:
5757
permissions:
5858
id-token: write
5959
steps:
60-
- uses: actions/download-artifact@v4
61-
with:
60+
- uses: actions/download-artifact@v4
61+
with:
6262
name: artifact
6363
path: dist
64-
- name: Publish package distributions to PyPI
65-
uses: pypa/gh-action-pypi-publish@ec4db0b4ddc65acdf4bff5fa45ac92d78b56bdf0
64+
- name: Publish package distributions to PyPI
65+
uses: pypa/gh-action-pypi-publish@ec4db0b4ddc65acdf4bff5fa45ac92d78b56bdf0

pyproject.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,11 @@ classifiers = [
1515
"Intended Audience :: Developers",
1616
"License :: OSI Approved :: BSD License",
1717
"Programming Language :: Python :: 3",
18-
"Programming Language :: Python :: 3.8",
19-
"Programming Language :: Python :: 3.9",
20-
"Programming Language :: Python :: 3.10",
21-
"Programming Language :: Python :: 3.11",
2218
"Operating System :: OS Independent",
2319
"Topic :: Software Development :: Libraries :: Python Modules",
2420
]
2521
license = { text = "BSD-3-Clause" }
26-
requires-python = ">=3.8"
22+
requires-python = ">=3.10"
2723
dependencies = ["bidict", "pika", "setuptools", "stomp-py>=7"]
2824

2925
[project.urls]

src/workflows/contrib/status_monitor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import curses
44
import threading
55
import time
6-
from typing import Any, Dict
6+
from typing import Any
77

88
import workflows.transport
99
from workflows.services.common_service import CommonService
@@ -19,7 +19,7 @@ class Monitor: # pragma: no cover
1919
shutdown = False
2020
"""Set to true to end the main loop and shut down the service monitor."""
2121

22-
cards: Dict[Any, Any] = {}
22+
cards: dict[Any, Any] = {}
2323
"""Register card shown for seen services"""
2424

2525
border_chars = ()

src/workflows/recipe/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from __future__ import annotations
22

33
import functools
4-
from typing import Any, Callable
4+
from collections.abc import Callable
5+
from typing import Any
56

67
from workflows.recipe.recipe import Recipe
78
from workflows.recipe.validate import validate_recipe

src/workflows/recipe/recipe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import copy
44
import json
55
import string
6-
from typing import Any, Dict
6+
from typing import Any
77

88
import workflows
99

@@ -15,7 +15,7 @@ class Recipe:
1515
A recipe describes how all involved services are connected together, how
1616
data should be passed and how errors should be handled."""
1717

18-
recipe: Dict[Any, Any] = {}
18+
recipe: dict[Any, Any] = {}
1919
"""The processing recipe is encoded in this dictionary."""
2020
# TODO: Describe format
2121

src/workflows/recipe/wrapper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import logging
44
import time
5-
from typing import Any, Callable
5+
from collections.abc import Callable
6+
from typing import Any
67

78
import workflows.recipe
89

src/workflows/services/__init__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
import pkg_resources
3+
from importlib.metadata import entry_points
44

55

66
def lookup(service: str):
@@ -25,10 +25,7 @@ def get_known_services():
2525
setattr(
2626
get_known_services,
2727
"cache",
28-
{
29-
e.name: e.load
30-
for e in pkg_resources.iter_entry_points("workflows.services")
31-
},
28+
{e.name: e.load for e in entry_points(group="workflows.services")},
3229
)
3330
register = get_known_services.cache.copy()
3431
return register

src/workflows/services/common_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import queue
88
import threading
99
import time
10-
from typing import Any, Dict
10+
from typing import Any
1111

1212
import workflows
1313
import workflows.logging
@@ -128,7 +128,7 @@ def in_shutdown(self):
128128

129129
# Any keyword arguments set on service invocation
130130

131-
start_kwargs: Dict[Any, Any] = {}
131+
start_kwargs: dict[Any, Any] = {}
132132

133133
# Not so overrideable functions ---------------------------------------------
134134

src/workflows/transport/__init__.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22

33
import argparse
44
import optparse
5-
from typing import TYPE_CHECKING, Type
6-
7-
import pkg_resources
5+
from importlib.metadata import entry_points
6+
from typing import TYPE_CHECKING
87

98
if TYPE_CHECKING:
109
from .common_transport import CommonTransport
1110

1211
default_transport = "PikaTransport"
1312

1413

15-
def lookup(transport: str) -> Type[CommonTransport]:
14+
def lookup(transport: str) -> type[CommonTransport]:
1615
"""Get a transport layer class based on its name."""
1716
return get_known_transports().get(
1817
transport, get_known_transports()[default_transport]
@@ -55,15 +54,12 @@ def add_command_line_options(
5554
transport().add_command_line_options(parser)
5655

5756

58-
def get_known_transports() -> dict[str, Type[CommonTransport]]:
57+
def get_known_transports() -> dict[str, type[CommonTransport]]:
5958
"""Return a dictionary of all known transport mechanisms."""
6059
if not hasattr(get_known_transports, "cache"):
6160
setattr(
6261
get_known_transports,
6362
"cache",
64-
{
65-
e.name: e.load()
66-
for e in pkg_resources.iter_entry_points("workflows.transport")
67-
},
63+
{e.name: e.load() for e in entry_points(group="workflows.transport")},
6864
)
6965
return get_known_transports.cache.copy() # type: ignore

src/workflows/transport/common_transport.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import decimal
44
import logging
5-
from typing import Any, Callable, Dict, Mapping, NamedTuple, Optional, Set, Type
5+
from collections.abc import Callable, Mapping
6+
from typing import Any, NamedTuple
67

78
import workflows
89
from workflows.transport import middleware
@@ -20,9 +21,9 @@ class CommonTransport:
2021
subscriptions and transactions."""
2122

2223
__callback_interceptor = None
23-
__subscriptions: Dict[int, Dict[str, Any]] = {}
24+
__subscriptions: dict[int, dict[str, Any]] = {}
2425
__subscription_id: int = 0
25-
__transactions: Set[int] = set()
26+
__transactions: set[int] = set()
2627
__transaction_id: int = 0
2728

2829
log = logging.getLogger("workflows.transport")
@@ -32,14 +33,14 @@ class CommonTransport:
3233
#
3334

3435
def __init__(
35-
self, middleware: list[Type[middleware.BaseTransportMiddleware]] = None
36+
self, middleware: list[type[middleware.BaseTransportMiddleware]] = None
3637
):
3738
if middleware is None:
3839
self.middleware = []
3940
else:
4041
self.middleware = middleware
4142

42-
def add_middleware(self, middleware: Type[middleware.BaseTransportMiddleware]):
43+
def add_middleware(self, middleware: type[middleware.BaseTransportMiddleware]):
4344
self.middleware.insert(0, middleware)
4445

4546
@classmethod
@@ -99,7 +100,7 @@ def mangled_callback(header, message):
99100

100101
@middleware.wrap
101102
def subscribe_temporary(
102-
self, channel_hint: Optional[str], callback: MessageCallback, **kwargs
103+
self, channel_hint: str | None, callback: MessageCallback, **kwargs
103104
) -> TemporarySubscription:
104105
"""Listen to a new queue that is specifically created for this connection,
105106
and has a limited lifetime. Notify for messages via callback function.
@@ -320,7 +321,7 @@ def broadcast_status(self, status: dict) -> None:
320321
raise NotImplementedError
321322

322323
@middleware.wrap
323-
def ack(self, message, subscription_id: Optional[int] = None, **kwargs):
324+
def ack(self, message, subscription_id: int | None = None, **kwargs):
324325
"""Acknowledge receipt of a message. This only makes sense when the
325326
'acknowledgement' flag was set for the relevant subscription.
326327
:param message: ID of the message to be acknowledged, OR a dictionary
@@ -351,7 +352,7 @@ def ack(self, message, subscription_id: Optional[int] = None, **kwargs):
351352
self._ack(message_id, subscription_id=subscription_id, **kwargs)
352353

353354
@middleware.wrap
354-
def nack(self, message, subscription_id: Optional[int] = None, **kwargs):
355+
def nack(self, message, subscription_id: int | None = None, **kwargs):
355356
"""Reject receipt of a message. This only makes sense when the
356357
'acknowledgement' flag was set for the relevant subscription.
357358
:param message: ID of the message to be rejected, OR a dictionary
@@ -380,7 +381,7 @@ def nack(self, message, subscription_id: Optional[int] = None, **kwargs):
380381
self._nack(message_id, subscription_id=subscription_id, **kwargs)
381382

382383
@middleware.wrap
383-
def transaction_begin(self, subscription_id: Optional[int] = None, **kwargs) -> int:
384+
def transaction_begin(self, subscription_id: int | None = None, **kwargs) -> int:
384385
"""Start a new transaction.
385386
:param **kwargs: Further parameters for the transport layer.
386387
:return: A transaction ID that can be passed to other functions.
@@ -462,7 +463,7 @@ def _subscribe_broadcast(self, sub_id: int, channel, callback, **kwargs):
462463
def _subscribe_temporary(
463464
self,
464465
sub_id: int,
465-
channel_hint: Optional[str],
466+
channel_hint: str | None,
466467
callback: MessageCallback,
467468
**kwargs,
468469
) -> str:
@@ -530,7 +531,7 @@ def _nack(self, message_id, subscription_id, **kwargs):
530531
raise NotImplementedError("Transport interface not implemented")
531532

532533
def _transaction_begin(
533-
self, transaction_id: int, *, subscription_id: Optional[int] = None, **kwargs
534+
self, transaction_id: int, *, subscription_id: int | None = None, **kwargs
534535
) -> None:
535536
"""Start a new transaction.
536537
:param transaction_id: ID for this transaction in the transport layer.

0 commit comments

Comments
 (0)