Skip to content

Commit

Permalink
deps: forget about python_version specifier for importlib_metadata
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dgw committed Mar 13, 2022
1 parent 4a72004 commit 48cabf5
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 26 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 3 additions & 5 deletions sopel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
11 changes: 5 additions & 6 deletions sopel/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions sopel/plugins/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
8 changes: 2 additions & 6 deletions test/plugins/test_plugins_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
8 changes: 2 additions & 6 deletions test/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 48cabf5

Please sign in to comment.