From 969de2944a7f083f5a906622da916046c62892dd Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sat, 5 Oct 2024 02:56:50 +0900 Subject: [PATCH] Drop usage of importlib_metadata This is follow-up of b7fe561d0980db5c3d6d5ef9fb5b9a036d5cdbd1 and use TypeError caused by the interface change as the key, instead of python versions, which may work better for distributions with own feature backports. Change-Id: I84113cf1dc4de0481c9878a83e2dcd99a8fe69b9 --- neutron/conf/db/migration_cli.py | 22 +++++++++++++--------- requirements.txt | 3 --- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/neutron/conf/db/migration_cli.py b/neutron/conf/db/migration_cli.py index e28ad9a8b7e..73abd5941d6 100644 --- a/neutron/conf/db/migration_cli.py +++ b/neutron/conf/db/migration_cli.py @@ -10,22 +10,26 @@ # License for the specific language governing permissions and limitations # under the License. -import sys +from importlib.metadata import entry_points from oslo_config import cfg from neutron._i18n import _ -if sys.version_info < (3, 10, 0): - from importlib_metadata import entry_points -else: - from importlib.metadata import entry_points MIGRATION_ENTRYPOINTS = 'neutron.db.alembic_migrations' -migration_entrypoints = { - entrypoint.name: entrypoint - for entrypoint in entry_points(group=MIGRATION_ENTRYPOINTS) -} + +try: + migration_entrypoints = { + entrypoint.name: entrypoint + for entrypoint in entry_points(group=MIGRATION_ENTRYPOINTS) + } +except TypeError: + # For python < 3.10 + migration_entrypoints = { + entrypoint.name: entrypoint + for entrypoint in entry_points()[MIGRATION_ENTRYPOINTS] + } INSTALLED_SUBPROJECTS = list(migration_entrypoints) diff --git a/requirements.txt b/requirements.txt index 2fc62781c0c..96991315f05 100644 --- a/requirements.txt +++ b/requirements.txt @@ -56,6 +56,3 @@ python-designateclient>=2.7.0 # Apache-2.0 os-vif>=3.1.0 # Apache-2.0 futurist>=1.2.0 # Apache-2.0 tooz>=1.58.0 # Apache-2.0 - -# TODO(tkajinam): Remove importlib_metadata when python 3.9 support is dropped -importlib_metadata>=3.6;python_version<"3.10" # Apache-2.0