From a9f2b8cc7ba4dc591f44b9d1bc852c275a2d20fb Mon Sep 17 00:00:00 2001 From: Letu Ren Date: Tue, 9 Jan 2024 18:28:50 +0800 Subject: [PATCH] Switch to importlib-metadata to drop deprecated pkg_resources According to https://setuptools.pypa.io/en/latest/pkg_resources.html, pkg_resources has been deprecated and importlib-metadata is recommended. `DistributionNotFound` only can be thrown from `find_plugins()` which is not used by ia. Tested with plugin https://github.com/JesseWeinstein/ia_recent. Closes: https://github.com/jjjake/internetarchive/issues/613 --- internetarchive/cli/ia.py | 6 +++--- setup.cfg | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/internetarchive/cli/ia.py b/internetarchive/cli/ia.py index 8e044c36..9a5b2c70 100755 --- a/internetarchive/cli/ia.py +++ b/internetarchive/cli/ia.py @@ -64,7 +64,7 @@ import sys from docopt import docopt, printable_usage -from pkg_resources import DistributionNotFound, iter_entry_points +from importlib.metadata import entry_points from schema import Or, Schema, SchemaError # type: ignore[import] from internetarchive import __version__ @@ -97,11 +97,11 @@ def load_ia_module(cmd: str): return __import__(_module, fromlist=['internetarchive.cli']) else: _module = f'ia_{cmd}' - for ep in iter_entry_points('internetarchive.cli.plugins'): + for ep in entry_points(group='internetarchive.cli.plugins'): if ep.name == _module: return ep.load() raise ImportError - except (ImportError, DistributionNotFound): + except (ImportError): print(f"error: '{cmd}' is not an ia command! See 'ia help'", file=sys.stderr) matches = '\t'.join(difflib.get_close_matches(cmd, cmd_aliases.values())) diff --git a/setup.cfg b/setup.cfg index bec6295d..6201bf31 100644 --- a/setup.cfg +++ b/setup.cfg @@ -31,6 +31,7 @@ install_requires = schema>=0.4.0 tqdm>=4.0.0 urllib3>=1.26.0 + importlib-metadata; python_version <= 3.7 python_requires = >=3.7 include_package_data = True zip_safe = False