Skip to content

Commit

Permalink
Merge pull request #817 from DimitriPapadopoulos/pyupgrade
Browse files Browse the repository at this point in the history
MNT: Pyupgrade suggestions
  • Loading branch information
effigies authored Jul 13, 2023
2 parents 5fb2e2f + c6f6317 commit 53ccf79
Show file tree
Hide file tree
Showing 20 changed files with 52 additions and 59 deletions.
2 changes: 0 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
Expand Down
1 change: 0 additions & 1 deletion niworkflows/engine/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""
Expand Down
2 changes: 1 addition & 1 deletion niworkflows/engine/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, name, base_dir=None):
path to workflow storage
"""
super(LiterateWorkflow, self).__init__(name, base_dir)
super().__init__(name, base_dir)
self.__desc__ = None
self.__postdesc__ = None

Expand Down
6 changes: 3 additions & 3 deletions niworkflows/interfaces/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class BIDSDataGrabber(SimpleInterface):
def __init__(self, *args, **kwargs):
anat_only = kwargs.pop("anat_only")
anat_derivatives = kwargs.pop("anat_derivatives", None)
super(BIDSDataGrabber, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
if anat_only is not None:
self._require_funcs = not anat_only
self._require_t1w = anat_derivatives is None
Expand Down Expand Up @@ -820,12 +820,12 @@ class ReadSidecarJSON(SimpleInterface):
def __init__(self, fields=None, undef_fields=False, **inputs):
from bids.utils import listify

super(ReadSidecarJSON, self).__init__(**inputs)
super().__init__(**inputs)
self._fields = listify(fields or [])
self._undef_fields = undef_fields

def _outputs(self):
base = super(ReadSidecarJSON, self)._outputs()
base = super()._outputs()
if self._fields:
base = add_traits(base, self._fields)
return base
Expand Down
12 changes: 6 additions & 6 deletions niworkflows/interfaces/fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class FixHeaderApplyTransforms(ApplyTransforms):

def _run_interface(self, runtime, correct_return_codes=(0,)):
# Run normally
runtime = super(FixHeaderApplyTransforms, self)._run_interface(
runtime = super()._run_interface(
runtime, correct_return_codes
)

Expand Down Expand Up @@ -100,7 +100,7 @@ class FixHeaderRegistration(Registration):

def _run_interface(self, runtime, correct_return_codes=(0,)):
# Run normally
runtime = super(FixHeaderRegistration, self)._run_interface(
runtime = super()._run_interface(
runtime, correct_return_codes
)

Expand Down Expand Up @@ -143,12 +143,12 @@ def __init__(self, *args, **kwargs):
"""Add a private property to keep the path to the right input."""
self._input_image = None
self._negative_values = False
super(FixN4BiasFieldCorrection, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def _format_arg(self, name, trait_spec, value):
if name == "input_image":
return trait_spec.argstr % self._input_image
return super(FixN4BiasFieldCorrection, self)._format_arg(
return super()._format_arg(
name, trait_spec, value
)

Expand All @@ -166,9 +166,9 @@ def _parse_inputs(self, skip=None):
newnii.to_filename(self._input_image)
self._negative_values = True

return super(FixN4BiasFieldCorrection, self)._parse_inputs(skip=skip)
return super()._parse_inputs(skip=skip)

def _list_outputs(self):
outputs = super(FixN4BiasFieldCorrection, self)._list_outputs()
outputs = super()._list_outputs()
outputs["negative_values"] = self._negative_values
return outputs
10 changes: 5 additions & 5 deletions niworkflows/interfaces/freesurfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ def _num_vols(self):
def cmdline(self):
if self._num_vols() == 1:
return "echo Only one time point!"
return super(StructuralReference, self).cmdline
return super().cmdline

def _list_outputs(self):
outputs = super(StructuralReference, self)._list_outputs()
outputs = super()._list_outputs()
if self._num_vols() == 1:
in_file = self.inputs.in_files[0]
outputs["out_file"] = in_file
Expand Down Expand Up @@ -117,7 +117,7 @@ class MakeMidthickness(fs.MRIsExpand):

@property
def cmdline(self):
cmd = super(MakeMidthickness, self).cmdline
cmd = super().cmdline
if not isdefined(self.inputs.graymid) or len(self.inputs.graymid) < 1:
return cmd

Expand Down Expand Up @@ -217,7 +217,7 @@ def _run_interface(self, runtime):
return runtime


class TruncateLTA(object):
class TruncateLTA:
"""
Truncate long filenames in LTA files.
Expand Down Expand Up @@ -247,7 +247,7 @@ def _post_run_hook(self, runtime):

fix_lta_length(lta_file)

runtime = super(TruncateLTA, self)._post_run_hook(runtime)
runtime = super()._post_run_hook(runtime)
return runtime


Expand Down
4 changes: 2 additions & 2 deletions niworkflows/interfaces/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ def __init__(self, fields=None, **inputs):
if isinstance(self._fields, str):
self._fields = [self._fields]

super(CopyXForm, self).__init__(**inputs)
super().__init__(**inputs)

add_traits(self.inputs, self._fields)
for f in set(self._fields).intersection(list(inputs.keys())):
setattr(self.inputs, f, inputs[f])

def _outputs(self):
base = super(CopyXForm, self)._outputs()
base = super()._outputs()
if self._fields:
fields = self._fields.copy()
if "in_file" in fields:
Expand Down
6 changes: 3 additions & 3 deletions niworkflows/interfaces/nilearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ def _run_interface(self, runtime):
self._mask_file = os.path.join(runtime.cwd, "mask_file.nii.gz")

runtime.returncode = 0
return super(ComputeEPIMask, self)._run_interface(runtime)
return super()._run_interface(runtime)

def _list_outputs(self):
outputs = super(ComputeEPIMask, self)._list_outputs()
outputs = super()._list_outputs()
outputs["mask_file"] = self._mask_file
return outputs

Expand All @@ -261,7 +261,7 @@ def _post_run_hook(self, runtime):
self._mask_file,
)

return super(ComputeEPIMask, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)


def _enhance_t2_contrast(in_file, newpath=None, offset=0.5):
Expand Down
2 changes: 1 addition & 1 deletion niworkflows/interfaces/norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def __init__(self, **inputs):
self._reference_image = None
self.retry = 1
self.terminal_output = "file"
super(SpatialNormalization, self).__init__(**inputs)
super().__init__(**inputs)

def _get_settings(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions niworkflows/interfaces/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _run_interface(self, runtime):
failures = 0
while True:
try:
runtime = super(RobustACompCor, self)._run_interface(runtime)
runtime = super()._run_interface(runtime)
break
except LinAlgError:
failures += 1
Expand All @@ -63,7 +63,7 @@ def _run_interface(self, runtime):
failures = 0
while True:
try:
runtime = super(RobustTCompCor, self)._run_interface(runtime)
runtime = super()._run_interface(runtime)
break
except LinAlgError:
failures += 1
Expand Down
2 changes: 1 addition & 1 deletion niworkflows/interfaces/reportlets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class ReportingInterface(reporting.ReportCapableInterface):
output_spec = reporting.ReportCapableOutputSpec

def __init__(self, generate_report=True, **kwargs):
super(ReportingInterface, self).__init__(
super().__init__(
generate_report=generate_report, **kwargs
)

Expand Down
12 changes: 6 additions & 6 deletions niworkflows/interfaces/reportlets/masks.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _run_interface(self, runtime):
if self.generate_report:
self.inputs.mask = True

return super(BETRPT, self)._run_interface(runtime)
return super()._run_interface(runtime)

def _post_run_hook(self, runtime):
"""generates a report showing slices from each axis of an arbitrary
Expand All @@ -74,7 +74,7 @@ def _post_run_hook(self, runtime):
self._mask_file,
)

return super(BETRPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)


class _BrainExtractionInputSpecRPT(
Expand Down Expand Up @@ -117,7 +117,7 @@ def _post_run_hook(self, runtime):
self._mask_file,
)

return super(BrainExtractionRPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)


class _ACompCorInputSpecRPT(nrb._SVGReportCapableInputSpec, confounds.CompCorInputSpec):
Expand Down Expand Up @@ -153,7 +153,7 @@ def _post_run_hook(self, runtime):
self._mask_file,
)

return super(ACompCorRPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)


class _TCompCorInputSpecRPT(
Expand Down Expand Up @@ -195,7 +195,7 @@ def _post_run_hook(self, runtime):
self.aggregate_outputs(runtime=runtime).high_variance_masks,
)

return super(TCompCorRPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)


class _SimpleShowMaskInputSpec(nrb._SVGReportCapableInputSpec):
Expand All @@ -212,7 +212,7 @@ def _post_run_hook(self, runtime):
self._seg_files = [self.inputs.mask_file]
self._masked = True

return super(SimpleShowMaskRPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)


class _ROIsPlotInputSpecRPT(nrb._SVGReportCapableInputSpec):
Expand Down
20 changes: 10 additions & 10 deletions niworkflows/interfaces/reportlets/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _post_run_hook(self, runtime):
self._moving_image,
)

return super(SpatialNormalizationRPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)


class _ANTSRegistrationInputSpecRPT(
Expand Down Expand Up @@ -106,7 +106,7 @@ def _post_run_hook(self, runtime):
self._moving_image,
)

return super(ANTSRegistrationRPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)


class _ANTSApplyTransformsInputSpecRPT(
Expand Down Expand Up @@ -134,7 +134,7 @@ def _post_run_hook(self, runtime):
self._moving_image,
)

return super(ANTSApplyTransformsRPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)


class _ApplyTOPUPInputSpecRPT(
Expand Down Expand Up @@ -169,7 +169,7 @@ def _post_run_hook(self, runtime):
self._moving_image,
)

return super(ApplyTOPUPRPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)


class _FUGUEInputSpecRPT(nrb._SVGReportCapableInputSpec, fsl.preprocess.FUGUEInputSpec):
Expand Down Expand Up @@ -198,7 +198,7 @@ def _post_run_hook(self, runtime):
self._moving_image,
)

return super(FUGUERPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)


class _FLIRTInputSpecRPT(nrb._SVGReportCapableInputSpec, fsl.preprocess.FLIRTInputSpec):
Expand All @@ -225,7 +225,7 @@ def _post_run_hook(self, runtime):
self._moving_image,
)

return super(FLIRTRPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)


class _ApplyXFMInputSpecRPT(
Expand Down Expand Up @@ -291,7 +291,7 @@ def _post_run_hook(self, runtime):
self._moving_image,
)

return super(BBRegisterRPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)


class _MRICoregInputSpecRPT(
Expand Down Expand Up @@ -342,7 +342,7 @@ def _post_run_hook(self, runtime):
self._moving_image,
)

return super(MRICoregRPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)


class _SimpleBeforeAfterInputSpecRPT(nrb._SVGReportCapableInputSpec):
Expand Down Expand Up @@ -373,7 +373,7 @@ def _post_run_hook(self, runtime):
self._moving_image,
)

return super(SimpleBeforeAfterRPT, self)._post_run_hook(runtime)
return super()._post_run_hook(runtime)


class _ResampleBeforeAfterInputSpecRPT(_SimpleBeforeAfterInputSpecRPT):
Expand Down Expand Up @@ -411,7 +411,7 @@ def _post_run_hook(self, runtime):
self._moving_image,
)

runtime = super(ResampleBeforeAfterRPT, self)._post_run_hook(runtime)
runtime = super()._post_run_hook(runtime)
NIWORKFLOWS_LOG.info("Successfully created report (%s)", self._out_report)
os.unlink(fname)

Expand Down
Loading

0 comments on commit 53ccf79

Please sign in to comment.