Skip to content

Clarify pkg_resources vs importlib_metadata #37

@juftin

Description

@juftin

pkg_resources is deprecated, it would be nice have the docs clarify how to use click-plugins with importlib_metadata / importlib.metadata instead.

ATTENTION

Use of pkg_resources is deprecated in favor of importlib.resources, importlib.metadata and their backports (importlib_resources, importlib_metadata). Some useful APIs are also provided by packaging (e.g. requirements and version parsing). Users should refrain from new usage of pkg_resources and should work to port to importlib-based solutions.

I've replaced this:

from pkg_resources import iter_entry_points

import click
from click_plugins import with_plugins


@with_plugins(iter_entry_points('core_package.cli_plugins'))
@click.group()
def cli():
    """Commandline interface for yourpackage."""

with this:

import click
from click_plugins import with_plugins
from importlib_metadata import entry_points


@with_plugins(entry_points(group='core_package.cli_plugins'))
@click.group()
def cli():
    """Commandline interface for yourpackage."""

The above code is compatible with importlib-metadata>=3.6

Activity

added a commit that references this issue on Jun 9, 2025
bd0f4ff
geowurster

geowurster commented on Jun 9, 2025

@geowurster
Member

I have switched to importlib in #40, but this PR comes with some major caveats.

added 2 commits that reference this issue on Jun 25, 2025
45a1220
b972c07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @geowurster@juftin

        Issue actions

          Clarify `pkg_resources` vs `importlib_metadata` · Issue #37 · click-contrib/click-plugins