Skip to content

Clarify pkg_resources vs importlib_metadata #37

Open
@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

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

    Issue actions