From 9b6be5a6fd0c45d392c04c86a446e3b8069d9985 Mon Sep 17 00:00:00 2001 From: Jan Stransky Date: Mon, 16 Feb 2026 11:38:30 +0100 Subject: [PATCH] Removal of dependency on `pkg_resources`. --- setup.cfg | 11 ++++++----- src/freephil/common.py | 27 +++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/setup.cfg b/setup.cfg index fc7d6bfd8..b5ad436c6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -11,10 +11,11 @@ classifiers = License :: OSI Approved :: BSD License Natural Language :: English Programming Language :: Python :: 3 - Programming Language :: Python :: 3.6 - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 + Programming Language :: Python :: 3.13 + Programming Language :: Python :: 3.14 keywords = dials project-urls = Bug-Tracker = https://github.com/Anthchirp/freephil/issues @@ -28,7 +29,7 @@ install_requires = package_dir= =src packages = find: -python_requires = >=3.6 +python_requires = >=3.10 zip_safe = False [options.packages.find] diff --git a/src/freephil/common.py b/src/freephil/common.py index 98bbf9d70..fdf54b989 100644 --- a/src/freephil/common.py +++ b/src/freephil/common.py @@ -12,7 +12,30 @@ import weakref from itertools import count -import pkg_resources +# Python >= 3.10: use stdlib importlib.metadata for entry point discovery. +from importlib import metadata as _importlib_metadata # type: ignore + + +def _discover_freephil_converters(): + """Return a list of third-party converter classes via entry points. + + Since Python 3.10 is required, this uses importlib.metadata.entry_points + with the group argument. Broken entry points are ignored. + """ + group_name = "freephil.converter" + try: + candidates = _importlib_metadata.entry_points(group=group_name) + loaded = [] + for ep in candidates or []: + try: + loaded.append(ep.load()) + except Exception: + # Ignore broken entry points to keep imports resilient + continue + return loaded + except Exception: + # Any unexpected issue: do not break import, just return no plugins + return [] import freephil @@ -123,7 +146,7 @@ def extended_converter_registry(additional_converters, base_registry=None): floats_converters, choice_converters, ] - + [e.load() for e in pkg_resources.iter_entry_points("freephil.converter")], + + _discover_freephil_converters(), base_registry={}, )