Backports Entry Points Selectable

1.3.0 · active · verified Wed Apr 15

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.

Warnings

Install

Imports

Quickstart

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}")

view raw JSON →