Registry / devops / backports-entry-points-selectable

backports-entry-points-selectable

JSON →
library1.3.0pypypi✓ verified 85d ago

backports.entry_points_selectable is a compatibility shim that provides selectable entry points, specifically designed to ease the adoption of `importlib.metadata` 3.6+. It enables 'selectable' entry points (passing keyword arguments to `entry_points()` or invoking `.select()` on the result) even on older Python versions (prior to 3.10) or when `importlib_metadata` is older than 3.6. The current version is 1.3.0, and it receives updates as needed to maintain compatibility.

pip install backports-entry-points-selectable
INSTALL
IMPORT
SIG · BACKPORTS-ENTRY-PO
B
backports-entry-points-selectable
devopspythonv1.3.0
Install
1.5s avg
Import
91ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.3.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.097s · 17.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.085s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

entry_points
from backports.entry_points_selectable import entry_points
from importlib.metadata import entry_points
On Python versions older than 3.10 (or `importlib_metadata` < 3.6), importing `entry_points` directly from `importlib.metadata` will not provide the 'selectable' interface (i.e., passing keyword arguments like `group` or `name` or using the `.select()` method on the result). This shim explicitly provides that compatibility.

This quickstart demonstrates how to import and use the `entry_points` function provided by `backports.entry_points_selectable`. It shows how to retrieve entry points by group and how to find a specific entry point by both group and name, utilizing the 'selectable' interface. This is the primary functionality backported by the library.

from backports.entry_points_selectable import entry_points # Example: Find all console scripts console_scripts = entry_points(group='console_scripts') print(f"Found {len(console_scripts)} console scripts.") for ep in console_scripts: print(f" - {ep.name}: {ep.value}") # Example: Find a specific entry point by name and group try: (mypy_ep,) = entry_points(group='console_scripts', name='mypy') print(f"\nFound specific entry point: {mypy_ep.name} -> {mypy_ep.value}") # Load and execute the entry point (caution: this runs code) # mypy_main = mypy_ep.load() # mypy_main([]) except ValueError: print("\n'mypy' console script not found or multiple found.") # Fallback using .select() if no arguments were passed initially (less common with this backport) all_entry_points = entry_points() python_eps = all_entry_points.select(group='pytest11') print(f"\nFound {len(python_eps)} pytest plugins.") for ep in python_eps: print(f" - {ep.name}: {ep.value}")
Debug
Known issues
gotchaThis backport is primarily for Python versions older than 3.10 or environments using `importlib_metadata` older than 3.6. For Python 3.10+ (which includes the selectable entry point interface in `importlib.metadata` directly), this library may be unnecessary and can be removed.
fix
On Python 3.10 and newer, remove `backports-entry-points-selectable` from your dependencies and import `entry_points` directly from `importlib.metadata`. For example, replace `from backports.entry_points_selectable import entry_points` with `from importlib.metadata import entry_points`.
affects: <3.10
deprecatedThe dictionary-like interface for `entry_points()` (e.g., `entry_points()['group_name']`) is deprecated in upstream `importlib.metadata` (Python 3.10+ and `importlib_metadata` 3.9+). While `backports.entry_points_selectable` aims to provide compatibility, relying on the dict interface is discouraged.
fix
Always use the 'selectable' interface by passing keyword arguments directly to `entry_points()` (e.g., `entry_points(group='console_scripts')`) or by calling the `.select()` method on the returned `EntryPoints` object for explicit filtering.
affects: All versions when used with older `importlib_metadata` or Python < 3.10 (where the dict interface might still be implicitly supported but is considered deprecated upstream).
gotchaThis library only shims the `entry_points` function. If your project uses other APIs from `importlib.metadata` (e.g., `metadata`, `version`, `files`, `requires`), you might still need to explicitly depend on the `importlib_metadata` PyPI package if targeting Python versions older than 3.8.
fix
If supporting Python < 3.8 and using other `importlib.metadata` APIs, ensure `importlib_metadata` is also a dependency in your project. For example: `install_requires = ['importlib_metadata; python_version < "3.8"', 'backports-entry-points-selectable']`.
affects: All versions, particularly when supporting Python < 3.8.
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'backports.entry_points_selectable'
This error occurs when the `backports.entry_points_selectable` package is not installed in the Python environment or is not accessible in the `PYTHONPATH`.
fix
Install the package using pip: `pip install backports.entry-points-selectable`
TypeError: entry_points() got an unexpected keyword argument 'group'
This error arises when attempting to use the 'selectable' entry points feature (passing keyword arguments like 'group' to `entry_points()`) on a Python version older than 3.10 or with an `importlib_metadata` version older than 3.6, without correctly importing or utilizing the `backports.entry_points_selectable` shim.
fix
Ensure `backports.entry_points_selectable` is installed and then import `entry_points` from it: `from backports.entry_points_selectable import entry_points`.
DeprecationWarning: SelectableGroups dict interface is deprecated. Use select.
This warning indicates that code is still accessing `entry_points` as a dictionary (e.g., `entry_points()['group_name']`) when a newer version of `importlib.metadata` (or `importlib_metadata`) or `backports.entry_points_selectable` is in use, which provides a more modern `EntryPoints` object with a `.select()` method or direct keyword arguments.
fix
Update your code to use the `select` method or keyword arguments for `entry_points`, for example: `entry_points().select(group='group_name')` or `entry_points(group='group_name').
Upgrade
Version history
1.3.0latest on PyPI · released Nov 27, 2023
Audit
Dependencies
importlib_metadataoptionalProvides foundational `importlib.metadata` APIs on Python versions older than 3.8, or older versions of `importlib.metadata` in 3.8/3.9 that lack selectable entry points. This shim relies on it but also wraps its `entry_points` function for compatibility. While this backport might conditionally install it, projects using other `importlib.metadata` functions should explicitly require `importlib_metadata` for full API coverage on older Pythons.
Agent activity
11 hits · last 30 days
node
10
Resources
backports-entry-points-selectable — pip install backports-entry-points-selectable · libregistry