Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down
27 changes: 25 additions & 2 deletions src/freephil/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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={},
)

Expand Down