From 48cabf5b3d09c1cf4885e83283c1e7a6078303ae Mon Sep 17 00:00:00 2001 From: dgw Date: Sat, 12 Mar 2022 19:52:44 -0600 Subject: [PATCH] deps: forget about `python_version` specifier for `importlib_metadata` My clean install of Python 3.10 on Ubuntu 20.04 (via deadsnakes/ppa) came with an old version of `importlib_metadata` that tripped up the fallback logic I so carefully included. Rather than contort the import logic, let's just use the backport until Sopel no longer supports Python versions where stdlib can't replace it. --- requirements.txt | 2 +- sopel/__init__.py | 8 +++----- sopel/plugins/__init__.py | 11 +++++------ sopel/plugins/handlers.py | 6 ++++-- test/plugins/test_plugins_handlers.py | 8 ++------ test/test_plugins.py | 8 ++------ 6 files changed, 17 insertions(+), 26 deletions(-) diff --git a/requirements.txt b/requirements.txt index f2492374ae..1e8559009d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,5 +5,5 @@ geoip2>=4.0,<5.0 requests>=2.24.0,<3.0.0 dnspython<3.0 sqlalchemy>=1.4,<1.5 -importlib_metadata>=3.6; python_version < '3.10' +importlib_metadata>=3.6 packaging diff --git a/sopel/__init__.py b/sopel/__init__.py index 82b8f0a0c4..fde0da5e07 100644 --- a/sopel/__init__.py +++ b/sopel/__init__.py @@ -16,11 +16,9 @@ import re import sys -try: - import importlib.metadata as importlib_metadata -except ImportError: - # TODO: remove fallback when dropping py3.7 - import importlib_metadata +# TODO: replace with stdlib importlib.metadata when dropping py3.7 +# version info used in this module works from py3.8+ +import importlib_metadata __all__ = [ 'bot', diff --git a/sopel/plugins/__init__.py b/sopel/plugins/__init__.py index 6a59149a6a..d5f55a3a86 100644 --- a/sopel/plugins/__init__.py +++ b/sopel/plugins/__init__.py @@ -33,12 +33,11 @@ import itertools import os -try: - import importlib_metadata -except ImportError: - # TODO: use stdlib only when possible, after dropping py3.9 - # stdlib does not support `entry_points(group='filter')` until py3.10 - import importlib.metadata as importlib_metadata +# TODO: use stdlib importlib.metadata when possible, after dropping py3.9. +# Stdlib does not support `entry_points(group='filter')` until py3.10, but +# fallback logic is more trouble than it's worth when e.g. clean Ubuntu +# py3.10 envs include old versions of this backport. +import importlib_metadata from . import exceptions, handlers, rules # noqa diff --git a/sopel/plugins/handlers.py b/sopel/plugins/handlers.py index c16d7852fb..dfd5d61c61 100644 --- a/sopel/plugins/handlers.py +++ b/sopel/plugins/handlers.py @@ -559,8 +559,10 @@ class EntryPointPlugin(PyModulePlugin): Entry points are a `standard packaging mechanism`__ for Python, used by other applications (such as ``pytest``) for their plugins. - The ``importlib_metadata`` backport package is used on Python versions - older than 3.10, but its API is the same as :mod:`importlib.metadata`. + The ``importlib_metadata`` backport package is used for consistency + across all of Sopel's supported Python versions. Its API matches that + of :mod:`importlib.metadata` from Python 3.10 and up; Sopel will drop + this external requirement when practical. .. __: https://packaging.python.org/en/latest/specifications/entry-points/ diff --git a/test/plugins/test_plugins_handlers.py b/test/plugins/test_plugins_handlers.py index 1bc26fcd3c..34ccaadbee 100644 --- a/test/plugins/test_plugins_handlers.py +++ b/test/plugins/test_plugins_handlers.py @@ -4,14 +4,10 @@ import os import sys +# TODO: use stdlib importlib.metadata when dropping py3.9 +import importlib_metadata import pytest -try: - import importlib.metadata as importlib_metadata -except ImportError: - # TODO: remove fallback when dropping py3.9 - import importlib_metadata - from sopel.plugins import handlers diff --git a/test/test_plugins.py b/test/test_plugins.py index ced8914988..21b77c7d41 100644 --- a/test/test_plugins.py +++ b/test/test_plugins.py @@ -3,14 +3,10 @@ import sys +# TODO: switch to stdlib importlib.metdata when dropping py3.9 +import importlib_metadata import pytest -try: - import importlib.metadata as importlib_metadata -except ImportError: - # TODO: remove fallback when dropping py3.9 - import importlib_metadata - from sopel import plugins