Skip to content

Commit 9f9b27a

Browse files
committed
STY: Replace {str(x)} with {x} in f-strings
1 parent f067a03 commit 9f9b27a

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

pydra/engine/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ def _collect_outputs(self):
12311231
err_file = getattr(self, val.name).output_dir / "_error.pklz"
12321232
raise ValueError(
12331233
f"Task {val.name} raised an error, full crash report is here: "
1234-
f"{str(err_file)}"
1234+
f"{err_file}"
12351235
)
12361236
return attr.evolve(output, **output_wf)
12371237

pydra/engine/tests/test_shelltask_inputspec.py

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ def test_shell_cmd_inputs_template_1():
770770
)
771771
# outA has argstr in the metadata fields, so it's a part of the command line
772772
# the full path will be use din the command line
773-
assert shelly.cmdline == f"executable inpA -o {str(shelly.output_dir / 'inpA_out')}"
773+
assert shelly.cmdline == f"executable inpA -o {shelly.output_dir / 'inpA_out'}"
774774
# checking if outA in the output fields
775775
assert shelly.output_names == ["return_code", "stdout", "stderr", "outA"]
776776

@@ -922,7 +922,7 @@ def test_shell_cmd_inputs_template_3():
922922
# using syntax from the outAB field
923923
assert (
924924
shelly.cmdline
925-
== f"executable inpA inpB -o {str(shelly.output_dir / 'inpA_out')} {str(shelly.output_dir / 'inpB_out')}"
925+
== f"executable inpA inpB -o {shelly.output_dir / 'inpA_out'} {str(shelly.output_dir / 'inpB_out')}"
926926
)
927927
# checking if outA and outB in the output fields (outAB should not be)
928928
assert shelly.output_names == ["return_code", "stdout", "stderr", "outA", "outB"]
@@ -1002,7 +1002,7 @@ def test_shell_cmd_inputs_template_3a():
10021002
# using syntax from the outAB field
10031003
assert (
10041004
shelly.cmdline
1005-
== f"executable inpA inpB -o {str(shelly.output_dir / 'inpA_out')} {str(shelly.output_dir / 'inpB_out')}"
1005+
== f"executable inpA inpB -o {shelly.output_dir / 'inpA_out'} {str(shelly.output_dir / 'inpB_out')}"
10061006
)
10071007
# checking if outA and outB in the output fields (outAB should not be)
10081008
assert shelly.output_names == ["return_code", "stdout", "stderr", "outA", "outB"]
@@ -1076,7 +1076,7 @@ def test_shell_cmd_inputs_template_4():
10761076
executable="executable", input_spec=my_input_spec, inpA="inpA"
10771077
)
10781078
# inpB is not provided so outB not in the command line
1079-
assert shelly.cmdline == f"executable inpA -o {str(shelly.output_dir / 'inpA_out')}"
1079+
assert shelly.cmdline == f"executable inpA -o {shelly.output_dir / 'inpA_out'}"
10801080
assert shelly.output_names == ["return_code", "stdout", "stderr", "outA", "outB"]
10811081

10821082

@@ -1151,7 +1151,7 @@ def test_shell_cmd_inputs_template_6():
11511151
shelly = ShellCommandTask(
11521152
executable="executable", input_spec=my_input_spec, inpA="inpA"
11531153
)
1154-
assert shelly.cmdline == f"executable inpA -o {str(shelly.output_dir / 'inpA_out')}"
1154+
assert shelly.cmdline == f"executable inpA -o {shelly.output_dir / 'inpA_out'}"
11551155

11561156
# a string is provided for outA, so this should be used as the outA value
11571157
shelly = ShellCommandTask(
@@ -1163,7 +1163,7 @@ def test_shell_cmd_inputs_template_6():
11631163
shelly = ShellCommandTask(
11641164
executable="executable", input_spec=my_input_spec, inpA="inpA", outA=True
11651165
)
1166-
assert shelly.cmdline == f"executable inpA -o {str(shelly.output_dir / 'inpA_out')}"
1166+
assert shelly.cmdline == f"executable inpA -o {shelly.output_dir / 'inpA_out'}"
11671167

11681168
# False is provided for outA, so the outA shouldn't be used
11691169
shelly = ShellCommandTask(
@@ -1225,7 +1225,7 @@ def test_shell_cmd_inputs_template_6a():
12251225
shelly = ShellCommandTask(
12261226
executable="executable", input_spec=my_input_spec, inpA="inpA", outA=True
12271227
)
1228-
assert shelly.cmdline == f"executable inpA -o {str(shelly.output_dir / 'inpA_out')}"
1228+
assert shelly.cmdline == f"executable inpA -o {shelly.output_dir / 'inpA_out'}"
12291229

12301230
# False is provided for outA, so the outA shouldn't be used
12311231
shelly = ShellCommandTask(
@@ -1278,7 +1278,7 @@ def test_shell_cmd_inputs_template_7(tmpdir):
12781278
# outA should be formatted in a way that that .txt goes to the end
12791279
assert (
12801280
shelly.cmdline
1281-
== f"executable {tmpdir.join('a_file.txt')} {str(shelly.output_dir / 'a_file_out.txt')}"
1281+
== f"executable {tmpdir.join('a_file.txt')} {shelly.output_dir / 'a_file_out.txt'}"
12821282
)
12831283

12841284

@@ -1327,7 +1327,7 @@ def test_shell_cmd_inputs_template_7a(tmpdir):
13271327
# outA should be formatted in a way that that .txt goes to the end
13281328
assert (
13291329
shelly.cmdline
1330-
== f"executable {tmpdir.join('a_file.txt')} {str(shelly.output_dir / 'a_file_out.txt')}"
1330+
== f"executable {tmpdir.join('a_file.txt')} {shelly.output_dir / 'a_file_out.txt'}"
13311331
)
13321332

13331333

@@ -1376,7 +1376,7 @@ def test_shell_cmd_inputs_template_7b(tmpdir):
13761376
# outA should be formatted in a way that that .txt goes to the end
13771377
assert (
13781378
shelly.cmdline
1379-
== f"executable {tmpdir.join('a_file.txt')} {str(shelly.output_dir / 'a_file_out')}"
1379+
== f"executable {tmpdir.join('a_file.txt')} {shelly.output_dir / 'a_file_out'}"
13801380
)
13811381

13821382

@@ -1422,7 +1422,7 @@ def test_shell_cmd_inputs_template_8(tmpdir):
14221422
# outA should be formatted in a way that inpA extension is removed and the template extension is used
14231423
assert (
14241424
shelly.cmdline
1425-
== f"executable {tmpdir.join('a_file.t')} {str(shelly.output_dir / 'a_file_out.txt')}"
1425+
== f"executable {tmpdir.join('a_file.t')} {shelly.output_dir / 'a_file_out.txt'}"
14261426
)
14271427

14281428

@@ -1482,7 +1482,7 @@ def test_shell_cmd_inputs_template_9(tmpdir):
14821482

14831483
assert (
14841484
shelly.cmdline
1485-
== f"executable {tmpdir.join('inpA.t')} -i 3 -o {str(shelly.output_dir / 'inpA_3_out.txt')}"
1485+
== f"executable {tmpdir.join('inpA.t')} -i 3 -o {shelly.output_dir / 'inpA_3_out.txt'}"
14861486
)
14871487
# checking if outA in the output fields
14881488
assert shelly.output_names == ["return_code", "stdout", "stderr", "outA"]
@@ -1544,7 +1544,7 @@ def test_shell_cmd_inputs_template_9a(tmpdir):
15441544

15451545
assert (
15461546
shelly.cmdline
1547-
== f"executable {tmpdir.join('inpA.t')} -i hola -o {str(shelly.output_dir / 'inpA_hola_out.txt')}"
1547+
== f"executable {tmpdir.join('inpA.t')} -i hola -o {shelly.output_dir / 'inpA_hola_out.txt'}"
15481548
)
15491549
# checking if outA in the output fields
15501550
assert shelly.output_names == ["return_code", "stdout", "stderr", "outA"]
@@ -1714,9 +1714,7 @@ def test_shell_cmd_inputs_template_10():
17141714
)
17151715
# outA has argstr in the metadata fields, so it's a part of the command line
17161716
# the full path will be use din the command line
1717-
assert (
1718-
shelly.cmdline == f"executable 3.3 -o {str(shelly.output_dir / 'file_3.3_out')}"
1719-
)
1717+
assert shelly.cmdline == f"executable 3.3 -o {shelly.output_dir / 'file_3.3_out'}"
17201718
# checking if outA in the output fields
17211719
assert shelly.output_names == ["return_code", "stdout", "stderr", "outA"]
17221720

@@ -1817,7 +1815,7 @@ def template_fun(inputs):
18171815
executable="executable", input_spec=my_input_spec, inpA="inpA"
18181816
)
18191817

1820-
assert shelly.cmdline == f"executable inpA -o {str(shelly.output_dir / 'inpA_out')}"
1818+
assert shelly.cmdline == f"executable inpA -o {shelly.output_dir / 'inpA_out'}"
18211819

18221820

18231821
def test_shell_cmd_inputs_template_function_2():
@@ -1880,7 +1878,7 @@ def template_fun(inputs):
18801878
inpB=1,
18811879
)
18821880

1883-
assert shelly.cmdline == f"executable inpA -o {str(shelly.output_dir / 'inpA_odd')}"
1881+
assert shelly.cmdline == f"executable inpA -o {shelly.output_dir / 'inpA_odd'}"
18841882

18851883

18861884
def test_shell_cmd_inputs_template_1_st():
@@ -1930,7 +1928,7 @@ def test_shell_cmd_inputs_template_1_st():
19301928
# assert len(cmdline_list) == 2
19311929
# for i in range(2):
19321930
# path_out = Path(shelly.output_dir[i]) / f"{inpA[i]}_out"
1933-
# assert cmdline_list[i] == f"executable {inpA[i]} -o {str(path_out)}"
1931+
# assert cmdline_list[i] == f"executable {inpA[i]} -o {path_out}"
19341932

19351933

19361934
# TODO: after deciding how we use requires/templates
@@ -2129,7 +2127,7 @@ def test_shell_cmd_inputs_di(tmpdir, use_validator):
21292127
)
21302128
assert (
21312129
shelly.cmdline
2132-
== f"DenoiseImage -i {tmpdir.join('a_file.ext')} -s 1 -p 1 -r 2 -o [{str(shelly.output_dir / 'a_file_out.ext')}]"
2130+
== f"DenoiseImage -i {tmpdir.join('a_file.ext')} -s 1 -p 1 -r 2 -o [{shelly.output_dir / 'a_file_out.ext'}]"
21332131
)
21342132

21352133
# input file name, noiseImage is set to True, so template is used in the output
@@ -2141,7 +2139,7 @@ def test_shell_cmd_inputs_di(tmpdir, use_validator):
21412139
)
21422140
assert (
21432141
shelly.cmdline == f"DenoiseImage -i {tmpdir.join('a_file.ext')} -s 1 -p 1 -r 2 "
2144-
f"-o [{str(shelly.output_dir / 'a_file_out.ext')}, {str(shelly.output_dir / 'a_file_noise.ext')}]"
2142+
f"-o [{shelly.output_dir / 'a_file_out.ext'}, {str(shelly.output_dir / 'a_file_noise.ext')}]"
21452143
)
21462144

21472145
# input file name and help_short
@@ -2153,7 +2151,7 @@ def test_shell_cmd_inputs_di(tmpdir, use_validator):
21532151
)
21542152
assert (
21552153
shelly.cmdline
2156-
== f"DenoiseImage -i {tmpdir.join('a_file.ext')} -s 1 -p 1 -r 2 -h -o [{str(shelly.output_dir / 'a_file_out.ext')}]"
2154+
== f"DenoiseImage -i {tmpdir.join('a_file.ext')} -s 1 -p 1 -r 2 -h -o [{shelly.output_dir / 'a_file_out.ext'}]"
21572155
)
21582156

21592157
assert shelly.output_names == [
@@ -2173,7 +2171,7 @@ def test_shell_cmd_inputs_di(tmpdir, use_validator):
21732171
)
21742172
assert (
21752173
shelly.cmdline
2176-
== f"DenoiseImage -d 2 -i {tmpdir.join('a_file.ext')} -s 1 -p 1 -r 2 -o [{str(shelly.output_dir / 'a_file_out.ext')}]"
2174+
== f"DenoiseImage -d 2 -i {tmpdir.join('a_file.ext')} -s 1 -p 1 -r 2 -o [{shelly.output_dir / 'a_file_out.ext'}]"
21772175
)
21782176

21792177
# adding image_dimensionality that has allowed_values [2, 3, 4] and providing 5 - exception should be raised

pydra/engine/workers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,12 @@ def _prepare_runscripts(self, task, interpreter="/bin/sh", rerun=False):
252252
batchscript = script_dir / f"batchscript_{uid}.sh"
253253
python_string = (
254254
f"""'from pydra.engine.helpers import load_and_run; """
255-
f"""load_and_run(task_pkl="{str(task_pkl)}", ind={ind}, rerun={rerun}) '"""
255+
f"""load_and_run(task_pkl="{task_pkl}", ind={ind}, rerun={rerun}) '"""
256256
)
257257
bcmd = "\n".join(
258258
(
259259
f"#!{interpreter}",
260-
f"#SBATCH --output={str(script_dir / 'slurm-%j.out')}",
260+
f"#SBATCH --output={script_dir / 'slurm-%j.out'}",
261261
f"{sys.executable} -c " + python_string,
262262
)
263263
)

0 commit comments

Comments
 (0)