Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0493406

Browse files
DimitriPapadopouloseffigies
andcommitted
STY: Apply ruff/pyupgrade rule UP032
UP032 Use f-string instead of `format` call Co-authored-by: Chris Markiewicz <effigies@gmail.com>
1 parent 422ce65 commit 0493406

File tree

36 files changed

+117
-298
lines changed

36 files changed

+117
-298
lines changed

‎nipype/algorithms/confounds.py‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,7 @@ def _run_interface(self, runtime):
608608

609609
if len(imgseries.shape) != 4:
610610
raise ValueError(
611-
"{} expected a 4-D nifti file. Input {} has "
612-
"{} dimensions (shape {})".format(
611+
"{} expected a 4-D nifti file. Input {} has {} dimensions (shape {})".format( # noqa: UP032
613612
self._header,
614613
self.inputs.realigned_file,
615614
len(imgseries.shape),
@@ -648,8 +647,7 @@ def _run_interface(self, runtime):
648647

649648
if TR == 0:
650649
raise ValueError(
651-
"{} cannot detect repetition time from image - "
652-
"Set the repetition_time input".format(self._header)
650+
f"{self._header} cannot detect repetition time from image - Set the repetition_time input"
653651
)
654652

655653
if isdefined(self.inputs.variance_threshold):
@@ -753,8 +751,7 @@ def _run_interface(self, runtime):
753751
f.write("\t".join(["component"] + list(metadata.keys())) + "\n")
754752
for i in zip(components_names, *metadata.values()):
755753
f.write(
756-
"{0[0]}\t{0[1]}\t{0[2]:.10f}\t"
757-
"{0[3]:.10f}\t{0[4]:.10f}\t{0[5]}\n".format(i)
754+
f"{i[0]}\t{i[1]}\t{i[2]:.10f}\t{i[3]:.10f}\t{i[4]:.10f}\t{i[5]}\n"
758755
)
759756

760757
return runtime
@@ -1398,9 +1395,7 @@ def compute_noise_components(
13981395
if imgseries.shape[:3] != mask.shape:
13991396
raise ValueError(
14001397
"Inputs for CompCor, timeseries and mask, do not have "
1401-
"matching spatial dimensions ({} and {}, respectively)".format(
1402-
imgseries.shape[:3], mask.shape
1403-
)
1398+
f"matching spatial dimensions ({imgseries.shape[:3]} and {mask.shape}, respectively)"
14041399
)
14051400

14061401
voxel_timecourses = imgseries[mask, :]

‎nipype/caching/memory.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def __call__(self, **kwargs):
8686
return out
8787

8888
def __repr__(self):
89-
return "{}({}.{}), base_dir={})".format(
89+
return "{}({}.{}), base_dir={})".format(# noqa: UP032
9090
self.__class__.__name__,
9191
self.interface.__module__,
9292
self.interface.__name__,

‎nipype/interfaces/ants/registration.py‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def _transformation_constructor(self):
204204
return "".join(retval)
205205

206206
def _regularization_constructor(self):
207-
return "--regularization {}[{},{}]".format(
207+
return "--regularization {}[{},{}]".format(# noqa: UP032
208208
self.inputs.regularization,
209209
self.inputs.regularization_gradient_field_sigma,
210210
self.inputs.regularization_deformation_field_sigma,
@@ -1242,7 +1242,7 @@ def _format_winsorize_image_intensities(self):
12421242
)
12431243
)
12441244
self._quantilesDone = True
1245-
return "--winsorize-image-intensities [ {}, {} ]".format(
1245+
return "--winsorize-image-intensities [ {}, {} ]".format(# noqa: UP032
12461246
self.inputs.winsorize_lower_quantile,
12471247
self.inputs.winsorize_upper_quantile,
12481248
)
@@ -1269,12 +1269,12 @@ def _get_initial_transform_filenames(self):
12691269
def _format_arg(self, opt, spec, val):
12701270
if opt == "fixed_image_mask":
12711271
if isdefined(self.inputs.moving_image_mask):
1272-
return "--masks [ {}, {} ]".format(
1272+
return "--masks [ {}, {} ]".format(# noqa: UP032
12731273
self.inputs.fixed_image_mask,
12741274
self.inputs.moving_image_mask,
12751275
)
12761276
else:
1277-
return "--masks %s"%self.inputs.fixed_image_mask
1277+
return "--masks {}".format(self.inputs.fixed_image_mask) # noqa: UP032
12781278
elif opt == "transforms":
12791279
return self._format_registration()
12801280
elif opt == "initial_moving_transform":
@@ -1309,18 +1309,20 @@ def _format_arg(self, opt, spec, val):
13091309
out_filename = self._get_outputfilenames(inverse=False)
13101310
inv_out_filename = self._get_outputfilenames(inverse=True)
13111311
if out_filename and inv_out_filename:
1312-
return "--output [ {}, {}, {} ]".format(
1312+
return "--output [ {}, {}, {} ]".format(# noqa: UP032
13131313
self.inputs.output_transform_prefix,
13141314
out_filename,
13151315
inv_out_filename,
13161316
)
13171317
elif out_filename:
1318-
return "--output [ {}, {} ]".format(
1318+
return "--output [ {}, {} ]".format(# noqa: UP032
13191319
self.inputs.output_transform_prefix,
13201320
out_filename,
13211321
)
13221322
else:
1323-
return "--output %s" % self.inputs.output_transform_prefix
1323+
return "--output {}".format( # noqa: UP032
1324+
self.inputs.output_transform_prefix,
1325+
)
13241326
elif opt == "winsorize_upper_quantile" or opt == "winsorize_lower_quantile":
13251327
if not self._quantilesDone:
13261328
return self._format_winsorize_image_intensities()
@@ -1591,7 +1593,7 @@ class MeasureImageSimilarity(ANTSCommand):
15911593
def _metric_constructor(self):
15921594
retval = (
15931595
'--metric {metric}["{fixed_image}","{moving_image}",{metric_weight},'
1594-
"{radius_or_number_of_bins},{sampling_strategy},{sampling_percentage}]".format(
1596+
"{radius_or_number_of_bins},{sampling_strategy},{sampling_percentage}]".format(# noqa: UP032
15951597
metric=self.inputs.metric,
15961598
fixed_image=self.inputs.fixed_image,
15971599
moving_image=self.inputs.moving_image,
@@ -1605,13 +1607,13 @@ def _metric_constructor(self):
16051607

16061608
def _mask_constructor(self):
16071609
if self.inputs.moving_image_mask:
1608-
retval = '--masks ["{fixed_image_mask}","{moving_image_mask}"]'.format(
1610+
retval = '--masks ["{fixed_image_mask}","{moving_image_mask}"]'.format(# noqa: UP032
16091611
fixed_image_mask=self.inputs.fixed_image_mask,
16101612
moving_image_mask=self.inputs.moving_image_mask,
16111613
)
16121614
else:
1613-
retval = '--masks "{fixed_image_mask}"'.format(
1614-
fixed_image_mask=self.inputs.fixed_image_mask
1615+
retval = '--masks "{}"'.format(# noqa: UP032
1616+
fixed_image_mask=self.inputs.fixed_image_mask,
16151617
)
16161618
return retval
16171619

@@ -1871,9 +1873,7 @@ def _list_outputs(self):
18711873
f"00_{self.inputs.output_prefix}_AffineTransform.mat"
18721874
)
18731875
outputs["displacement_field"] = os.path.abspath(
1874-
"01_{}_DisplacementFieldTransform.nii.gz".format(
1875-
self.inputs.output_prefix
1876-
)
1876+
f"01_{self.inputs.output_prefix}_DisplacementFieldTransform.nii.gz"
18771877
)
18781878
if self.inputs.process == "assemble":
18791879
outputs["out_file"] = os.path.abspath(self.inputs.out_file)

‎nipype/interfaces/base/core.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,8 +849,8 @@ def _filename_from_source(self, name, chain=None):
849849

850850
if not isinstance(ns, (str, bytes)):
851851
raise ValueError(
852-
"name_source of '{}' trait should be an input trait "
853-
"name, but a type {} object was found".format(name, type(ns))
852+
f"name_source of '{name}' trait should be an input trait "
853+
f"name, but a type {type(ns)} object was found"
854854
)
855855

856856
if isdefined(getattr(self.inputs, ns)):

‎nipype/interfaces/base/specs.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,7 @@ def _deprecated_warn(self, obj, name, old, new):
141141
raise TraitError(msg)
142142
else:
143143
if trait_spec.new_name:
144-
msg += "Unsetting old value {}; setting new value {}.".format(
145-
name,
146-
trait_spec.new_name,
147-
)
144+
msg += f"Unsetting old value {name}; setting new value {trait_spec.new_name}."
148145
warn(msg)
149146
if trait_spec.new_name:
150147
self.trait_set(

‎nipype/interfaces/cmtk/parcellation.py‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -315,15 +315,10 @@ def create_annot_label(subject_id, subjects_dir, fs_dir, parcellation_name):
315315
)
316316
runCmd(mri_cmd, log)
317317
runCmd("mris_volmask %s" % subject_id, log)
318-
mri_cmd = 'mri_convert -i "{}/mri/ribbon.mgz" -o "{}/mri/ribbon.nii.gz"'.format(
319-
op.join(subjects_dir, subject_id),
320-
op.join(subjects_dir, subject_id),
321-
)
318+
subject_path = op.join(subjects_dir, subject_id)
319+
mri_cmd = f'mri_convert -i "{subject_path}/mri/ribbon.mgz" -o "{subject_path}/mri/ribbon.nii.gz"'
322320
runCmd(mri_cmd, log)
323-
mri_cmd = 'mri_convert -i "{}/mri/aseg.mgz" -o "{}/mri/aseg.nii.gz"'.format(
324-
op.join(subjects_dir, subject_id),
325-
op.join(subjects_dir, subject_id),
326-
)
321+
mri_cmd = f'mri_convert -i "{subject_path}/mri/aseg.mgz" -o "{subject_path}/mri/aseg.nii.gz"'
327322
runCmd(mri_cmd, log)
328323

329324
iflogger.info("[ DONE ]")

‎nipype/interfaces/dtitk/base.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ def __init__(self, *args, **kwargs):
4242
rename_idx = classes.index("DTITKRenameMixin")
4343
new_name = classes[rename_idx + 1]
4444
warnings.warn(
45-
"The {} interface has been renamed to {}\n"
45+
f"The {dep_name} interface has been renamed to {new_name}\n"
4646
"Please see the documentation for DTI-TK "
4747
"interfaces, as some inputs have been "
48-
"added or renamed for clarity."
49-
"".format(dep_name, new_name),
48+
"added or renamed for clarity.",
5049
DeprecationWarning,
5150
)
5251
super().__init__(*args, **kwargs)

‎nipype/interfaces/freesurfer/preprocess.py‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -729,10 +729,7 @@ def cmdline(self):
729729
outdir = self._get_outdir()
730730
cmd = []
731731
if not os.path.exists(outdir):
732-
cmdstr = "{} -c \"import os; os.makedirs('{}')\"".format(
733-
op.basename(sys.executable),
734-
outdir,
735-
)
732+
cmdstr = f"{op.basename(sys.executable)} -c \"import os; os.makedirs('{outdir}')\""
736733
cmd.extend([cmdstr])
737734
infofile = os.path.join(outdir, "shortinfo.txt")
738735
if not os.path.exists(infofile):
@@ -741,12 +738,7 @@ def cmdline(self):
741738
files = self._get_filelist(outdir)
742739
for infile, outfile in files:
743740
if not os.path.exists(outfile):
744-
single_cmd = "{}{} {} {}".format(
745-
self._cmd_prefix,
746-
self.cmd,
747-
infile,
748-
os.path.join(outdir, outfile),
749-
)
741+
single_cmd = f"{self._cmd_prefix}{self.cmd} {infile} {os.path.join(outdir, outfile)}"
750742
cmd.extend([single_cmd])
751743
return "; ".join(cmd)
752744

‎nipype/interfaces/freesurfer/tests/test_preprocess.py‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@ def test_fitmsparams(create_files_in_directory):
6565
# .inputs based parameters setting
6666
fit.inputs.in_files = filelist
6767
fit.inputs.out_dir = outdir
68-
assert fit.cmdline == "mri_ms_fitparms {} {} {}".format(
69-
filelist[0],
70-
filelist[1],
71-
outdir,
72-
)
68+
assert fit.cmdline == f"mri_ms_fitparms {filelist[0]} {filelist[1]} {outdir}"
7369

7470
# constructor based parameter setting
7571
fit2 = freesurfer.FitMSParams(
@@ -184,9 +180,7 @@ def test_bbregister(create_files_in_directory):
184180
base, _ = os.path.splitext(base)
185181

186182
assert bbr.cmdline == (
187-
"bbregister --t2 --init-fsl "
188-
"--reg {base}_bbreg_fsaverage.dat "
189-
"--mov {full} --s fsaverage".format(full=filelist[0], base=base)
183+
f"bbregister --t2 --init-fsl --reg {base}_bbreg_fsaverage.dat --mov {filelist[0]} --s fsaverage"
190184
)
191185

192186

‎nipype/interfaces/freesurfer/tests/test_utils.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,7 @@ def test_mrisexpand(tmpdir):
210210
nd_res = expand_nd.run()
211211

212212
# Commandlines differ
213-
node_cmdline = (
214-
"mris_expand -T 60 -pial {cwd}/lh.pial {cwd}/lh.smoothwm "
215-
"1 expandtmp".format(cwd=nd_res.runtime.cwd)
216-
)
213+
node_cmdline = f"mris_expand -T 60 -pial {nd_res.runtime.cwd}/lh.pial {nd_res.runtime.cwd}/lh.smoothwm 1 expandtmp"
217214
assert nd_res.runtime.cmdline == node_cmdline
218215

219216
# Check output

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /