Skip to content

Commit

Permalink
MNT: Fully drop pkg_resources
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Nov 21, 2023
1 parent 1eca711 commit d6bb667
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
4 changes: 2 additions & 2 deletions fmriprep/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def main():
_copy_any(dseg_tsv, str(config.execution.fmriprep_dir / "desc-aparcaseg_dseg.tsv"))
errno = 0
finally:
from pkg_resources import resource_filename as pkgrf
from .. import data

# Code Carbon
if config.execution.track_carbon:
Expand All @@ -218,7 +218,7 @@ def main():
config.execution.participant_label,
config.execution.fmriprep_dir,
config.execution.run_uuid,
config=pkgrf("fmriprep", "data/reports-spec.yml"),
config=data.load("reports-spec.yml"),
packagename="fmriprep",
)
write_derivative_description(config.execution.bids_dir, config.execution.fmriprep_dir)
Expand Down
11 changes: 5 additions & 6 deletions fmriprep/cli/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ def build_workflow(config_file, retval):

from niworkflows.utils.bids import collect_participants
from niworkflows.utils.misc import check_valid_fs_license
from pkg_resources import resource_filename as pkgrf

from fmriprep.reports.core import generate_reports
from fmriprep.utils.bids import check_pipeline_version

from .. import config
from .. import config, data
from ..utils.misc import check_deps
from ..workflows.base import init_fmriprep_wf

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

banner = [f"Running fMRIPrep version {version}"]
notice_path = Path(pkgrf("fmriprep", "data/NOTICE"))
notice_path = data.load.readable("NOTICE")
if notice_path.exists():
banner[0] += "\n"
banner += [f"License NOTICE {'#' * 50}"]
Expand Down Expand Up @@ -91,7 +90,7 @@ def build_workflow(config_file, retval):
config.execution.participant_label,
config.execution.fmriprep_dir,
config.execution.run_uuid,
config=pkgrf("fmriprep", "data/reports-spec.yml"),
config=data.load("reports-spec.yml"),
packagename="fmriprep",
)
return retval
Expand Down Expand Up @@ -183,9 +182,9 @@ def build_boilerplate(config_file, workflow):
from pathlib import Path
from subprocess import CalledProcessError, TimeoutExpired, check_call

from pkg_resources import resource_filename as pkgrf
from .. import data

bib_text = Path(pkgrf("fmriprep", "data/boilerplate.bib")).read_text()
bib_text = data.load.readable("boilerplate.bib").read_text()
citation_files["bib"].write_text(
bib_text.replace("fMRIPrep <version>", f"fMRIPrep {config.environment.version}")
)
Expand Down
6 changes: 2 additions & 4 deletions fmriprep/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@

import pytest
from niworkflows.utils.spaces import format_reference
from pkg_resources import resource_filename as pkgrf
from toml import loads

from .. import config
from .. import config, data


def _reset_config():
Expand Down Expand Up @@ -59,8 +58,7 @@ def test_reset_config():

def test_config_spaces():
"""Check that all necessary spaces are recorded in the config."""
filename = Path(pkgrf('fmriprep', 'data/tests/config.toml'))
settings = loads(filename.read_text())
settings = loads(data.load.readable("tests/config.toml").read_text())
for sectionname, configs in settings.items():
if sectionname != 'environment':
section = getattr(config, sectionname)
Expand Down
5 changes: 2 additions & 3 deletions fmriprep/workflows/bold/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@
import os.path as op
import typing as ty

import pkg_resources as pkgr
from nipype.interfaces import c3, fsl
from nipype.interfaces import utility as niu
from nipype.pipeline import engine as pe

from ... import config
from ... import config, data
from ...interfaces import DerivativesDataSink

DEFAULT_MEMORY_MIN_GB = config.DEFAULT_MEMORY_MIN_GB
Expand Down Expand Up @@ -588,7 +587,7 @@ def init_fsl_bbr_wf(
else:
# Should mostly be hit while building docs
LOGGER.warning("FSLDIR unset - using packaged BBR schedule")
flt_bbr.inputs.schedule = pkgr.resource_filename('fmriprep', 'data/flirtsch/bbr.sch')
flt_bbr.inputs.schedule = data.load('flirtsch/bbr.sch')
# fmt:off
workflow.connect([
(inputnode, wm_mask, [('t1w_dseg', 'in_seg')]),
Expand Down
8 changes: 4 additions & 4 deletions fmriprep/workflows/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
from pathlib import Path
from tempfile import mkdtemp

from pkg_resources import resource_filename as pkgrf
from toml import loads

from ... import data


@contextmanager
def mock_config():
Expand All @@ -40,8 +41,7 @@ def mock_config():
if not _old_fs:
os.environ['FREESURFER_HOME'] = mkdtemp()

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

config.execution.work_dir = Path(mkdtemp())
config.execution.bids_dir = Path(pkgrf('fmriprep', 'data/tests/ds000005')).absolute()
config.execution.bids_dir = data.load('tests/ds000005').absolute()
config.execution.fmriprep_dir = Path(mkdtemp())
config.execution.init()

Expand Down

0 comments on commit d6bb667

Please sign in to comment.