Skip to content

Replace pkg_resources with importlib.metadata #1672

Closed
@seisman

Description

@seisman

Description of the problem

from pkg_resources import get_distribution

In __init__.py, we use the get_distribution function from the pkg_resources module to get the version string of the PyGMT package.

It seems, pkg_resources is no longer recommended.

https://setuptools.pypa.io/en/latest/pkg_resources.html

Use of pkg_resources is discouraged in favor of importlib.resources, importlib.metadata, and their backports (resources, metadata). Please consider using those libraries instead of pkg_resources.

https://github.com/pypa/setuptools_scm#retrieving-package-version-at-runtime

Alternatively, you can use pkg_resources which is included in setuptools (but has a significant runtime cost):

I think we should use importlib.metadata instead:

from importlib.metadata import version
__version__ = version("pygmt")

The importlib.metadata module was added in Python 3.8, but PyGMT currently still supports Python 3.7. Luckily, we're going to drop Python 3.7 support on Dec. 26, 2021 as per NEP29, so it won't be a problem for us.

Metadata

Metadata

Assignees

No one assigned

    Labels

    maintenanceBoring but important stuff for the core devs

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions