From bb64ee5fe034e8beff07419ac9acfe937a259bbd Mon Sep 17 00:00:00 2001 From: Zhen-Qi Liu Date: Fri, 24 Nov 2023 21:50:42 -0500 Subject: [PATCH 1/3] [FIX] Fix deprecation --- netneurotools/datasets/utils.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/netneurotools/datasets/utils.py b/netneurotools/datasets/utils.py index 34cea9a..fc7d088 100644 --- a/netneurotools/datasets/utils.py +++ b/netneurotools/datasets/utils.py @@ -3,7 +3,12 @@ import json import os -from pkg_resources import resource_filename +try: + import importlib.resources + _importlib_avail = True +except ImportError: + from pkg_resources import resource_filename + _importlib_avail = False def _osfify_urls(data): @@ -36,8 +41,12 @@ def _osfify_urls(data): return data +if _importlib_avail: + osf = importlib.resources.files("netneurotools") / "data/osf.json" +else: + osf = resource_filename('netneurotools', 'data/osf.json') -with open(resource_filename('netneurotools', 'data/osf.json')) as src: +with open(osf) as src: OSF_RESOURCES = _osfify_urls(json.load(src)) From bd9197f699315150196f2381bd0ef05197650ad5 Mon Sep 17 00:00:00 2001 From: Zhen-Qi Liu Date: Thu, 30 Nov 2023 19:40:11 -0500 Subject: [PATCH 2/3] [FIX] Fix deprecation --- netneurotools/datasets/utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/netneurotools/datasets/utils.py b/netneurotools/datasets/utils.py index fc7d088..6b645f9 100644 --- a/netneurotools/datasets/utils.py +++ b/netneurotools/datasets/utils.py @@ -3,10 +3,11 @@ import json import os -try: - import importlib.resources +import importlib.resources + +if getattr(importlib.resources, 'files', None) is not None: _importlib_avail = True -except ImportError: +else: from pkg_resources import resource_filename _importlib_avail = False From b5d52d1b7e3ca530f61eec922fdd4f2c06b6360f Mon Sep 17 00:00:00 2001 From: Zhen-Qi Liu Date: Thu, 30 Nov 2023 19:44:31 -0500 Subject: [PATCH 3/3] [FIX] Style --- netneurotools/datasets/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/netneurotools/datasets/utils.py b/netneurotools/datasets/utils.py index 6b645f9..1594d7e 100644 --- a/netneurotools/datasets/utils.py +++ b/netneurotools/datasets/utils.py @@ -42,6 +42,7 @@ def _osfify_urls(data): return data + if _importlib_avail: osf = importlib.resources.files("netneurotools") / "data/osf.json" else: