From 748818d2cd4bfe2474c78f5a93b1a11fba32c561 Mon Sep 17 00:00:00 2001 From: Stanislav Kruchinin <21279249+polariton@users.noreply.github.com> Date: Sun, 24 Dec 2023 03:28:11 +0100 Subject: [PATCH 1/4] filters: use importlib_resources API to avoid deprecation warning --- resampy/filters.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/resampy/filters.py b/resampy/filters.py index 0cab898..f4d79be 100644 --- a/resampy/filters.py +++ b/resampy/filters.py @@ -46,8 +46,7 @@ ''' import numpy as np -import os -import pkg_resources +import importlib_resources import sys FILTER_FUNCTIONS = ['sinc_window'] @@ -203,10 +202,10 @@ def load_filter(filter_name): ''' if filter_name not in FILTER_CACHE: - fname = os.path.join('data', - os.path.extsep.join([filter_name, 'npz'])) + fname = importlib_resources.files(__name__) / 'data' / f'{filter_name}.npz' + with importlib_resources.as_file(fname) as f: + data = np.load(f) - data = np.load(pkg_resources.resource_filename(__name__, fname)) FILTER_CACHE[filter_name] = data['half_window'], data['precision'], data['rolloff'] return FILTER_CACHE[filter_name] From dd32a194f6039d641ed1a691960db0c711f4ec69 Mon Sep 17 00:00:00 2001 From: Stanislav Kruchinin <21279249+polariton@users.noreply.github.com> Date: Sun, 24 Dec 2023 03:28:27 +0100 Subject: [PATCH 2/4] Add importlib_resources to requirements --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index b5b28ce..34cee66 100644 --- a/setup.cfg +++ b/setup.cfg @@ -40,6 +40,7 @@ python_requires >= 3.6 install_requires = numpy>=1.17 numba>=0.53 + importlib_resources [options.package_data] resampy = data/* From 62b16407dfc42809179fb057212a3784d34e7c6e Mon Sep 17 00:00:00 2001 From: Stanislav Kruchinin <21279249+polariton@users.noreply.github.com> Date: Sun, 24 Dec 2023 03:28:50 +0100 Subject: [PATCH 3/4] Add importlib_resources to GitHub workflows --- .github/workflows/ci-minimal.yml | 2 +- .github/workflows/ci.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-minimal.yml b/.github/workflows/ci-minimal.yml index 7bd8b1d..ad7d823 100644 --- a/.github/workflows/ci-minimal.yml +++ b/.github/workflows/ci-minimal.yml @@ -34,7 +34,7 @@ jobs: shell: bash -l {0} run: | mamba install typing_extensions!=4.2 pytest - mamba install pip numpy==1.17 scipy==1.0 numba==0.53 + mamba install pip numpy==1.17 scipy==1.0 numba==0.53 importlib_resources - name: Install shell: bash -l {0} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c35dcd7..9b26ef1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,7 +39,7 @@ jobs: shell: bash -l {0} run: | mamba install typing_extensions!=4.2 - mamba install pip numpy scipy numba pytest pytest-cov pytest-doctestplus + mamba install pip numpy scipy numba pytest pytest-cov pytest-doctestplus importlib_resources - name: Install shell: bash -l {0} run: | From 0eddd89a43a2a704e241ada17826d60ea4439705 Mon Sep 17 00:00:00 2001 From: Brian McFee Date: Tue, 5 Mar 2024 14:01:08 -0500 Subject: [PATCH 4/4] Update resampy/filters.py fixing package resource locations --- resampy/filters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resampy/filters.py b/resampy/filters.py index f4d79be..5eb4792 100644 --- a/resampy/filters.py +++ b/resampy/filters.py @@ -202,7 +202,7 @@ def load_filter(filter_name): ''' if filter_name not in FILTER_CACHE: - fname = importlib_resources.files(__name__) / 'data' / f'{filter_name}.npz' + fname = importlib_resources.files("resampy") / 'data' / f'{filter_name}.npz' with importlib_resources.as_file(fname) as f: data = np.load(f)