Skip to content

Commit

Permalink
fix: migrate from pkg_resources.resource_filename to ``importlib_…
Browse files Browse the repository at this point in the history
…resources``

Resolves: #377.
  • Loading branch information
oesteban committed Jul 11, 2023
1 parent 54b05c0 commit 9800c52
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions sdcflows/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
import logging


def resource_fname(module: str, path: str):
from importlib.resources import files
return str((files(module) / path).absolute())


def front(inlist):
"""
Pop from a list or tuple, otherwise return untouched.
Expand Down
2 changes: 1 addition & 1 deletion sdcflows/workflows/apply/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
The target EPI is the distorted dataset (or a reference thereof).
"""
from pkg_resources import resource_filename as pkgrf
from nipype.pipeline import engine as pe
from nipype.interfaces import utility as niu
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
from sdcflows.utils.misc import resource_fname as pkgrf


def init_coeff2epi_wf(
Expand Down
7 changes: 4 additions & 3 deletions sdcflows/workflows/fit/pepolar.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
# https://www.nipreps.org/community/licensing/
#
"""Datasets with multiple phase encoded directions."""
from pkg_resources import resource_filename as _pkg_fname
from nipype.pipeline import engine as pe
from nipype.interfaces import utility as niu

from niworkflows.engine.workflows import LiterateWorkflow as Workflow
from sdcflows.utils.misc import resource_fname as pkgrf

INPUT_FIELDS = ("metadata", "in_data")
_PEPOLAR_DESC = """\
Expand Down Expand Up @@ -146,9 +146,10 @@ def init_topup_wf(
# The core of the implementation
# Feed the input images in LAS orientation, so FSL does not run funky reorientations
to_las = pe.Node(ReorientImageAndMetadata(target_orientation="LAS"), name="to_las")

topup = pe.Node(
TOPUP(
config=_pkg_fname("sdcflows", f"data/flirtsch/b02b0{'_quick' * sloppy}.cnf")
config=pkgrf("sdcflows", f"data/flirtsch/b02b0{'_quick' * sloppy}.cnf")
),
name="topup",
)
Expand Down Expand Up @@ -332,7 +333,7 @@ def init_3dQwarp_wf(omp_nthreads=1, debug=False, name="pepolar_estimate_wf"):

align_pes = pe.Node(
Registration(
from_file=_pkg_fname("sdcflows", "data/translation_rigid.json"),
from_file=pkgrf("sdcflows", "data/translation_rigid.json"),
output_warped_image=True,
),
name="align_pes",
Expand Down
7 changes: 3 additions & 4 deletions sdcflows/workflows/fit/syn.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@
"""
from pkg_resources import resource_filename
from nipype.pipeline import engine as pe
from nipype.interfaces import utility as niu
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
from sdcflows.utils.misc import resource_fname as pkgrf


DEFAULT_MEMORY_MIN_GB = 0.01
INPUT_FIELDS = (
Expand Down Expand Up @@ -120,7 +121,6 @@ def init_syn_sdc_wf(
Short description of the estimation method that was run.
"""
from pkg_resources import resource_filename as pkgrf
from packaging.version import parse as parseversion, Version
from nipype.interfaces.ants import ImageMath
from niworkflows.interfaces.fixes import (
Expand Down Expand Up @@ -401,7 +401,6 @@ def init_syn_preprocessing_wf(
the cost function of SyN.
"""
from pkg_resources import resource_filename as pkgrf
from niworkflows.interfaces.nibabel import (
IntensityClip,
ApplyMask,
Expand Down Expand Up @@ -496,7 +495,7 @@ def init_syn_preprocessing_wf(
)

epi2anat = pe.Node(
Registration(from_file=resource_filename("sdcflows", "data/affine.json")),
Registration(from_file=pkgrf("sdcflows", "data/affine.json")),
name="epi2anat",
n_procs=omp_nthreads,
)
Expand Down

0 comments on commit 9800c52

Please sign in to comment.