From a1eae4dde7d4a3d5fd8951b0f2a0b7167e3efdfe Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Thu, 15 Jun 2023 00:21:57 +0200 Subject: [PATCH 1/4] MNT: Remove `coding: utf-8` The default encoding for Python 3 sources is UTF-8: https://peps.python.org/pep-3120 --- docs/conf.py | 2 -- niworkflows/engine/__init__.py | 1 - niworkflows/interfaces/workbench.py | 1 - niworkflows/tests/__init__.py | 1 - 4 files changed, 5 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 3eaedb75867..079c66f86b9 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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 diff --git a/niworkflows/engine/__init__.py b/niworkflows/engine/__init__.py index f0463b59f34..c8a53565712 100644 --- a/niworkflows/engine/__init__.py +++ b/niworkflows/engine/__init__.py @@ -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: """ diff --git a/niworkflows/interfaces/workbench.py b/niworkflows/interfaces/workbench.py index 07d66e59d7a..2ef8549e765 100644 --- a/niworkflows/interfaces/workbench.py +++ b/niworkflows/interfaces/workbench.py @@ -1,4 +1,3 @@ -# -*- 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: """This module provides interfaces for workbench surface commands.""" diff --git a/niworkflows/tests/__init__.py b/niworkflows/tests/__init__.py index ebc98379e4d..17554c20002 100644 --- a/niworkflows/tests/__init__.py +++ b/niworkflows/tests/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # @Author: oesteban # @Date: 2018-02-15 11:21:50 # @Last Modified by: oesteban From bd1a896eecf8ca5987eeea5d3416fafcc510f97d Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Thu, 15 Jun 2023 00:45:21 +0200 Subject: [PATCH 2/4] MNT: `object` inheritance is implicit --- niworkflows/interfaces/freesurfer.py | 2 +- niworkflows/reports/core.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/niworkflows/interfaces/freesurfer.py b/niworkflows/interfaces/freesurfer.py index 24cc1f9b1e5..6d958956241 100644 --- a/niworkflows/interfaces/freesurfer.py +++ b/niworkflows/interfaces/freesurfer.py @@ -217,7 +217,7 @@ def _run_interface(self, runtime): return runtime -class TruncateLTA(object): +class TruncateLTA: """ Truncate long filenames in LTA files. diff --git a/niworkflows/reports/core.py b/niworkflows/reports/core.py index 558b83664a0..81c021bada7 100644 --- a/niworkflows/reports/core.py +++ b/niworkflows/reports/core.py @@ -84,7 +84,7 @@ def __gt__(self, other): return False -class Element(object): +class Element: """Just a basic component of a report""" def __init__(self, name, title=None): From e3a4b3e5375b8b2d1b5a8c42f46a43f432bc35e4 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Thu, 15 Jun 2023 00:56:31 +0200 Subject: [PATCH 3/4] MNT: do not pass the default arguments of super() In Python 3, the default arguments of the builtin super() are the current class and instance: https://docs.python.org/3/library/functions.html#super --- niworkflows/engine/workflows.py | 2 +- niworkflows/interfaces/bids.py | 6 +++--- niworkflows/interfaces/fixes.py | 12 +++++------ niworkflows/interfaces/freesurfer.py | 8 ++++---- niworkflows/interfaces/header.py | 4 ++-- niworkflows/interfaces/nilearn.py | 6 +++--- niworkflows/interfaces/norm.py | 2 +- niworkflows/interfaces/patches.py | 4 ++-- niworkflows/interfaces/reportlets/base.py | 2 +- niworkflows/interfaces/reportlets/masks.py | 12 +++++------ .../interfaces/reportlets/registration.py | 20 +++++++++---------- .../interfaces/reportlets/segmentation.py | 14 ++++++------- niworkflows/interfaces/utility.py | 4 ++-- niworkflows/interfaces/workbench.py | 2 +- niworkflows/utils/bids.py | 2 +- 15 files changed, 50 insertions(+), 50 deletions(-) diff --git a/niworkflows/engine/workflows.py b/niworkflows/engine/workflows.py index 6749c386e27..9f02f3674d8 100644 --- a/niworkflows/engine/workflows.py +++ b/niworkflows/engine/workflows.py @@ -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 diff --git a/niworkflows/interfaces/bids.py b/niworkflows/interfaces/bids.py index 4dea4ec1e97..b5deeece333 100644 --- a/niworkflows/interfaces/bids.py +++ b/niworkflows/interfaces/bids.py @@ -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 @@ -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 diff --git a/niworkflows/interfaces/fixes.py b/niworkflows/interfaces/fixes.py index f0da4318bb4..f9aef937281 100644 --- a/niworkflows/interfaces/fixes.py +++ b/niworkflows/interfaces/fixes.py @@ -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 ) @@ -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 ) @@ -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 ) @@ -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 diff --git a/niworkflows/interfaces/freesurfer.py b/niworkflows/interfaces/freesurfer.py index 6d958956241..5b31360387f 100644 --- a/niworkflows/interfaces/freesurfer.py +++ b/niworkflows/interfaces/freesurfer.py @@ -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 @@ -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 @@ -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 diff --git a/niworkflows/interfaces/header.py b/niworkflows/interfaces/header.py index 739abbf0125..1be07bd0495 100644 --- a/niworkflows/interfaces/header.py +++ b/niworkflows/interfaces/header.py @@ -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: diff --git a/niworkflows/interfaces/nilearn.py b/niworkflows/interfaces/nilearn.py index ac7c62fe744..74694dd74c5 100644 --- a/niworkflows/interfaces/nilearn.py +++ b/niworkflows/interfaces/nilearn.py @@ -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 @@ -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): diff --git a/niworkflows/interfaces/norm.py b/niworkflows/interfaces/norm.py index 85115c3ec54..b45fe9e6550 100644 --- a/niworkflows/interfaces/norm.py +++ b/niworkflows/interfaces/norm.py @@ -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): """ diff --git a/niworkflows/interfaces/patches.py b/niworkflows/interfaces/patches.py index fe16ef7d197..32dcde711b7 100644 --- a/niworkflows/interfaces/patches.py +++ b/niworkflows/interfaces/patches.py @@ -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 @@ -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 diff --git a/niworkflows/interfaces/reportlets/base.py b/niworkflows/interfaces/reportlets/base.py index 10454d10aad..5915cc43789 100644 --- a/niworkflows/interfaces/reportlets/base.py +++ b/niworkflows/interfaces/reportlets/base.py @@ -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 ) diff --git a/niworkflows/interfaces/reportlets/masks.py b/niworkflows/interfaces/reportlets/masks.py index 24bf3c67d42..bac370fe280 100644 --- a/niworkflows/interfaces/reportlets/masks.py +++ b/niworkflows/interfaces/reportlets/masks.py @@ -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 @@ -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( @@ -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): @@ -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( @@ -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): @@ -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): diff --git a/niworkflows/interfaces/reportlets/registration.py b/niworkflows/interfaces/reportlets/registration.py index 374e40392b0..3da3b94ddfe 100644 --- a/niworkflows/interfaces/reportlets/registration.py +++ b/niworkflows/interfaces/reportlets/registration.py @@ -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( @@ -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( @@ -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( @@ -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): @@ -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): @@ -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( @@ -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( @@ -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): @@ -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): @@ -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) diff --git a/niworkflows/interfaces/reportlets/segmentation.py b/niworkflows/interfaces/reportlets/segmentation.py index 8a0f882471f..072c0874497 100644 --- a/niworkflows/interfaces/reportlets/segmentation.py +++ b/niworkflows/interfaces/reportlets/segmentation.py @@ -48,7 +48,7 @@ def _run_interface(self, runtime): if self.generate_report: self.inputs.segments = True - return super(FASTRPT, self)._run_interface(runtime) + return super()._run_interface(runtime) def _post_run_hook(self, runtime): """generates a report showing nine slices, three per axis, of an @@ -70,7 +70,7 @@ def _post_run_hook(self, runtime): outputs.tissue_class_files, ) - return super(FASTRPT, self)._post_run_hook(runtime) + return super()._post_run_hook(runtime) class _ReconAllInputSpecRPT( @@ -106,7 +106,7 @@ def _post_run_hook(self, runtime): "Generating report for ReconAll (subject %s)", outputs.subject_id ) - return super(ReconAllRPT, self)._post_run_hook(runtime) + return super()._post_run_hook(runtime) class _MELODICInputSpecRPT(nrb._SVGReportCapableInputSpec, fsl.model.MELODICInputSpec): @@ -133,12 +133,12 @@ class MELODICRPT(fsl.MELODIC): _out_report = None def __init__(self, generate_report=False, **kwargs): - super(MELODICRPT, self).__init__(**kwargs) + super().__init__(**kwargs) self.generate_report = generate_report def _post_run_hook(self, runtime): # Run _post_run_hook of super class - runtime = super(MELODICRPT, self)._post_run_hook(runtime) + runtime = super()._post_run_hook(runtime) # leave early if there's nothing to do if not self.generate_report: return runtime @@ -171,7 +171,7 @@ def _post_run_hook(self, runtime): def _list_outputs(self): try: - outputs = super(MELODICRPT, self)._list_outputs() + outputs = super()._list_outputs() except NotImplementedError: outputs = {} if self._out_report is not None: @@ -235,4 +235,4 @@ def _post_run_hook(self, runtime): NIWORKFLOWS_LOG.info("Generating report for ICA AROMA") - return super(ICA_AROMARPT, self)._post_run_hook(runtime) + return super()._post_run_hook(runtime) diff --git a/niworkflows/interfaces/utility.py b/niworkflows/interfaces/utility.py index a8ec3aa3289..fdca1f23a5b 100644 --- a/niworkflows/interfaces/utility.py +++ b/niworkflows/interfaces/utility.py @@ -156,7 +156,7 @@ def __init__(self, keys=None, fields=None, **inputs): """ # Call constructor - super(KeySelect, self).__init__(**inputs) + super().__init__(**inputs) # Handle and initiate fields if not fields: @@ -222,7 +222,7 @@ def _list_outputs(self): return outputs def _outputs(self): - base = super(KeySelect, self)._outputs() + base = super()._outputs() base = add_traits(base, self._fields) return base diff --git a/niworkflows/interfaces/workbench.py b/niworkflows/interfaces/workbench.py index 2ef8549e765..fb33e2e602c 100644 --- a/niworkflows/interfaces/workbench.py +++ b/niworkflows/interfaces/workbench.py @@ -296,7 +296,7 @@ def _format_arg(self, opt, spec, val): roi_out = self._gen_filename(self.inputs.in_file, suffix="_roi") iflogger.info("Setting roi output file as", roi_out) spec.argstr += " " + roi_out - return super(MetricResample, self)._format_arg(opt, spec, val) + return super()._format_arg(opt, spec, val) def _list_outputs(self): outputs = super()._list_outputs() diff --git a/niworkflows/utils/bids.py b/niworkflows/utils/bids.py index 05e74280204..658cbbd2d6a 100644 --- a/niworkflows/utils/bids.py +++ b/niworkflows/utils/bids.py @@ -42,7 +42,7 @@ def __init__(self, message, bids_root): message=message, footer="".join(["-"] * len(header)), ) - super(BIDSError, self).__init__(self.msg) + super().__init__(self.msg) self.bids_root = bids_root From c6f63173f993cb085ab4fe8dd84a819b968af67b Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Thu, 15 Jun 2023 01:01:55 +0200 Subject: [PATCH 4/4] MNT: no need to import form `__future__` We are already there! --- niworkflows/tests/test_utils.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/niworkflows/tests/test_utils.py b/niworkflows/tests/test_utils.py index cdcbbb3419a..5f69bfaa534 100644 --- a/niworkflows/tests/test_utils.py +++ b/niworkflows/tests/test_utils.py @@ -22,8 +22,6 @@ # """ Utilities tests """ -from __future__ import absolute_import, division, print_function, unicode_literals - import os from templateflow.api import get as get_template from niworkflows.interfaces.reportlets.masks import SimpleShowMaskRPT