Skip to content

Commit d6bb667

Browse files
committed
MNT: Fully drop pkg_resources
1 parent 1eca711 commit d6bb667

File tree

5 files changed

+15
-19
lines changed

5 files changed

+15
-19
lines changed

fmriprep/cli/run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def main():
202202
_copy_any(dseg_tsv, str(config.execution.fmriprep_dir / "desc-aparcaseg_dseg.tsv"))
203203
errno = 0
204204
finally:
205-
from pkg_resources import resource_filename as pkgrf
205+
from .. import data
206206

207207
# Code Carbon
208208
if config.execution.track_carbon:
@@ -218,7 +218,7 @@ def main():
218218
config.execution.participant_label,
219219
config.execution.fmriprep_dir,
220220
config.execution.run_uuid,
221-
config=pkgrf("fmriprep", "data/reports-spec.yml"),
221+
config=data.load("reports-spec.yml"),
222222
packagename="fmriprep",
223223
)
224224
write_derivative_description(config.execution.bids_dir, config.execution.fmriprep_dir)

fmriprep/cli/workflow.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@ def build_workflow(config_file, retval):
3838

3939
from niworkflows.utils.bids import collect_participants
4040
from niworkflows.utils.misc import check_valid_fs_license
41-
from pkg_resources import resource_filename as pkgrf
4241

4342
from fmriprep.reports.core import generate_reports
4443
from fmriprep.utils.bids import check_pipeline_version
4544

46-
from .. import config
45+
from .. import config, data
4746
from ..utils.misc import check_deps
4847
from ..workflows.base import init_fmriprep_wf
4948

@@ -57,7 +56,7 @@ def build_workflow(config_file, retval):
5756
retval["workflow"] = None
5857

5958
banner = [f"Running fMRIPrep version {version}"]
60-
notice_path = Path(pkgrf("fmriprep", "data/NOTICE"))
59+
notice_path = data.load.readable("NOTICE")
6160
if notice_path.exists():
6261
banner[0] += "\n"
6362
banner += [f"License NOTICE {'#' * 50}"]
@@ -91,7 +90,7 @@ def build_workflow(config_file, retval):
9190
config.execution.participant_label,
9291
config.execution.fmriprep_dir,
9392
config.execution.run_uuid,
94-
config=pkgrf("fmriprep", "data/reports-spec.yml"),
93+
config=data.load("reports-spec.yml"),
9594
packagename="fmriprep",
9695
)
9796
return retval
@@ -183,9 +182,9 @@ def build_boilerplate(config_file, workflow):
183182
from pathlib import Path
184183
from subprocess import CalledProcessError, TimeoutExpired, check_call
185184

186-
from pkg_resources import resource_filename as pkgrf
185+
from .. import data
187186

188-
bib_text = Path(pkgrf("fmriprep", "data/boilerplate.bib")).read_text()
187+
bib_text = data.load.readable("boilerplate.bib").read_text()
189188
citation_files["bib"].write_text(
190189
bib_text.replace("fMRIPrep <version>", f"fMRIPrep {config.environment.version}")
191190
)

fmriprep/tests/test_config.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@
2727

2828
import pytest
2929
from niworkflows.utils.spaces import format_reference
30-
from pkg_resources import resource_filename as pkgrf
3130
from toml import loads
3231

33-
from .. import config
32+
from .. import config, data
3433

3534

3635
def _reset_config():
@@ -59,8 +58,7 @@ def test_reset_config():
5958

6059
def test_config_spaces():
6160
"""Check that all necessary spaces are recorded in the config."""
62-
filename = Path(pkgrf('fmriprep', 'data/tests/config.toml'))
63-
settings = loads(filename.read_text())
61+
settings = loads(data.load.readable("tests/config.toml").read_text())
6462
for sectionname, configs in settings.items():
6563
if sectionname != 'environment':
6664
section = getattr(config, sectionname)

fmriprep/workflows/bold/registration.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,11 @@
3333
import os.path as op
3434
import typing as ty
3535

36-
import pkg_resources as pkgr
3736
from nipype.interfaces import c3, fsl
3837
from nipype.interfaces import utility as niu
3938
from nipype.pipeline import engine as pe
4039

41-
from ... import config
40+
from ... import config, data
4241
from ...interfaces import DerivativesDataSink
4342

4443
DEFAULT_MEMORY_MIN_GB = config.DEFAULT_MEMORY_MIN_GB
@@ -588,7 +587,7 @@ def init_fsl_bbr_wf(
588587
else:
589588
# Should mostly be hit while building docs
590589
LOGGER.warning("FSLDIR unset - using packaged BBR schedule")
591-
flt_bbr.inputs.schedule = pkgr.resource_filename('fmriprep', 'data/flirtsch/bbr.sch')
590+
flt_bbr.inputs.schedule = data.load('flirtsch/bbr.sch')
592591
# fmt:off
593592
workflow.connect([
594593
(inputnode, wm_mask, [('t1w_dseg', 'in_seg')]),

fmriprep/workflows/tests/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727
from pathlib import Path
2828
from tempfile import mkdtemp
2929

30-
from pkg_resources import resource_filename as pkgrf
3130
from toml import loads
3231

32+
from ... import data
33+
3334

3435
@contextmanager
3536
def mock_config():
@@ -40,8 +41,7 @@ def mock_config():
4041
if not _old_fs:
4142
os.environ['FREESURFER_HOME'] = mkdtemp()
4243

43-
filename = Path(pkgrf('fmriprep', 'data/tests/config.toml'))
44-
settings = loads(filename.read_text())
44+
settings = loads(data.load.readable('tests/config.toml').read_text())
4545
for sectionname, configs in settings.items():
4646
if sectionname != 'environment':
4747
section = getattr(config, sectionname)
@@ -52,7 +52,7 @@ def mock_config():
5252
config.init_spaces()
5353

5454
config.execution.work_dir = Path(mkdtemp())
55-
config.execution.bids_dir = Path(pkgrf('fmriprep', 'data/tests/ds000005')).absolute()
55+
config.execution.bids_dir = data.load('tests/ds000005').absolute()
5656
config.execution.fmriprep_dir = Path(mkdtemp())
5757
config.execution.init()
5858

0 commit comments

Comments
 (0)