Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STY: Apply ruff rules (RUF) #919

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions niworkflows/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@


__all__ = [
'__version__',
'__packagename__',
'NIWORKFLOWS_LOG',
'__copyright__',
'__credits__',
'NIWORKFLOWS_LOG',
'__packagename__',
'__version__',
'load_resource',
]

Expand Down
2 changes: 1 addition & 1 deletion niworkflows/engine/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion niworkflows/interfaces/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion niworkflows/interfaces/cifti.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
22 changes: 11 additions & 11 deletions niworkflows/interfaces/confounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
8 changes: 5 additions & 3 deletions niworkflows/interfaces/nibabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#
"""Nibabel-based interfaces."""

from __future__ import annotations

from pathlib import Path
from warnings import warn

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion niworkflows/interfaces/nilearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion niworkflows/interfaces/tests/test_nibabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion niworkflows/reports/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def generate_report(self):

if (logs_path / 'CITATION.html').exists():
text = (
re.compile('<body>(.*?)</body>', re.DOTALL | re.IGNORECASE)
re.compile(r'<body>(.*?)</body>', re.DOTALL | re.IGNORECASE)
.findall((logs_path / 'CITATION.html').read_text())[0]
.strip()
)
Expand Down
2 changes: 1 addition & 1 deletion niworkflows/utils/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
8 changes: 4 additions & 4 deletions niworkflows/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]


Expand Down
2 changes: 1 addition & 1 deletion niworkflows/utils/spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ class SpatialReferences:

"""

__slots__ = ('_refs', '_cached')
__slots__ = ('_cached', '_refs')
standard_spaces = tuple(_tfapi.templates())
"""List of supported standard reference spaces."""

Expand Down
2 changes: 1 addition & 1 deletion niworkflows/viz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@

warnings.warn(msg, PendingDeprecationWarning, stacklevel=2)

__all__ = ['plot_carpet', 'SVGNS']
__all__ = ['SVGNS', 'plot_carpet']
10 changes: 5 additions & 5 deletions niworkflows/viz/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down
6 changes: 3 additions & 3 deletions niworkflows/viz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<svg '
start_idx = image_svg.find(start_tag)
Expand Down
Loading