Skip to content

Commit

Permalink
Merge pull request #923 from mgxd/sty/ruff-0.9.0
Browse files Browse the repository at this point in the history
STY: Format + add git blame ignore file
  • Loading branch information
mgxd authored Jan 13, 2025
2 parents 7337fb1 + 5536e4f commit 08c182c
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# 2025-01-09 - [email protected] - STY: Ruff format [git-blame-ignore-rev]
75136b2bb86426c22609449b3f48579ee9c2e4f5
8 changes: 4 additions & 4 deletions niworkflows/interfaces/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ def _run_interface(self, runtime):
_copy_any(in_file, out_file)

if self.inputs.metadata:
sidecar = out_file.parent / f"{out_file.name.split('.', 1)[0]}.json"
sidecar = out_file.parent / f'{out_file.name.split(".", 1)[0]}.json'
sidecar.unlink(missing_ok=True)
sidecar.write_text(dumps(self.inputs.metadata, indent=2))
self._results['out_meta'].append(str(sidecar))
Expand Down Expand Up @@ -1237,7 +1237,7 @@ def _run_interface(self, runtime):
{k: getattr(self.inputs, k) for k in meta_fields if k not in self._static_traits}
)
if self._metadata:
sidecar = out_file.parent / f"{out_file.name.split('.', 1)[0]}.json"
sidecar = out_file.parent / f'{out_file.name.split(".", 1)[0]}.json'
unlink(sidecar, missing_ok=True)
sidecar.write_text(dumps(self._metadata, sort_keys=True, indent=2))
self._results['out_meta'] = str(sidecar)
Expand Down Expand Up @@ -1483,6 +1483,6 @@ def _fmt_xyz(coords: list) -> str:
return f'{xyz} mm^3'

return (
f"Template {space} ({_fmt_xyz(res_meta['zooms'])}),"
f" curated by TemplateFlow {tf.__version__}"
f'Template {space} ({_fmt_xyz(res_meta["zooms"])}),'
f' curated by TemplateFlow {tf.__version__}'
)
3 changes: 1 addition & 2 deletions niworkflows/interfaces/confounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ class _SpikeRegressorsInputSpec(BaseInterfaceInputSpec):
concatenate = traits.Bool(
True,
usedefault=True,
desc='Indicates whether to concatenate spikes to existing confounds '
'or return spikes only',
desc='Indicates whether to concatenate spikes to existing confounds or return spikes only',
)
output_format = traits.Enum(
'spikes', 'mask', usedefault=True, desc='Format of output (spikes or mask)'
Expand Down
3 changes: 1 addition & 2 deletions niworkflows/interfaces/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,7 @@ def _run_interface(self, runtime):
# This check assumes all input masks have same dimensions
if img.shape[:3] != mask_imgs[0].shape[:3]:
raise NotImplementedError(
'Input image and mask should be of '
'same dimensions before running SignalExtraction'
'Input image and mask should be of same dimensions before running SignalExtraction'
)
# Load the mask.
# If mask is a list, each mask is treated as its own ROI/parcel
Expand Down
3 changes: 1 addition & 2 deletions niworkflows/interfaces/itk.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ class _MultiApplyTransformsInputSpec(_FixTraitApplyTransformsInputSpec):
input_image = InputMultiObject(
File(exists=True),
mandatory=True,
desc='input time-series as a list of volumes after splitting'
' through the fourth dimension',
desc='input time-series as a list of volumes after splitting through the fourth dimension',
)
num_threads = traits.Int(1, usedefault=True, nohash=True, desc='number of parallel processes')
save_cmd = traits.Bool(
Expand Down
2 changes: 1 addition & 1 deletion niworkflows/interfaces/nibabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def _run_interface(self, runtime):
img = nb.load(in_file)
extra_dims = tuple(dim for dim in img.shape[3:] if dim > 1) or (1,)
if len(extra_dims) != 1:
raise ValueError(f"Invalid shape {'x'.join(str(s) for s in img.shape)}")
raise ValueError(f'Invalid shape {"x".join(str(s) for s in img.shape)}')
img = img.__class__(
img.dataobj.reshape(img.shape[:3] + extra_dims), img.affine, img.header
)
Expand Down
2 changes: 1 addition & 1 deletion niworkflows/interfaces/surf.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def _run_interface(self, runtime):
in_file = Path(self.inputs.in_file)
extension = ''.join(in_file.suffixes[-((in_file.suffixes[-1] == '.gz') + 1) :])
info = self._pattern.match(in_file.name[: -len(extension)]).groupdict()
self._results['extension'] = f"{info.pop('extprefix', None) or ''}{extension}"
self._results['extension'] = f'{info.pop("extprefix", None) or ""}{extension}'
self._results.update(info)
if 'hemi' in self._results:
self._results['hemi'] = self._results['hemi'].upper()
Expand Down
3 changes: 1 addition & 2 deletions niworkflows/interfaces/workbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ class MetricDilateInputSpec(OpenMPTraitedSpec):
argstr='-exponent %f ',
position=9,
default=6.0,
desc='exponent n to use in (area / (distance ^ n)) as the '
'weighting function (default 6)',
desc='exponent n to use in (area / (distance ^ n)) as the weighting function (default 6)',
)

corrected_areas = File(
Expand Down
3 changes: 1 addition & 2 deletions niworkflows/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,5 @@ def test_compression(tmp_path):
size = int(os.stat(uncompressed).st_size)
size_compress = int(os.stat(compressed).st_size)
assert size >= size_compress, (
f'The uncompressed report is smaller ({size})'
f'than the compressed report ({size_compress})'
f'The uncompressed report is smaller ({size})than the compressed report ({size_compress})'
)
12 changes: 6 additions & 6 deletions niworkflows/tests/test_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def test_carpetplot(tr, sorting):
output_file=(
os.path.join(
save_artifacts,
f"carpet_nosegs_{'index' if tr is None else 'time'}_"
f"{'nosort' if sorting is None else sorting}.svg",
f'carpet_nosegs_{"index" if tr is None else "time"}_'
f'{"nosort" if sorting is None else sorting}.svg',
)
if save_artifacts
else None
Expand Down Expand Up @@ -87,8 +87,8 @@ def test_carpetplot(tr, sorting):
output_file=(
os.path.join(
save_artifacts,
f"carpet_random_{'index' if tr is None else 'seg'}_"
f"{'nosort' if sorting is None else sorting}.svg",
f'carpet_random_{"index" if tr is None else "seg"}_'
f'{"nosort" if sorting is None else sorting}.svg',
)
if save_artifacts
else None
Expand All @@ -114,8 +114,8 @@ def test_carpetplot(tr, sorting):
output_file=(
os.path.join(
save_artifacts,
f"carpet_const_{'index' if tr is None else 'time'}_"
f"{'nosort' if sorting is None else sorting}.svg",
f'carpet_const_{"index" if tr is None else "time"}_'
f'{"nosort" if sorting is None else sorting}.svg',
)
if save_artifacts
else None
Expand Down
2 changes: 1 addition & 1 deletion niworkflows/utils/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ def to_json(filename, data):


def combine_entities(**entities):
return f"_{'_'.join([f'{lab}-{val}' for lab, val in entities.items()])}" if entities else ''
return f'_{"_".join([f"{lab}-{val}" for lab, val in entities.items()])}' if entities else ''
6 changes: 3 additions & 3 deletions niworkflows/utils/tests/test_spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ def test_space_action(parser, spaces, expected):
pargs = parser.parse_known_args(args=('--spaces',) + spaces)[0]
parsed_spaces = pargs.spaces
assert isinstance(parsed_spaces, SpatialReferences)
assert all(
isinstance(sp, Reference) for sp in parsed_spaces.references
), 'Every element must be a `Reference`'
assert all(isinstance(sp, Reference) for sp in parsed_spaces.references), (
'Every element must be a `Reference`'
)
assert len(parsed_spaces.references) == len(expected)
for ref, expected_ref in zip(parsed_spaces.references, expected):
assert str(ref) == expected_ref
Expand Down

0 comments on commit 08c182c

Please sign in to comment.