Skip to content

Commit 5079243

Browse files
STY: Apply ruff/flynt rule FLY002
FLY002 Consider f-string instead of string join
1 parent e03ab6f commit 5079243

30 files changed

+52
-63
lines changed

Diff for: nipype/algorithms/rapidart.py

+8-14
Original file line numberDiff line numberDiff line change
@@ -397,19 +397,13 @@ def _get_output_filenames(self, motionfile, output_dir):
397397
else:
398398
raise Exception("Unknown type of file")
399399
_, filename, ext = split_filename(infile)
400-
artifactfile = os.path.join(
401-
output_dir, "".join(("art.", filename, "_outliers.txt"))
402-
)
403-
intensityfile = os.path.join(
404-
output_dir, "".join(("global_intensity.", filename, ".txt"))
405-
)
406-
statsfile = os.path.join(output_dir, "".join(("stats.", filename, ".txt")))
407-
normfile = os.path.join(output_dir, "".join(("norm.", filename, ".txt")))
408-
plotfile = os.path.join(
409-
output_dir, "".join(("plot.", filename, ".", self.inputs.plot_type))
410-
)
411-
displacementfile = os.path.join(output_dir, "".join(("disp.", filename, ext)))
412-
maskfile = os.path.join(output_dir, "".join(("mask.", filename, ext)))
400+
artifactfile = os.path.join(output_dir, f"art.{filename}_outliers.txt")
401+
intensityfile = os.path.join(output_dir, f"global_intensity.{filename}.txt")
402+
statsfile = os.path.join(output_dir, f"stats.{filename}.txt")
403+
normfile = os.path.join(output_dir, f"norm.{filename}.txt")
404+
plotfile = os.path.join(output_dir, f"plot.{filename}.{self.inputs.plot_type}")
405+
displacementfile = os.path.join(output_dir, f"disp.{filename}{ext}")
406+
maskfile = os.path.join(output_dir, f"mask.{filename}{ext}")
413407
return (
414408
artifactfile,
415409
intensityfile,
@@ -760,7 +754,7 @@ def _get_output_filenames(self, motionfile, output_dir):
760754
"""
761755
(_, filename) = os.path.split(motionfile)
762756
(filename, _) = os.path.splitext(filename)
763-
corrfile = os.path.join(output_dir, "".join(("qa.", filename, "_stimcorr.txt")))
757+
corrfile = os.path.join(output_dir, f"qa.{filename}_stimcorr.txt")
764758
return corrfile
765759

766760
def _stimcorr_core(self, motionfile, intensityfile, designmatrix, cwd=None):

Diff for: nipype/interfaces/afni/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def _gen_fname(self, basename, cwd=None, suffix=None, change_ext=True, ext=None)
292292
if ext is None:
293293
ext = Info.output_type_to_ext(self.inputs.outputtype)
294294
if change_ext:
295-
suffix = "".join((suffix, ext)) if suffix else ext
295+
suffix = f"{suffix}{ext}" if suffix else ext
296296

297297
if suffix is None:
298298
suffix = ""

Diff for: nipype/interfaces/ants/resampling.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def _list_outputs(self):
134134
outputs = self._outputs().get()
135135
_, name, ext = split_filename(os.path.abspath(self.inputs.input_image))
136136
outputs["output_image"] = os.path.join(
137-
os.getcwd(), "".join((name, self.inputs.out_postfix, ext))
137+
os.getcwd(), f"{name}{self.inputs.out_postfix}{ext}"
138138
)
139139
return outputs
140140

@@ -254,7 +254,7 @@ class WarpImageMultiTransform(ANTSCommand):
254254
def _gen_filename(self, name):
255255
if name == "output_image":
256256
_, name, ext = split_filename(os.path.abspath(self.inputs.input_image))
257-
return "".join((name, self.inputs.out_postfix, ext))
257+
return f"{name}{self.inputs.out_postfix}{ext}"
258258
return None
259259

260260
def _format_arg(self, opt, spec, val):

Diff for: nipype/interfaces/base/core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ def version_from_command(self, flag="-v", cmd=None):
709709
out_environ = self._get_environ()
710710
env.update(out_environ)
711711
proc = sp.Popen(
712-
" ".join((cmd, flag)),
712+
f"{cmd} {flag}",
713713
shell=True,
714714
env=canonicalize_env(env),
715715
stdout=sp.PIPE,

Diff for: nipype/interfaces/base/specs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def _deprecated_warn(self, obj, name, old, new):
136136
msg3 = "It has been replaced by %s." % trait_spec.new_name
137137
else:
138138
msg3 = ""
139-
msg = " ".join((msg1, msg2, msg3))
139+
msg = f"{msg1} {msg2} {msg3}"
140140
if Version(str(trait_spec.deprecated)) < self.package_version:
141141
raise TraitError(msg)
142142
else:

Diff for: nipype/interfaces/brainsuite/brainsuite.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1801,7 +1801,7 @@ def getFileName(inputName, suffix):
18011801
dotRegex = regex.compile("[^.]+")
18021802
# extract between last slash and first period
18031803
inputNoExtension = dotRegex.findall(fullInput)[0]
1804-
return os.path.abspath("".join((inputNoExtension, suffix)))
1804+
return os.path.abspath(f"{inputNoExtension}{suffix}")
18051805

18061806

18071807
def l_outputs(self):

Diff for: nipype/interfaces/cat12/surface.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ def _list_outputs(self):
145145
outputs[name_hemisphere] = []
146146
if not isdefined(outputs[all_files_hemisphere]):
147147
outputs[all_files_hemisphere] = []
148-
generated_filename = ".".join(
149-
[hemisphere, parameter_name, original_filename]
148+
generated_filename = (
149+
f"{hemisphere}.{parameter_name}.{original_filename}"
150150
)
151151
outputs[name_hemisphere].append(
152152
os.path.join(pth, generated_filename)

Diff for: nipype/interfaces/dtitk/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def _gen_fname(self, basename, cwd=None, suffix=None, change_ext=True, ext=None)
8989
ext = Info.output_type_to_ext(self.inputs.output_type)
9090
if change_ext:
9191
if suffix:
92-
suffix = "".join((suffix, ext))
92+
suffix = f"{suffix}{ext}"
9393
else:
9494
suffix = ext
9595
if suffix is None:

Diff for: nipype/interfaces/freesurfer/model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ def _list_outputs(self):
674674
outfile = fname_presuffix(
675675
self.inputs.in_file,
676676
newpath=os.getcwd(),
677-
suffix=".".join(("_thresh", self.inputs.out_type)),
677+
suffix=f"_thresh.{self.inputs.out_type}",
678678
use_ext=False,
679679
)
680680
else:

Diff for: nipype/interfaces/freesurfer/preprocess.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2541,7 +2541,7 @@ def _format_arg(self, name, spec, value):
25412541
cmd = " ".join((cmd, "-fa %.1f" % self.inputs.flip_list[i]))
25422542
if isdefined(self.inputs.xfm_list):
25432543
cmd = " ".join((cmd, "-at %s" % self.inputs.xfm_list[i]))
2544-
cmd = " ".join((cmd, file))
2544+
cmd = f"{cmd} {file}"
25452545
return cmd
25462546
return super()._format_arg(name, spec, value)
25472547

Diff for: nipype/interfaces/fsl/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def _gen_fname(self, basename, cwd=None, suffix=None, change_ext=True, ext=None)
237237
ext = Info.output_type_to_ext(self.inputs.output_type)
238238
if change_ext:
239239
if suffix:
240-
suffix = "".join((suffix, ext))
240+
suffix = f"{suffix}{ext}"
241241
else:
242242
suffix = ext
243243
if suffix is None:

Diff for: nipype/interfaces/fsl/tests/test_preprocess.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -306,21 +306,21 @@ def test_flirt(setup_flirt):
306306
# Handle autogeneration of outfile
307307
pth, fname, ext = split_filename(infile)
308308
outfile = fsl_name(fsl.FLIRT(), "%s_flirt" % fname)
309-
outfile = " ".join(["-out", outfile])
309+
outfile = f"-out {outfile}"
310310
# Handle autogeneration of outmatrix
311311
outmatrix = "%s_flirt.mat" % fname
312-
outmatrix = " ".join(["-omat", outmatrix])
312+
outmatrix = f"-omat {outmatrix}"
313313
# Build command line
314-
cmdline = " ".join([cmdline, outfile, outmatrix, param])
314+
cmdline = f"{cmdline} {outfile} {outmatrix} {param}"
315315
flirter = fsl.FLIRT(in_file=infile, reference=reffile)
316316
setattr(flirter.inputs, key, value)
317317
assert flirter.cmdline == cmdline
318318

319319
# Test OutputSpec
320320
flirter = fsl.FLIRT(in_file=infile, reference=reffile)
321321
pth, fname, ext = split_filename(infile)
322-
flirter.inputs.out_file = "".join(["foo", ext])
323-
flirter.inputs.out_matrix_file = "".join(["bar", ext])
322+
flirter.inputs.out_file = f"foo{ext}"
323+
flirter.inputs.out_matrix_file = f"bar{ext}"
324324
outs = flirter._list_outputs()
325325
assert outs["out_file"] == os.path.join(os.getcwd(), flirter.inputs.out_file)
326326
assert outs["out_matrix_file"] == os.path.join(

Diff for: nipype/interfaces/io.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1821,7 +1821,7 @@ def _get_files(self, path, key, dirval, altkey=None):
18211821
else:
18221822
globprefix = "*"
18231823
keys = ensure_list(altkey) if altkey else [key]
1824-
globfmt = os.path.join(path, dirval, "".join((globprefix, "{}", globsuffix)))
1824+
globfmt = os.path.join(path, dirval, f"{globprefix}{{}}{globsuffix}")
18251825
return [
18261826
os.path.abspath(f) for key in keys for f in glob.glob(globfmt.format(key))
18271827
]

Diff for: nipype/interfaces/mne/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def _get_files(self, path, key, dirval, altkey=None):
112112
keydir = op.join(path, dirval)
113113
if altkey:
114114
key = altkey
115-
globpattern = op.join(keydir, "".join((globprefix, key, globsuffix)))
115+
globpattern = op.join(keydir, f"{globprefix}{key}{globsuffix}")
116116
return glob.glob(globpattern)
117117

118118
def _list_outputs(self):

Diff for: nipype/interfaces/niftyfit/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ def _gen_fname(self, basename, out_dir=None, suffix=None, ext=None):
4545
if ext is not None:
4646
final_ext = ext
4747
if suffix is not None:
48-
final_bn = "".join((final_bn, suffix))
48+
final_bn = f"{final_bn}{suffix}"
4949
return os.path.abspath(os.path.join(out_dir, final_bn + final_ext))

Diff for: nipype/interfaces/niftyreg/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,5 @@ def _gen_fname(self, basename, out_dir=None, suffix=None, ext=None):
132132
if ext is not None:
133133
final_ext = ext
134134
if suffix is not None:
135-
final_bn = "".join((final_bn, suffix))
135+
final_bn = f"{final_bn}{suffix}"
136136
return os.path.abspath(os.path.join(out_dir, final_bn + final_ext))

Diff for: nipype/interfaces/petpvc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def _gen_fname(
225225
cwd = os.getcwd()
226226
if change_ext:
227227
if suffix:
228-
suffix = "".join((suffix, ext))
228+
suffix = f"{suffix}{ext}"
229229
else:
230230
suffix = ext
231231
if suffix is None:

Diff for: nipype/interfaces/spm/preprocess.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ def _list_outputs(self):
12631263
outputs["normalized_source"] = self.inputs.source
12641264
elif "write" in self.inputs.jobtype:
12651265
if isdefined(self.inputs.write_preserve) and self.inputs.write_preserve:
1266-
prefixNorm = "".join(["m", self.inputs.out_prefix])
1266+
prefixNorm = f"m{self.inputs.out_prefix}"
12671267
else:
12681268
prefixNorm = self.inputs.out_prefix
12691269
outputs["normalized_files"] = []

Diff for: nipype/pipeline/engine/utils.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,9 @@ def get_print_name(node, simple_form=True):
457457
if len(pkglist) > 2:
458458
destclass = ".%s" % pkglist[2]
459459
if simple_form:
460-
name = node.fullname + destclass
460+
name = f"{node.fullname}{destclass}"
461461
else:
462-
name = ".".join([node.fullname, interface]) + destclass
462+
name = f"{node.fullname}.{interface}{destclass}"
463463
if simple_form:
464464
parts = name.split(".")
465465
if len(parts) > 2:
@@ -1565,7 +1565,7 @@ def write_workflow_prov(graph, filename=None, format="all"):
15651565
_, hashval, _, _ = node.hash_exists()
15661566
attrs = {
15671567
pm.PROV["type"]: nipype_ns[classname],
1568-
pm.PROV["label"]: "_".join((classname, node.name)),
1568+
pm.PROV["label"]: f"{classname}_{node.name}",
15691569
nipype_ns["hashval"]: hashval,
15701570
}
15711571
process = ps.g.activity(get_id(), None, None, attrs)

Diff for: nipype/pipeline/engine/workflows.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,7 @@ def list_node_names(self):
394394
for node in nx.topological_sort(self._graph):
395395
if isinstance(node, Workflow):
396396
outlist.extend(
397-
[
398-
".".join((node.name, nodename))
399-
for nodename in node.list_node_names()
400-
]
397+
f"{node.name}.{nodename}" for nodename in node.list_node_names()
401398
)
402399
else:
403400
outlist.append(node.name)
@@ -931,7 +928,7 @@ def _reset_hierarchy(self):
931928
if isinstance(node, Workflow):
932929
node._reset_hierarchy()
933930
for innernode in node._graph.nodes():
934-
innernode._hierarchy = ".".join((self.name, innernode._hierarchy))
931+
innernode._hierarchy = f"{self.name}.{innernode._hierarchy}"
935932
else:
936933
node._hierarchy = self.name
937934

@@ -995,7 +992,7 @@ def _generate_flatgraph(self):
995992
# logger.debug('expanding workflow: %s', node)
996993
node._generate_flatgraph()
997994
for innernode in node._graph.nodes():
998-
innernode._hierarchy = ".".join((self.name, innernode._hierarchy))
995+
innernode._hierarchy = f"{self.name}.{innernode._hierarchy}"
999996
self._graph.add_nodes_from(node._graph.nodes())
1000997
self._graph.add_edges_from(node._graph.edges(data=True))
1001998
if nodes2remove:

Diff for: nipype/pipeline/plugins/tests/test_legacymultiproc_nondaemon.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def run_multiproc_nondaemon_with_flag(nondaemon_flag):
122122
plugin_args={"n_procs": 2, "non_daemon": nondaemon_flag},
123123
)
124124

125-
names = [".".join((node._hierarchy, node.name)) for node in execgraph.nodes()]
125+
names = [f"{node._hierarchy}.{node.name}" for node in execgraph.nodes()]
126126
node = list(execgraph.nodes())[names.index("pipe.f2")]
127127
result = node.get_output("sum_out")
128128
os.chdir(cur_dir)

Diff for: nipype/pipeline/plugins/tests/test_linear.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_run_in_series(tmpdir):
3939
pipe.base_dir = os.getcwd()
4040
mod1.inputs.input1 = 1
4141
execgraph = pipe.run(plugin="Linear")
42-
names = [".".join((node._hierarchy, node.name)) for node in execgraph.nodes()]
42+
names = [f"{node._hierarchy}.{node.name}" for node in execgraph.nodes()]
4343
node = list(execgraph.nodes())[names.index("pipe.mod1")]
4444
result = node.get_output("output1")
4545
assert result == [1, 1]

Diff for: nipype/pipeline/plugins/tests/test_oar.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_run_oargraph(tmp_path):
3838
pipe.base_dir = os.getcwd()
3939
mod1.inputs.input1 = 1
4040
execgraph = pipe.run(plugin="OAR")
41-
names = [".".join((node._hierarchy, node.name)) for node in execgraph.nodes()]
41+
names = [f"{node._hierarchy}.{node.name}" for node in execgraph.nodes()]
4242
node = list(execgraph.nodes())[names.index("pipe.mod1")]
4343
result = node.get_output("output1")
4444
assert result == [1, 1]

Diff for: nipype/pipeline/plugins/tests/test_pbs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_run_pbsgraph(tmp_path):
3737
pipe.connect([(mod1, mod2, [("output1", "input1")])])
3838
mod1.inputs.input1 = 1
3939
execgraph = pipe.run(plugin="PBSGraph")
40-
names = [".".join((node._hierarchy, node.name)) for node in execgraph.nodes()]
40+
names = [f"{node._hierarchy}.{node.name}" for node in execgraph.nodes()]
4141
node = list(execgraph.nodes())[names.index("pipe.mod1")]
4242
result = node.get_output("output1")
4343
assert result == [1, 1]

Diff for: nipype/pipeline/plugins/tests/test_somaflow.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_run_somaflow(tmpdir):
4242
pipe.base_dir = os.getcwd()
4343
mod1.inputs.input1 = 1
4444
execgraph = pipe.run(plugin="SomaFlow")
45-
names = [".".join((node._hierarchy, node.name)) for node in execgraph.nodes()]
45+
names = [f"{node._hierarchy}.{node.name}" for node in execgraph.nodes()]
4646
node = list(execgraph.nodes())[names.index("pipe.mod1")]
4747
result = node.get_output("output1")
4848
assert result == [1, 1]

Diff for: nipype/pipeline/plugins/tools.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,8 @@ def report_nodes_not_run(notrun):
8383
if notrun:
8484
logger.info("***********************************")
8585
for info in notrun:
86-
logger.error(
87-
"could not run node: %s"
88-
% ".".join((info["node"]._hierarchy, info["node"]._id))
89-
)
86+
node = info["node"]
87+
logger.error(f"could not run node: {node._hierarchy}.{node._id}")
9088
logger.info("crashfile: %s" % info["crashfile"])
9189
logger.debug("The following dependent nodes were not run")
9290
for subnode in info["dependents"]:

Diff for: nipype/utils/docparse.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def format_params(paramlist, otherlist=None):
118118
otherlist.insert(0, hdr)
119119
otherlist.insert(0, "\n")
120120
otherparams = "\n".join(otherlist)
121-
doc = "".join([doc, otherparams])
121+
doc = f"{doc}{otherparams}"
122122
return doc
123123

124124

@@ -251,7 +251,7 @@ def get_doc(cmd, opt_map, help_flag=None, trap_error=True):
251251
if cmd_path == "":
252252
raise Exception("Command %s not found" % cmd.split(" ")[0])
253253
if help_flag:
254-
cmd = " ".join((cmd, help_flag))
254+
cmd = f"{cmd} {help_flag}"
255255
doc = grab_doc(cmd, trap_error)
256256
opts = reverse_opt_map(opt_map)
257257
return build_doc(doc, opts)
@@ -332,7 +332,7 @@ def get_params_from_doc(cmd, style="--", help_flag=None, trap_error=True):
332332
if cmd_path == "":
333333
raise Exception("Command %s not found" % cmd.split(" ")[0])
334334
if help_flag:
335-
cmd = " ".join((cmd, help_flag))
335+
cmd = f"{cmd} {help_flag}"
336336
doc = grab_doc(cmd, trap_error)
337337
return _parse_doc(doc, style)
338338

Diff for: nipype/utils/filemanip.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def hash_rename(filename, hashvalue):
137137
and sets path to output_directory
138138
"""
139139
path, name, ext = split_filename(filename)
140-
newfilename = "".join((name, "_0x", hashvalue, ext))
140+
newfilename = f"{name}_0x{hashvalue}{ext}"
141141
return op.join(path, newfilename)
142142

143143

Diff for: nipype/utils/tests/test_filemanip.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_hash_rename(filename, newname):
8787
def test_check_forhash():
8888
fname = "foobar"
8989
orig_hash = "_0x4323dbcefdc51906decd8edcb3327943"
90-
hashed_name = "".join((fname, orig_hash, ".nii"))
90+
hashed_name = f"{fname}{orig_hash}.nii"
9191
result, hash = check_forhash(hashed_name)
9292
assert result
9393
assert hash == [orig_hash]

Diff for: tools/checkspecs.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def _parse_lines(self, linesource, module):
143143
# exclude private stuff
144144
name = self._get_object_name(line)
145145
if not name.startswith("_") and self._survives_exclude(
146-
".".join((module, name)), "class"
146+
f"{module}.{name}", "class"
147147
):
148148
classes.append(name)
149149
else:
@@ -449,7 +449,7 @@ def discover_modules(self):
449449
# Check directory names for packages
450450
root_uri = self._path2uri(os.path.join(self.root_path, dirpath))
451451
for dirname in dirnames[:]: # copy list - we modify inplace
452-
package_uri = ".".join((root_uri, dirname))
452+
package_uri = f"{root_uri}.{dirname}"
453453
if self._uri2path(package_uri) and self._survives_exclude(
454454
package_uri, "package"
455455
):
@@ -459,7 +459,7 @@ def discover_modules(self):
459459
# Check filenames for modules
460460
for filename in filenames:
461461
module_name = filename[:-3]
462-
module_uri = ".".join((root_uri, module_name))
462+
module_uri = f"{root_uri}.{module_name}"
463463
if self._uri2path(module_uri) and self._survives_exclude(
464464
module_uri, "module"
465465
):

0 commit comments

Comments
 (0)