File tree Expand file tree Collapse file tree 3 files changed +22
-4
lines changed Expand file tree Collapse file tree 3 files changed +22
-4
lines changed Original file line number Diff line number Diff line change
1
+ import sys
2
+ from atexit import register
3
+ from contextlib import ExitStack
4
+ from functools import lru_cache
5
+
6
+
7
+ if sys .version_info < (3 , 9 ):
8
+ from importlib_resources import as_file , files
9
+ else :
10
+ from importlib .resources import as_file , files
11
+
12
+ _stack = ExitStack ()
13
+ register (_stack .close )
14
+
15
+
16
+ @lru_cache
17
+ def load_resource (anchor , * parts ) -> str :
18
+ return str (_stack .enter_context (as_file (files (anchor ).joinpath (* parts ))))
Original file line number Diff line number Diff line change 1
1
import pytest
2
2
import shutil
3
- from pkg_resources import resource_filename
3
+ from . import load_resource
4
4
5
5
from nipype .interfaces import fsl
6
6
import nipype .interfaces .utility as nutil
12
12
def test_isolation (tmp_path ):
13
13
in_file = tmp_path / "orig/tpms_msk.nii.gz"
14
14
in_file .parent .mkdir ()
15
- shutil .copyfile (resource_filename ("nipype" , "testing/data/tpms_msk.nii.gz" ), in_file )
15
+ shutil .copyfile (load_resource ("nipype" , "testing/data/tpms_msk.nii.gz" ), in_file )
16
16
17
17
out_dir = tmp_path / "output"
18
18
out_dir .mkdir ()
Original file line number Diff line number Diff line change @@ -27,11 +27,11 @@ class Nipype1Task(pydra.engine.task.TaskBase):
27
27
in Pydra Task outputs.
28
28
29
29
>>> import pytest
30
- >>> from pkg_resources import resource_filename
30
+ >>> from pydra.tasks.nipype1.tests import load_resource
31
31
>>> from nipype.interfaces import fsl
32
32
>>> if fsl.Info.version() is None:
33
33
... pytest.skip()
34
- >>> img = resource_filename ('nipype', 'testing/data/tpms_msk.nii.gz')
34
+ >>> img = load_resource ('nipype', 'testing/data/tpms_msk.nii.gz')
35
35
36
36
>>> from pydra.tasks.nipype1.utils import Nipype1Task
37
37
>>> thresh = Nipype1Task(fsl.Threshold())
You can’t perform that action at this time.
0 commit comments