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

Replace usage of pkg_resources for importlib.resources #449

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ For **package developers** including sample data in their projects:
"""
Module mypackage/datasets.py
"""
import pkg_resources
from importlib import resources
import pandas
import pooch

Expand Down Expand Up @@ -154,7 +154,7 @@ GOODBOY = pooch.create(
# manage large numbers of data files. The registry file should be packaged
# and distributed with your software.
GOODBOY.load_registry(
pkg_resources.resource_stream("mypackage", "registry.txt")
resources.open_text("mypackage", "registry.txt")
)

# Define functions that your users can call to get back the data in memory
Expand Down
9 changes: 5 additions & 4 deletions doc/registry-files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ hashes in a file and use :meth:`pooch.Pooch.load_registry` to read them.
.. code:: python

import os
import pkg_resources
from importlib import resources

POOCH = pooch.create(
path=pooch.os_cache("plumbus"),
Expand All @@ -24,14 +24,15 @@ hashes in a file and use :meth:`pooch.Pooch.load_registry` to read them.
registry=None,
)
# Get registry file from package_data
registry_file = pkg_resources.resource_stream("plumbus", "registry.txt")
registry_file = resources.open_text("plumbus", "registry.txt")
# Load this registry file
POOCH.load_registry(registry_file)

In this case, the ``registry.txt`` file is in the ``plumbus/`` package
directory and should be shipped with the package (see below for instructions).
We use `pkg_resources <https://setuptools.readthedocs.io/en/latest/pkg_resources.html#basic-resource-access>`__
to access the ``registry.txt``, giving it the name of our Python package.
We use `importlib.resources
<https://docs.python.org/3/library/importlib.resources.html>`__ to access the
``registry.txt``, giving it the name of our Python package.

Registry file format
--------------------
Expand Down
Loading