Skip to content

Commit 83da101

Browse files
committed
sty: Manual fixes for remaining checks
1 parent 0b9750e commit 83da101

File tree

28 files changed

+79
-65
lines changed

28 files changed

+79
-65
lines changed

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
os.close(tffiledesc)
3737
templateflow.api.get = mock.MagicMock(return_value=tffilename)
3838

39-
from niworkflows import __copyright__, __packagename__, __version__
39+
from niworkflows import __copyright__, __packagename__, __version__ # noqa:E402
4040

4141
sys.path.append(os.path.abspath('sphinxext'))
4242

niworkflows/__about__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@
2727
as well as for open-source software distribution.
2828
"""
2929

30-
from datetime import datetime
31-
3230
__packagename__ = 'niworkflows'
33-
__copyright__ = f'Copyright {datetime.now().year}, The NiPreps Developers'
31+
__copyright__ = 'Copyright, The NiPreps Developers'
3432
__credits__ = [
3533
'Oscar Esteban',
3634
'Ross Blair',

niworkflows/anat/ants.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"""Nipype translation of ANTs' workflows."""
2424

2525
# general purpose
26-
from collections import OrderedDict
2726
from multiprocessing import cpu_count
2827
from warnings import warn
2928

@@ -55,10 +54,11 @@
5554
from ..utils.misc import get_template_specs
5655

5756
ATROPOS_MODELS = {
58-
'T1w': OrderedDict([('nclasses', 3), ('csf', 1), ('gm', 2), ('wm', 3)]),
59-
'T2w': OrderedDict([('nclasses', 3), ('csf', 3), ('gm', 2), ('wm', 1)]),
60-
'FLAIR': OrderedDict([('nclasses', 3), ('csf', 1), ('gm', 3), ('wm', 2)]),
57+
'T1w': {'nclasses': 3, 'csf': 1, 'gm': 2, 'wm': 3},
58+
'T2w': {'nclasses': 3, 'csf': 3, 'gm': 2, 'wm': 1},
59+
'FLAIR': {'nclasses': 3, 'csf': 1, 'gm': 3, 'wm': 2},
6160
}
61+
T1W_MODEL = tuple(ATROPOS_MODELS['T1w'].values())
6262

6363

6464
def init_brain_extraction_wf(
@@ -293,7 +293,8 @@ def init_brain_extraction_wf(
293293
except ValueError:
294294
warn(
295295
"antsAI's option --search-grid was added in ANTS 2.3.0 "
296-
f'({init_aff.interface.version} found.)'
296+
f'({init_aff.interface.version} found.)',
297+
stacklevel=1,
297298
)
298299

299300
# Set up spatial normalization
@@ -355,6 +356,7 @@ def init_brain_extraction_wf(
355356
"N4BiasFieldCorrection's --rescale-intensities option was added in ANTS 2.1.0 "
356357
f'({inu_n4_final.interface.version} found.) Please consider upgrading.',
357358
UserWarning,
359+
stacklevel=1,
358360
)
359361

360362
# Apply mask
@@ -501,7 +503,7 @@ def init_atropos_wf(
501503
omp_nthreads=None,
502504
mem_gb=3.0,
503505
padding=10,
504-
in_segmentation_model=tuple(ATROPOS_MODELS['T1w'].values()),
506+
in_segmentation_model=T1W_MODEL,
505507
bspline_fitting_distance=200,
506508
wm_prior=False,
507509
):
@@ -758,6 +760,7 @@ def init_atropos_wf(
758760
"N4BiasFieldCorrection's --rescale-intensities option was added in ANTS 2.1.0 "
759761
f'({inu_n4_final.interface.version} found.) Please consider upgrading.',
760762
UserWarning,
763+
stacklevel=1,
761764
)
762765

763766
# Apply mask
@@ -987,6 +990,7 @@ def init_n4_only_wf(
987990
"N4BiasFieldCorrection's --rescale-intensities option was added in ANTS 2.1.0 "
988991
f'({inu_n4_final.interface.version} found.) Please consider upgrading.',
989992
UserWarning,
993+
stacklevel=1,
990994
)
991995

992996
# fmt: off

niworkflows/anat/freesurfer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@
3737
)
3838
from ..interfaces.surf import NormalizeSurf
3939

40+
SUBJECTS_DIR = getenv('SUBJECTS_DIR')
4041

41-
def init_gifti_surface_wf(name='gifti_surface_wf', subjects_dir=getenv('SUBJECTS_DIR', None)):
42+
43+
def init_gifti_surface_wf(name='gifti_surface_wf', subjects_dir=SUBJECTS_DIR):
4244
"""
4345
Build a Nipype workflow to prepare GIFTI surfaces from FreeSurfer.
4446

niworkflows/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def find_resource_or_skip(resource):
5151

5252

5353
@pytest.fixture(autouse=True)
54-
def add_np(doctest_namespace):
54+
def _add_np(doctest_namespace):
5555
from .testing import data_dir, data_dir_canary
5656
from .utils.bids import collect_data
5757

niworkflows/engine/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python
21
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
32
# vi: set ft=python sts=4 ts=4 sw=4 et:
43
"""

niworkflows/func/tests/test_util.py

100755100644
File mode changed.

niworkflows/interfaces/bids.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
if sys.version_info < (3, 10): # PY39
7070
builtin_zip = zip
7171

72-
def zip(*args, strict=False):
72+
def zip(*args, strict=False): # noqa: A001
7373
if strict and any(len(args[0]) != len(arg) for arg in args):
7474
raise ValueError('strict_zip() requires all arguments to have the same length')
7575
return builtin_zip(*args)
@@ -676,7 +676,7 @@ def _run_interface(self, runtime):
676676
if data_dtype == 'source': # match source dtype
677677
try:
678678
data_dtype = nb.load(self.inputs.source_file[0]).get_data_dtype()
679-
except Exception:
679+
except Exception: # noqa: BLE001
680680
LOGGER.warning(
681681
f'Could not get data type of file {self.inputs.source_file[0]}'
682682
)
@@ -1193,7 +1193,7 @@ def _run_interface(self, runtime):
11931193
if data_dtype == 'source': # match source dtype
11941194
try:
11951195
data_dtype = nb.load(self.inputs.source_file[0]).get_data_dtype()
1196-
except Exception:
1196+
except Exception: # noqa: BLE001
11971197
LOGGER.warning(
11981198
f'Could not get data type of file {self.inputs.source_file[0]}'
11991199
)

niworkflows/interfaces/cifti.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
#
2323
"""Handling connectivity: combines FreeSurfer surfaces with subcortical volumes."""
2424

25+
from __future__ import annotations
26+
2527
import json
26-
import typing
2728
import warnings
2829
from pathlib import Path
2930

@@ -252,7 +253,7 @@ def _create_cifti_image(
252253
bold_surfs: tuple[str, str],
253254
surface_labels: tuple[str, str],
254255
tr: float,
255-
metadata: typing.Optional[dict] = None,
256+
metadata: dict | None = None,
256257
):
257258
"""
258259
Generate CIFTI image in target space.
@@ -280,7 +281,7 @@ def _create_cifti_image(
280281
bold_img = nb.load(bold_file)
281282
label_img = nb.load(volume_label)
282283
if label_img.shape != bold_img.shape[:3]:
283-
warnings.warn('Resampling bold volume to match label dimensions')
284+
warnings.warn('Resampling bold volume to match label dimensions', stacklevel=1)
284285
bold_img = resample_to_img(bold_img, label_img)
285286

286287
# ensure images match HCP orientation (LAS)

niworkflows/interfaces/freesurfer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ def mri_info(fname, argument):
566566
import numpy as np
567567

568568
cmd_info = f'mri_info --{argument} {fname}'
569-
proc = sp.Popen(cmd_info, stdout=sp.PIPE, shell=True)
569+
proc = sp.Popen(cmd_info, stdout=sp.PIPE, shell=True) # noqa: S602
570570
data = bytearray(proc.stdout.read())
571571
mstring = np.fromstring(data.decode('utf-8'), sep='\n')
572572
result = np.reshape(mstring, (4, -1))

0 commit comments

Comments
 (0)