Skip to content

Commit

Permalink
[FIX] Fix deprecation (netneurolab#127)
Browse files Browse the repository at this point in the history
Replace pkg_resources with importlib.resources.files
  • Loading branch information
liuzhenqi77 authored Feb 2, 2024
1 parent 3faabb0 commit 56d97d7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
strategy:
matrix:
os: ['ubuntu-latest']
python-version: ['3.8', '3.9', '3.10']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
15 changes: 13 additions & 2 deletions netneurotools/datasets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@

import json
import os
from pkg_resources import resource_filename
import importlib.resources

if getattr(importlib.resources, 'files', None) is not None:
_importlib_avail = True
else:
from pkg_resources import resource_filename
_importlib_avail = False


def _osfify_urls(data):
Expand Down Expand Up @@ -37,7 +43,12 @@ def _osfify_urls(data):
return data


with open(resource_filename('netneurotools', 'data/osf.json')) as src:
if _importlib_avail:
osf = importlib.resources.files("netneurotools") / "data/osf.json"
else:
osf = resource_filename('netneurotools', 'data/osf.json')

with open(osf) as src:
OSF_RESOURCES = _osfify_urls(json.load(src))


Expand Down

0 comments on commit 56d97d7

Please sign in to comment.