Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify pkg_resources vs importlib_metadata #37

Open
juftin opened this issue Jan 25, 2024 · 0 comments
Open

Clarify pkg_resources vs importlib_metadata #37

juftin opened this issue Jan 25, 2024 · 0 comments

Comments

@juftin
Copy link

juftin commented Jan 25, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant