Skip to content

Commit b913ae2

Browse files
nulanoradarhere
authored andcommitted
use f-strings in winbuild
1 parent 1f65295 commit b913ae2

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

winbuild/build_prepare.py

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,32 @@
66

77

88
def cmd_cd(path):
9-
return "cd /D {path}".format(**locals())
9+
return f"cd /D {path}"
1010

1111

1212
def cmd_set(name, value):
13-
return "set {name}={value}".format(**locals())
13+
return f"set {name}={value}"
1414

1515

1616
def cmd_append(name, value):
17-
op = "path " if name == "PATH" else "set {name}="
18-
return (op + "%{name}%;{value}").format(**locals())
17+
op = "path " if name == "PATH" else f"set {name}="
18+
return op + f"%{name}%;{value}"
1919

2020

2121
def cmd_copy(src, tgt):
22-
return 'copy /Y /B "{src}" "{tgt}"'.format(**locals())
22+
return f'copy /Y /B "{src}" "{tgt}"'
2323

2424

2525
def cmd_xcopy(src, tgt):
26-
return 'xcopy /Y /E "{src}" "{tgt}"'.format(**locals())
26+
return f'xcopy /Y /E "{src}" "{tgt}"'
2727

2828

2929
def cmd_mkdir(path):
30-
return 'mkdir "{path}"'.format(**locals())
30+
return f'mkdir "{path}"'
3131

3232

3333
def cmd_rmdir(path):
34-
return 'rmdir /S /Q "{path}"'.format(**locals())
34+
return f'rmdir /S /Q "{path}"'
3535

3636

3737
def cmd_nmake(makefile=None, target="", params=None):
@@ -44,13 +44,13 @@ def cmd_nmake(makefile=None, target="", params=None):
4444

4545
return " ".join(
4646
[
47-
"{{nmake}}",
47+
"{nmake}",
4848
"-nologo",
49-
'-f "{makefile}"' if makefile is not None else "",
50-
"{params}",
51-
'"{target}"',
49+
f'-f "{makefile}"' if makefile is not None else "",
50+
f"{params}",
51+
f'"{target}"',
5252
]
53-
).format(**locals())
53+
)
5454

5555

5656
def cmd_cmake(params=None, file="."):
@@ -62,30 +62,30 @@ def cmd_cmake(params=None, file="."):
6262
params = str(params)
6363
return " ".join(
6464
[
65-
"{{cmake}}",
65+
"{cmake}",
6666
"-DCMAKE_VERBOSE_MAKEFILE=ON",
6767
"-DCMAKE_RULE_MESSAGES:BOOL=OFF",
6868
"-DCMAKE_BUILD_TYPE=Release",
69-
"{params}",
69+
f"{params}",
7070
'-G "NMake Makefiles"',
71-
'"{file}"',
71+
f'"{file}"',
7272
]
73-
).format(**locals())
73+
)
7474

7575

7676
def cmd_msbuild(
7777
file, configuration="Release", target="Build", platform="{msbuild_arch}"
7878
):
7979
return " ".join(
8080
[
81-
"{{msbuild}}",
82-
"{file}",
83-
'/t:"{target}"',
84-
'/p:Configuration="{configuration}"',
85-
"/p:Platform={platform}",
81+
"{msbuild}",
82+
f"{file}",
83+
f'/t:"{target}"',
84+
f'/p:Configuration="{configuration}"',
85+
f"/p:Platform={platform}",
8686
"/m",
8787
]
88-
).format(**locals())
88+
)
8989

9090

9191
SF_MIRROR = "http://iweb.dl.sourceforge.net"
@@ -336,12 +336,12 @@ def find_msvs():
336336
# vs2017
337337
msbuild = os.path.join(vspath, "MSBuild", "15.0", "Bin", "MSBuild.exe")
338338
if os.path.isfile(msbuild):
339-
vs["msbuild"] = '"{}"'.format(msbuild)
339+
vs["msbuild"] = f'"{msbuild}"'
340340
else:
341341
# vs2019
342342
msbuild = os.path.join(vspath, "MSBuild", "Current", "Bin", "MSBuild.exe")
343343
if os.path.isfile(msbuild):
344-
vs["msbuild"] = '"{}"'.format(msbuild)
344+
vs["msbuild"] = f'"{msbuild}"'
345345
else:
346346
print("Visual Studio MSBuild not found")
347347
return None
@@ -350,7 +350,7 @@ def find_msvs():
350350
if not os.path.isfile(vcvarsall):
351351
print("Visual Studio vcvarsall not found")
352352
return None
353-
vs["header"].append('call "{}" {{vcvars_arch}}'.format(vcvarsall))
353+
vs["header"].append(f'call "{vcvarsall}" {{vcvars_arch}}')
354354

355355
return vs
356356

@@ -411,7 +411,7 @@ def get_footer(dep):
411411
def build_dep(name):
412412
dep = deps[name]
413413
dir = dep["dir"]
414-
file = "build_dep_{name}.cmd".format(**locals())
414+
file = f"build_dep_{name}.cmd"
415415

416416
extract_dep(dep["url"], dep["filename"])
417417

@@ -424,10 +424,10 @@ def build_dep(name):
424424
with open(patch_file, "w") as f:
425425
f.write(text)
426426

427-
banner = "Building {name} ({dir})".format(**locals())
427+
banner = f"Building {name} ({dir})"
428428
lines = [
429429
"@echo " + ("=" * 70),
430-
"@echo ==== {:<60} ====".format(banner),
430+
f"@echo ==== {banner:<60} ====",
431431
"@echo " + ("=" * 70),
432432
"cd /D %s" % os.path.join(build_dir, dir),
433433
*prefs["header"],
@@ -444,7 +444,8 @@ def build_dep_all():
444444
for dep_name in deps:
445445
if dep_name in disabled:
446446
continue
447-
lines.append(r'cmd.exe /c "{{build_dir}}\{}"'.format(build_dep(dep_name)))
447+
script = build_dep(dep_name)
448+
lines.append(fr'cmd.exe /c "{{build_dir}}\{script}"')
448449
lines.append("if errorlevel 1 echo Build failed! && exit /B 1")
449450
lines.append("@echo All Pillow dependencies built successfully!")
450451
write_script("build_dep_all.cmd", lines)

0 commit comments

Comments
 (0)