Skip to content

Commit b55d82d

Browse files
authored
Merge pull request #930 from DimitriPapadopoulos/ruff
STY: Enable more ruff rules
2 parents 3927e5b + a7249c3 commit b55d82d

File tree

14 files changed

+53
-38
lines changed

14 files changed

+53
-38
lines changed

niworkflows/engine/tests/test_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from ..plugin import MultiProcPlugin
99

1010

11-
def add(x, y): # noqa: FURB118 # the Function interface does not support builtin functions
11+
def add(x, y): # the Function interface does not support builtin functions
1212
return x + y
1313

1414

niworkflows/func/tests/test_util.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,7 @@ def test_masking(input_fname, expected_fname):
156156

157157
res = wf.run(plugin='MultiProc')
158158

159-
combine_masks = [node for node in res.nodes if node.name.endswith('combine_masks')][
160-
0
161-
]
159+
combine_masks = next(node for node in res.nodes if node.name.endswith('combine_masks'))
162160
overlap = symmetric_overlap(expected_fname, combine_masks.result.outputs.out_file)
163161

164162
mask_dir = reports_dir / 'fmriprep_bold_mask' / dsname

niworkflows/interfaces/bids.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ def _run_interface(self, runtime):
673673
data_dtype = nb.load(self.inputs.source_file[0]).get_data_dtype()
674674
except Exception: # noqa: BLE001
675675
LOGGER.warning(
676-
f'Could not get data type of file {self.inputs.source_file[0]}'
676+
'Could not get data type of file %s', self.inputs.source_file[0]
677677
)
678678
data_dtype = None
679679

@@ -682,8 +682,10 @@ def _run_interface(self, runtime):
682682
orig_dtype = nii.get_data_dtype()
683683
if orig_dtype != data_dtype:
684684
LOGGER.warning(
685-
f'Changing {Path(dest_file).name} dtype '
686-
f'from {orig_dtype} to {data_dtype}'
685+
'Changing %s dtype from %s to %s',
686+
Path(dest_file).name,
687+
orig_dtype,
688+
data_dtype,
687689
)
688690
# coerce dataobj to new data dtype
689691
if np.issubdtype(data_dtype, np.integer):
@@ -1186,7 +1188,7 @@ def _run_interface(self, runtime):
11861188
data_dtype = nb.load(self.inputs.source_file[0]).get_data_dtype()
11871189
except Exception: # noqa: BLE001
11881190
LOGGER.warning(
1189-
f'Could not get data type of file {self.inputs.source_file[0]}'
1191+
'Could not get data type of file %s', self.inputs.source_file[0]
11901192
)
11911193
data_dtype = None
11921194

@@ -1195,7 +1197,7 @@ def _run_interface(self, runtime):
11951197
orig_dtype = nii.get_data_dtype()
11961198
if orig_dtype != data_dtype:
11971199
LOGGER.warning(
1198-
f'Changing {out_file} dtype from {orig_dtype} to {data_dtype}'
1200+
'Changing %s dtype from %s to %s', out_file, orig_dtype, orig_dtype
11991201
)
12001202
# coerce dataobj to new data dtype
12011203
if np.issubdtype(data_dtype, np.integer):

niworkflows/interfaces/confounds.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -534,20 +534,20 @@ def _expand_shorthand(model_formula, variables):
534534
nss = _get_matches_from_data('non_steady_state_outlier[0-9]+', variables)
535535
spikes = _get_matches_from_data('motion_outlier[0-9]+', variables)
536536

537-
model_formula = re.sub(r'wm', wm, model_formula)
538-
model_formula = re.sub(r'gsr', gsr, model_formula)
539-
model_formula = re.sub(r'rps', rps, model_formula)
540-
model_formula = re.sub(r'fd', fd, model_formula)
541-
model_formula = re.sub(r'acc', acc, model_formula)
542-
model_formula = re.sub(r'tcc', tcc, model_formula)
543-
model_formula = re.sub(r'dv', dv, model_formula)
544-
model_formula = re.sub(r'dvall', dvall, model_formula)
545-
model_formula = re.sub(r'nss', nss, model_formula)
546-
model_formula = re.sub(r'spikes', spikes, model_formula)
537+
model_formula = model_formula.replace('wm', wm)
538+
model_formula = model_formula.replace('gsr', gsr)
539+
model_formula = model_formula.replace('rps', rps)
540+
model_formula = model_formula.replace('fd', fd)
541+
model_formula = model_formula.replace('acc', acc)
542+
model_formula = model_formula.replace('tcc', tcc)
543+
model_formula = model_formula.replace('dv', dv)
544+
model_formula = model_formula.replace('dvall', dvall)
545+
model_formula = model_formula.replace('nss', nss)
546+
model_formula = model_formula.replace('spikes', spikes)
547547

548548
formula_variables = _get_variables_from_formula(model_formula)
549549
others = ' + '.join(set(variables) - set(formula_variables))
550-
model_formula = re.sub(r'others', others, model_formula)
550+
model_formula = model_formula.replace('others', others)
551551
return model_formula
552552

553553

niworkflows/interfaces/tests/test_bids.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ def make_empty_nii_with_dtype(fname, dtype):
571571
for s in source_file:
572572
make_empty_nii_with_dtype(s, source_dtype)
573573

574-
prep, save = make_prep_and_save(
574+
prep, _save = make_prep_and_save(
575575
interface,
576576
base_directory=str(tmp_path),
577577
data_dtype='source',

niworkflows/interfaces/tests/test_itk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_applytfms(tmpdir, ext, copy_dtype, in_dtype):
5050

5151
ifargs = {'copy_dtype': copy_dtype, 'reference_image': in_file}
5252
args = (in_file, in_xform, ifargs, 0, str(tmpdir))
53-
out_file, cmdline = _applytfms(args)
53+
out_file, _cmdline = _applytfms(args)
5454

5555
assert out_file == str(tmpdir / (f'src_xform-00000{ext}'))
5656

niworkflows/interfaces/tests/test_plotting.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
def test_cifti_carpetplot():
3636
"""Exercise extraction of timeseries from CIFTI2."""
37-
save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS', False)
37+
save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS')
3838

3939
cifti_file = load_test_data(
4040
'sub-01_task-mixedgamblestask_run-02_space-fsLR_den-91k_bold.dtseries.nii'
@@ -54,7 +54,7 @@ def test_cifti_carpetplot():
5454

5555
def test_nifti_carpetplot():
5656
"""Exercise extraction of timeseries from CIFTI2."""
57-
save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS', False)
57+
save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS')
5858

5959
nifti_file = load_test_data('sub-ds205s03_task-functionallocalizer_run-01_bold_volreg.nii.gz')
6060
seg_file = load_test_data('sub-ds205s03_task-functionallocalizer_run-01_bold_parc.nii.gz')

niworkflows/interfaces/workbench.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def _format_arg(self, opt, spec, val):
292292
if opt == 'valid_roi_out' and val:
293293
# generate a filename and add it to argstr
294294
roi_out = self._gen_filename(self.inputs.in_file, suffix='_roi')
295-
iflogger.info('Setting roi output file as', roi_out)
295+
iflogger.info('Setting roi output file as %s', roi_out)
296296
spec.argstr += ' ' + roi_out
297297
return super()._format_arg(opt, spec, val)
298298

niworkflows/reports/core.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,7 @@ def _process_orderings(orderings, layout):
462462
{value[idx] for value in all_value_combos} for idx in range(len(orderings))
463463
]
464464
# if all values are None for an entity, we do not want to keep that entity
465-
keep_idx = [
466-
not (len(val_set) == 1 and None in val_set or not val_set) for val_set in unique_values
467-
]
465+
keep_idx = [val_set not in (set(), {None}) for val_set in unique_values]
468466
# the "kept" entities
469467
entities = list(compress(orderings, keep_idx))
470468
# the "kept" value combinations

niworkflows/tests/test_confounds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
def _smoke_test_report(report_interface, artifact_name):
3838
out_report = report_interface.run().outputs.out_file
3939

40-
save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS', False)
40+
save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS')
4141
if save_artifacts:
4242
copy(out_report, os.path.join(save_artifacts, artifact_name))
4343
assert os.path.isfile(out_report), f'Report "{out_report}" does not exist'

0 commit comments

Comments
 (0)