diff --git a/niworkflows/engine/tests/test_plugin.py b/niworkflows/engine/tests/test_plugin.py index 7f3f5de5f3b..be2d76b66aa 100644 --- a/niworkflows/engine/tests/test_plugin.py +++ b/niworkflows/engine/tests/test_plugin.py @@ -8,7 +8,7 @@ from ..plugin import MultiProcPlugin -def add(x, y): # noqa: FURB118 # the Function interface does not support builtin functions +def add(x, y): # the Function interface does not support builtin functions return x + y diff --git a/niworkflows/func/tests/test_util.py b/niworkflows/func/tests/test_util.py index 2242ccc9b99..534dc8b0ae0 100644 --- a/niworkflows/func/tests/test_util.py +++ b/niworkflows/func/tests/test_util.py @@ -156,9 +156,7 @@ def test_masking(input_fname, expected_fname): res = wf.run(plugin='MultiProc') - combine_masks = [node for node in res.nodes if node.name.endswith('combine_masks')][ - 0 - ] + combine_masks = next(node for node in res.nodes if node.name.endswith('combine_masks')) overlap = symmetric_overlap(expected_fname, combine_masks.result.outputs.out_file) mask_dir = reports_dir / 'fmriprep_bold_mask' / dsname diff --git a/niworkflows/interfaces/bids.py b/niworkflows/interfaces/bids.py index 77dfccfaa3a..84c50f10f6e 100644 --- a/niworkflows/interfaces/bids.py +++ b/niworkflows/interfaces/bids.py @@ -673,7 +673,7 @@ def _run_interface(self, runtime): data_dtype = nb.load(self.inputs.source_file[0]).get_data_dtype() except Exception: # noqa: BLE001 LOGGER.warning( - f'Could not get data type of file {self.inputs.source_file[0]}' + 'Could not get data type of file %s', self.inputs.source_file[0] ) data_dtype = None @@ -682,8 +682,10 @@ def _run_interface(self, runtime): orig_dtype = nii.get_data_dtype() if orig_dtype != data_dtype: LOGGER.warning( - f'Changing {Path(dest_file).name} dtype ' - f'from {orig_dtype} to {data_dtype}' + 'Changing %s dtype from %s to %s', + Path(dest_file).name, + orig_dtype, + data_dtype, ) # coerce dataobj to new data dtype if np.issubdtype(data_dtype, np.integer): @@ -1186,7 +1188,7 @@ def _run_interface(self, runtime): data_dtype = nb.load(self.inputs.source_file[0]).get_data_dtype() except Exception: # noqa: BLE001 LOGGER.warning( - f'Could not get data type of file {self.inputs.source_file[0]}' + 'Could not get data type of file %s', self.inputs.source_file[0] ) data_dtype = None @@ -1195,7 +1197,7 @@ def _run_interface(self, runtime): orig_dtype = nii.get_data_dtype() if orig_dtype != data_dtype: LOGGER.warning( - f'Changing {out_file} dtype from {orig_dtype} to {data_dtype}' + 'Changing %s dtype from %s to %s', out_file, orig_dtype, orig_dtype ) # coerce dataobj to new data dtype if np.issubdtype(data_dtype, np.integer): diff --git a/niworkflows/interfaces/confounds.py b/niworkflows/interfaces/confounds.py index f9ae8340520..4dc5b103a57 100644 --- a/niworkflows/interfaces/confounds.py +++ b/niworkflows/interfaces/confounds.py @@ -534,20 +534,20 @@ def _expand_shorthand(model_formula, variables): nss = _get_matches_from_data('non_steady_state_outlier[0-9]+', variables) spikes = _get_matches_from_data('motion_outlier[0-9]+', variables) - model_formula = re.sub(r'wm', wm, model_formula) - model_formula = re.sub(r'gsr', gsr, model_formula) - model_formula = re.sub(r'rps', rps, model_formula) - model_formula = re.sub(r'fd', fd, model_formula) - model_formula = re.sub(r'acc', acc, model_formula) - model_formula = re.sub(r'tcc', tcc, model_formula) - model_formula = re.sub(r'dv', dv, model_formula) - model_formula = re.sub(r'dvall', dvall, model_formula) - model_formula = re.sub(r'nss', nss, model_formula) - model_formula = re.sub(r'spikes', spikes, model_formula) + model_formula = model_formula.replace('wm', wm) + model_formula = model_formula.replace('gsr', gsr) + model_formula = model_formula.replace('rps', rps) + model_formula = model_formula.replace('fd', fd) + model_formula = model_formula.replace('acc', acc) + model_formula = model_formula.replace('tcc', tcc) + model_formula = model_formula.replace('dv', dv) + model_formula = model_formula.replace('dvall', dvall) + model_formula = model_formula.replace('nss', nss) + model_formula = model_formula.replace('spikes', spikes) formula_variables = _get_variables_from_formula(model_formula) others = ' + '.join(set(variables) - set(formula_variables)) - model_formula = re.sub(r'others', others, model_formula) + model_formula = model_formula.replace('others', others) return model_formula diff --git a/niworkflows/interfaces/tests/test_bids.py b/niworkflows/interfaces/tests/test_bids.py index 9549c404315..5da592f8ece 100644 --- a/niworkflows/interfaces/tests/test_bids.py +++ b/niworkflows/interfaces/tests/test_bids.py @@ -571,7 +571,7 @@ def make_empty_nii_with_dtype(fname, dtype): for s in source_file: make_empty_nii_with_dtype(s, source_dtype) - prep, save = make_prep_and_save( + prep, _save = make_prep_and_save( interface, base_directory=str(tmp_path), data_dtype='source', diff --git a/niworkflows/interfaces/tests/test_itk.py b/niworkflows/interfaces/tests/test_itk.py index b622e36f3c5..9c8ee0e2421 100644 --- a/niworkflows/interfaces/tests/test_itk.py +++ b/niworkflows/interfaces/tests/test_itk.py @@ -50,7 +50,7 @@ def test_applytfms(tmpdir, ext, copy_dtype, in_dtype): ifargs = {'copy_dtype': copy_dtype, 'reference_image': in_file} args = (in_file, in_xform, ifargs, 0, str(tmpdir)) - out_file, cmdline = _applytfms(args) + out_file, _cmdline = _applytfms(args) assert out_file == str(tmpdir / (f'src_xform-00000{ext}')) diff --git a/niworkflows/interfaces/tests/test_plotting.py b/niworkflows/interfaces/tests/test_plotting.py index e5fc0a10934..5a604c8a1e3 100644 --- a/niworkflows/interfaces/tests/test_plotting.py +++ b/niworkflows/interfaces/tests/test_plotting.py @@ -34,7 +34,7 @@ def test_cifti_carpetplot(): """Exercise extraction of timeseries from CIFTI2.""" - save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS', False) + save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS') cifti_file = load_test_data( 'sub-01_task-mixedgamblestask_run-02_space-fsLR_den-91k_bold.dtseries.nii' @@ -54,7 +54,7 @@ def test_cifti_carpetplot(): def test_nifti_carpetplot(): """Exercise extraction of timeseries from CIFTI2.""" - save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS', False) + save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS') nifti_file = load_test_data('sub-ds205s03_task-functionallocalizer_run-01_bold_volreg.nii.gz') seg_file = load_test_data('sub-ds205s03_task-functionallocalizer_run-01_bold_parc.nii.gz') diff --git a/niworkflows/interfaces/workbench.py b/niworkflows/interfaces/workbench.py index 975f24f19f0..21474c02512 100644 --- a/niworkflows/interfaces/workbench.py +++ b/niworkflows/interfaces/workbench.py @@ -292,7 +292,7 @@ def _format_arg(self, opt, spec, val): if opt == 'valid_roi_out' and val: # generate a filename and add it to argstr roi_out = self._gen_filename(self.inputs.in_file, suffix='_roi') - iflogger.info('Setting roi output file as', roi_out) + iflogger.info('Setting roi output file as %s', roi_out) spec.argstr += ' ' + roi_out return super()._format_arg(opt, spec, val) diff --git a/niworkflows/reports/core.py b/niworkflows/reports/core.py index 54cfbb6bdd3..5c7a2926d05 100644 --- a/niworkflows/reports/core.py +++ b/niworkflows/reports/core.py @@ -462,9 +462,7 @@ def _process_orderings(orderings, layout): {value[idx] for value in all_value_combos} for idx in range(len(orderings)) ] # if all values are None for an entity, we do not want to keep that entity - keep_idx = [ - not (len(val_set) == 1 and None in val_set or not val_set) for val_set in unique_values - ] + keep_idx = [val_set not in (set(), {None}) for val_set in unique_values] # the "kept" entities entities = list(compress(orderings, keep_idx)) # the "kept" value combinations diff --git a/niworkflows/tests/test_confounds.py b/niworkflows/tests/test_confounds.py index b3862b020b5..27e23762b43 100644 --- a/niworkflows/tests/test_confounds.py +++ b/niworkflows/tests/test_confounds.py @@ -37,7 +37,7 @@ def _smoke_test_report(report_interface, artifact_name): out_report = report_interface.run().outputs.out_file - save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS', False) + save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS') if save_artifacts: copy(out_report, os.path.join(save_artifacts, artifact_name)) assert os.path.isfile(out_report), f'Report "{out_report}" does not exist' diff --git a/niworkflows/tests/test_registration.py b/niworkflows/tests/test_registration.py index f5f80a8294b..b9c2c53bee7 100644 --- a/niworkflows/tests/test_registration.py +++ b/niworkflows/tests/test_registration.py @@ -47,7 +47,7 @@ def _smoke_test_report(report_interface, artifact_name): res = pe.Node(report_interface, name='smoke_test', base_dir=tmpdir).run() out_report = res.outputs.out_report - save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS', False) + save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS') if save_artifacts: copy(out_report, os.path.join(save_artifacts, artifact_name)) assert os.path.isfile(out_report), 'Report does not exist' diff --git a/niworkflows/tests/test_segmentation.py b/niworkflows/tests/test_segmentation.py index 52729c62c8d..c04dbd29143 100644 --- a/niworkflows/tests/test_segmentation.py +++ b/niworkflows/tests/test_segmentation.py @@ -46,7 +46,7 @@ def _smoke_test_report(report_interface, artifact_name): res = pe.Node(report_interface, name='smoke_test', base_dir=tmpdir).run() out_report = res.outputs.out_report - save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS', False) + save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS') if save_artifacts: copy(out_report, os.path.join(save_artifacts, artifact_name)) assert os.path.isfile(out_report), f'Report "{out_report}" does not exist' diff --git a/niworkflows/tests/test_viz.py b/niworkflows/tests/test_viz.py index 82b65d3a99d..c973dc4e89b 100644 --- a/niworkflows/tests/test_viz.py +++ b/niworkflows/tests/test_viz.py @@ -43,7 +43,7 @@ @pytest.mark.parametrize('sorting', [None, 'ward', 'linkage']) def test_carpetplot(tr, sorting): """Write a carpetplot""" - save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS', False) + save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS') rng = np.random.default_rng(2010) @@ -137,7 +137,7 @@ def test_carpetplot(tr, sorting): ) def test_fmriplot(input_files): """Exercise the fMRIPlot class.""" - save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS', False) + save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS') rng = np.random.default_rng(2010) in_file = os.path.join(datadir, input_files[0]) diff --git a/pyproject.toml b/pyproject.toml index c825d35625c..9b0b3e6bced 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -118,9 +118,6 @@ line-length = 99 [tool.ruff.lint] extend-select = [ - "F", - "E", - "W", "I", "UP", "YTT", @@ -128,8 +125,8 @@ extend-select = [ "BLE", "B", "A", - # "CPY", "C4", + # "CPY", "DTZ", "T10", # "EM", @@ -137,13 +134,33 @@ extend-select = [ "FA", "ISC", "ICN", + "LOG", + "G", + "PIE", + "PYI", "PT", "Q", + # "SIM", + # "TID", + "FLY", + # "PD", + "PERF", + "W", + "PGH", + "PLC", + "PLE", + "PLW", + "FURB", + "RUF", ] ignore = [ "S311", # We are not using random for cryptographic purposes - "ISC001", + "S404", "S603", + "PLW1510", + "PLW2901", + "RUF005", + "RUF012", ] [tool.ruff.lint.flake8-quotes]