From 5860444bd19565791eecdb24dd620cf60b848e11 Mon Sep 17 00:00:00 2001 From: Santiago Soler Date: Mon, 6 Jan 2025 11:21:28 -0800 Subject: [PATCH] Replace usage of `pkg_resources` for `importlib.resources` (#449) Replace the deprecated `pkg_resources` in favor of `importlib.resources` in documentation bits that instruct users how to read registry files within their packages. --- README.md | 4 ++-- doc/registry-files.rst | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0d05fbf2..eaa706ed 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/doc/registry-files.rst b/doc/registry-files.rst index 571a146e..b9d10b16 100644 --- a/doc/registry-files.rst +++ b/doc/registry-files.rst @@ -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"), @@ -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 `__ -to access the ``registry.txt``, giving it the name of our Python package. +We use `importlib.resources +`__ to access the +``registry.txt``, giving it the name of our Python package. Registry file format --------------------