From b20f7dac3f9b9f28fc85588c9e1ce3f8419dce98 Mon Sep 17 00:00:00 2001 From: Nicholas Devenish Date: Fri, 13 Sep 2024 15:46:17 +0100 Subject: [PATCH] Revert "Remove pkg_resources dependency" and test Python 3.12 (#183) * Revert "Remove dependency on pkg_resources in favour of importlib (#181)" This ran into the python 3.8/3.10/3.12 cross-compatibility issue. * Add python 3.12 to azure testing This should avoid this problem happening again (and github actions should now run properly). --- .azure-pipelines/azure-pipelines.yml | 2 ++ src/workflows/services/__init__.py | 7 +++++-- src/workflows/transport/__init__.py | 8 ++++++-- tests/services/test.py | 13 ------------- tests/transport/test.py | 14 +------------- 5 files changed, 14 insertions(+), 30 deletions(-) diff --git a/.azure-pipelines/azure-pipelines.yml b/.azure-pipelines/azure-pipelines.yml index bc334545..74b572fd 100644 --- a/.azure-pipelines/azure-pipelines.yml +++ b/.azure-pipelines/azure-pipelines.yml @@ -88,5 +88,7 @@ stages: PYTHON_VERSION: 3.10 python311: PYTHON_VERSION: 3.11 + python312: + PYTHON_VERSION: 3.12 steps: - template: ci.yml diff --git a/src/workflows/services/__init__.py b/src/workflows/services/__init__.py index 458ad7ea..9b008ab7 100644 --- a/src/workflows/services/__init__.py +++ b/src/workflows/services/__init__.py @@ -1,6 +1,6 @@ from __future__ import annotations -from importlib.metadata import entry_points +import pkg_resources def lookup(service: str): @@ -25,7 +25,10 @@ def get_known_services(): setattr( get_known_services, "cache", - {e.name: e.load for e in entry_points()["workflows.services"]}, + { + e.name: e.load + for e in pkg_resources.iter_entry_points("workflows.services") + }, ) register = get_known_services.cache.copy() return register diff --git a/src/workflows/transport/__init__.py b/src/workflows/transport/__init__.py index e62a4e1f..0ede6b1b 100644 --- a/src/workflows/transport/__init__.py +++ b/src/workflows/transport/__init__.py @@ -2,9 +2,10 @@ import argparse import optparse -from importlib.metadata import entry_points from typing import TYPE_CHECKING, Type +import pkg_resources + if TYPE_CHECKING: from .common_transport import CommonTransport @@ -60,6 +61,9 @@ def get_known_transports() -> dict[str, Type[CommonTransport]]: setattr( get_known_transports, "cache", - {e.name: e.load() for e in entry_points()["workflows.transport"]}, + { + e.name: e.load() + for e in pkg_resources.iter_entry_points("workflows.transport") + }, ) return get_known_transports.cache.copy() # type: ignore diff --git a/tests/services/test.py b/tests/services/test.py index d0277811..388b4d47 100644 --- a/tests/services/test.py +++ b/tests/services/test.py @@ -1,21 +1,8 @@ from __future__ import annotations import workflows.services -from workflows.services.common_service import CommonService def test_known_services_is_a_dictionary(): """Check services register build in CommonService.""" assert isinstance(workflows.services.get_known_services(), dict) - - -def test_enumerate_services(): - """Verify we can discover the installed services.""" - services = workflows.services.get_known_services() - assert services.keys() == { - "SampleConsumer", - "SampleProducer", - "SampleTxn", - "SampleTxnProducer", - } - assert all([issubclass(service(), CommonService) for service in services.values()]) diff --git a/tests/transport/test.py b/tests/transport/test.py index bde7fab2..9c55a1f8 100644 --- a/tests/transport/test.py +++ b/tests/transport/test.py @@ -1,23 +1,11 @@ from __future__ import annotations import workflows.transport -from workflows.transport.common_transport import CommonTransport def test_known_transports_is_a_dictionary(): """Check transport register build in CommonTransport.""" - transports = workflows.transport.get_known_transports() - print(transports) - assert isinstance(transports, dict) - - -def test_enumerate_transports(): - """Verify we can discover the installed transports.""" - transports = workflows.transport.get_known_transports() - assert transports.keys() == {"OfflineTransport", "PikaTransport", "StompTransport"} - assert all( - [issubclass(transport, CommonTransport) for transport in transports.values()] - ) + assert isinstance(workflows.transport.get_known_transports(), dict) def test_load_any_transport():