diff --git a/niworkflows/__init__.py b/niworkflows/__init__.py index d3cf16edeaf..39e388513e8 100644 --- a/niworkflows/__init__.py +++ b/niworkflows/__init__.py @@ -15,11 +15,11 @@ __all__ = [ - '__version__', - '__packagename__', + 'NIWORKFLOWS_LOG', '__copyright__', '__credits__', - 'NIWORKFLOWS_LOG', + '__packagename__', + '__version__', 'load_resource', ] diff --git a/niworkflows/engine/plugin.py b/niworkflows/engine/plugin.py index ba7e31e6007..7aa5d0ee414 100644 --- a/niworkflows/engine/plugin.py +++ b/niworkflows/engine/plugin.py @@ -303,7 +303,7 @@ def _local_hash_check(self, jobid, graph): overwrite = self.procs[jobid].overwrite always_run = self.procs[jobid].interface.always_run - if cached and updated and (overwrite is False or overwrite is None and not always_run): + if cached and updated and (overwrite is False or (overwrite is None and not always_run)): try: self._task_finished_cb(jobid, cached=True) self._remove_node_dirs() diff --git a/niworkflows/interfaces/bids.py b/niworkflows/interfaces/bids.py index ec7131dff3a..5fa6b3c2303 100644 --- a/niworkflows/interfaces/bids.py +++ b/niworkflows/interfaces/bids.py @@ -1470,7 +1470,7 @@ def _get_tf_resolution(space: str, resolution: str) -> str: res_meta = None # Due to inconsistencies, resolution keys may or may not be zero-padded - padded_res = f'{str(resolution):0>2}' + padded_res = f'{resolution:0>2}' for r in (resolution, padded_res): if r in resolutions: res_meta = resolutions[r] diff --git a/niworkflows/interfaces/cifti.py b/niworkflows/interfaces/cifti.py index c61b4c45b4f..bbe67ea75e4 100644 --- a/niworkflows/interfaces/cifti.py +++ b/niworkflows/interfaces/cifti.py @@ -202,7 +202,7 @@ def _prepare_cifti(grayordinates: str) -> tuple[list, str, dict]: '170k': {'surface-den': '59k', 'tf-res': '06', 'grayords': '170,494', 'res-mm': '1.6mm'}, } if grayordinates not in grayord_key: - raise NotImplementedError('Grayordinates {grayordinates} is not supported.') + raise NotImplementedError(f'Grayordinates {grayordinates} is not supported.') tf_vol_res = grayord_key[grayordinates]['tf-res'] total_grayords = grayord_key[grayordinates]['grayords'] diff --git a/niworkflows/interfaces/confounds.py b/niworkflows/interfaces/confounds.py index 1f7d026b2ef..c9b63f109e5 100644 --- a/niworkflows/interfaces/confounds.py +++ b/niworkflows/interfaces/confounds.py @@ -535,20 +535,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('wm', wm, model_formula) - model_formula = re.sub('gsr', gsr, model_formula) - model_formula = re.sub('rps', rps, model_formula) - model_formula = re.sub('fd', fd, model_formula) - model_formula = re.sub('acc', acc, model_formula) - model_formula = re.sub('tcc', tcc, model_formula) - model_formula = re.sub('dv', dv, model_formula) - model_formula = re.sub('dvall', dvall, model_formula) - model_formula = re.sub('nss', nss, model_formula) - model_formula = re.sub('spikes', spikes, model_formula) + 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) formula_variables = _get_variables_from_formula(model_formula) others = ' + '.join(set(variables) - set(formula_variables)) - model_formula = re.sub('others', others, model_formula) + model_formula = re.sub(r'others', others, model_formula) return model_formula diff --git a/niworkflows/interfaces/nibabel.py b/niworkflows/interfaces/nibabel.py index d041164a692..d8c4a7b2094 100644 --- a/niworkflows/interfaces/nibabel.py +++ b/niworkflows/interfaces/nibabel.py @@ -22,6 +22,8 @@ # """Nibabel-based interfaces.""" +from __future__ import annotations + from pathlib import Path from warnings import warn @@ -520,9 +522,9 @@ def _run_interface(self, runtime): def reorient_file( in_file: str, *, - target_file: str = None, - target_ornt: str = None, - newpath: str = None, + target_file: str | None = None, + target_ornt: str | None = None, + newpath: str | None = None, ) -> str: """ Reorient an image. diff --git a/niworkflows/interfaces/nilearn.py b/niworkflows/interfaces/nilearn.py index 711098d095c..bf1f7bdf175 100644 --- a/niworkflows/interfaces/nilearn.py +++ b/niworkflows/interfaces/nilearn.py @@ -47,7 +47,7 @@ NILEARN_VERSION = 'unknown' LOGGER = logging.getLogger('nipype.interface') -__all__ = ['NILEARN_VERSION', 'MaskEPI', 'Merge', 'ComputeEPIMask'] +__all__ = ['NILEARN_VERSION', 'ComputeEPIMask', 'MaskEPI', 'Merge'] class _MaskEPIInputSpec(BaseInterfaceInputSpec): diff --git a/niworkflows/interfaces/tests/test_nibabel.py b/niworkflows/interfaces/tests/test_nibabel.py index 7207502a344..498c9160ff4 100644 --- a/niworkflows/interfaces/tests/test_nibabel.py +++ b/niworkflows/interfaces/tests/test_nibabel.py @@ -49,7 +49,7 @@ def create_roi(tmp_path): def _create_roi(affine, img_data, roi_index): img_data[tuple(roi_index)] = 1 nii = nb.Nifti1Image(img_data, affine) - filename = tmp_path / f'{str(uuid.uuid4())}.nii.gz' + filename = tmp_path / f'{uuid.uuid4()}.nii.gz' files.append(filename) nii.to_filename(filename) return filename diff --git a/niworkflows/reports/core.py b/niworkflows/reports/core.py index d954fa34c97..70e30f2d745 100644 --- a/niworkflows/reports/core.py +++ b/niworkflows/reports/core.py @@ -384,7 +384,7 @@ def generate_report(self): if (logs_path / 'CITATION.html').exists(): text = ( - re.compile('
(.*?)', re.DOTALL | re.IGNORECASE) + re.compile(r'(.*?)', re.DOTALL | re.IGNORECASE) .findall((logs_path / 'CITATION.html').read_text())[0] .strip() ) diff --git a/niworkflows/utils/bids.py b/niworkflows/utils/bids.py index d323464f8ce..621d642055e 100644 --- a/niworkflows/utils/bids.py +++ b/niworkflows/utils/bids.py @@ -388,7 +388,7 @@ def group_multiecho(bold_sess): def _grp_echos(x): if '_echo-' not in x: return x - echo = re.search('_echo-\\d*', x).group(0) + echo = re.search(r'_echo-\d*', x).group(0) return x.replace(echo, '_echo-?') ses_uids = [] diff --git a/niworkflows/utils/misc.py b/niworkflows/utils/misc.py index e06b956f86e..0793ae42784 100644 --- a/niworkflows/utils/misc.py +++ b/niworkflows/utils/misc.py @@ -28,13 +28,13 @@ import warnings __all__ = [ - 'get_template_specs', - 'fix_multi_T1w_source_name', + '_copy_any', 'add_suffix', + 'clean_directory', + 'fix_multi_T1w_source_name', + 'get_template_specs', 'read_crashfile', 'splitext', - '_copy_any', - 'clean_directory', ] diff --git a/niworkflows/utils/spaces.py b/niworkflows/utils/spaces.py index eb82851bd7c..ac6b607573c 100644 --- a/niworkflows/utils/spaces.py +++ b/niworkflows/utils/spaces.py @@ -464,7 +464,7 @@ class SpatialReferences: """ - __slots__ = ('_refs', '_cached') + __slots__ = ('_cached', '_refs') standard_spaces = tuple(_tfapi.templates()) """List of supported standard reference spaces.""" diff --git a/niworkflows/viz/__init__.py b/niworkflows/viz/__init__.py index 0a86420550c..151dae80d25 100644 --- a/niworkflows/viz/__init__.py +++ b/niworkflows/viz/__init__.py @@ -11,4 +11,4 @@ warnings.warn(msg, PendingDeprecationWarning, stacklevel=2) -__all__ = ['plot_carpet', 'SVGNS'] +__all__ = ['SVGNS', 'plot_carpet'] diff --git a/niworkflows/viz/plots.py b/niworkflows/viz/plots.py index 3ae21769cf8..f837bbc5834 100644 --- a/niworkflows/viz/plots.py +++ b/niworkflows/viz/plots.py @@ -39,14 +39,14 @@ class fMRIPlot: """Generates the fMRI Summary Plot.""" __slots__ = ( - 'timeseries', - 'segments', - 'tr', 'confounds', - 'spikes', 'nskip', - 'sort_carpet', 'paired_carpet', + 'segments', + 'sort_carpet', + 'spikes', + 'timeseries', + 'tr', ) def __init__( diff --git a/niworkflows/viz/utils.py b/niworkflows/viz/utils.py index a82ce564925..60883cfb203 100644 --- a/niworkflows/viz/utils.py +++ b/niworkflows/viz/utils.py @@ -138,10 +138,10 @@ def extract_svg(display_object, dpi=300, compress='auto'): image_svg = svg2str(display_object, dpi) if compress is True or compress == 'auto': image_svg = svg_compress(image_svg, compress) - image_svg = re.sub(' height="[0-9]+[a-z]*"', '', image_svg, count=1) - image_svg = re.sub(' width="[0-9]+[a-z]*"', '', image_svg, count=1) + image_svg = re.sub(r' height="[0-9]+[a-z]*"', '', image_svg, count=1) + image_svg = re.sub(r' width="[0-9]+[a-z]*"', '', image_svg, count=1) image_svg = re.sub( - ' viewBox', ' preseveAspectRation="xMidYMid meet" viewBox', image_svg, count=1 + r' viewBox', ' preseveAspectRation="xMidYMid meet" viewBox', image_svg, count=1 ) start_tag = '