Use fstring instead of `.format`

This commit is contained in:
Matthieu Gautier 2024-04-30 14:16:50 +02:00
parent 908b90190c
commit 6b08e12910
16 changed files with 88 additions and 105 deletions

View File

@ -50,7 +50,7 @@ class NeutralEnv:
def _detect_command(self, name, default=None, options=["--version"], required=True): def _detect_command(self, name, default=None, options=["--version"], required=True):
if default is None: if default is None:
default = [[name]] default = [[name]]
env_key = "KBUILD_{}_COMMAND".format(name.upper()) env_key = f"KBUILD_{name.upper()}_COMMAND"
if env_key in os.environ: if env_key in os.environ:
default = [os.environ[env_key].split()] + default default = [os.environ[env_key].split()] + default
for command in default: for command in default:
@ -65,10 +65,10 @@ class NeutralEnv:
return command return command
else: else:
if required: if required:
sys.exit("ERROR: {} command not found".format(name)) sys.exit(f"ERROR: {name} command not found")
else: else:
print("WARNING: {} command not found".format(name), file=sys.stderr) print(f"WARNING: {name} command not found", file=sys.stderr)
return ["{}_NOT_FOUND".format(name.upper())] return [f"{name.upper()}_NOT_FOUND"]
class BuildEnv: class BuildEnv:

View File

@ -26,9 +26,10 @@ class Builder:
if neutralEnv("distname") not in config.compatible_hosts: if neutralEnv("distname") not in config.compatible_hosts:
print( print(
( (
colorize("ERROR") + ": The config {} cannot be build on host {}.\n" colorize("ERROR")
+ f": The config {config.name} cannot be build on host {neutralEnv('distname')}.\n"
"Select another config or change your host system." "Select another config or change your host system."
).format(config.name, neutralEnv("distname")) )
) )
self.targetDefs = config.add_targets(option("target"), self._targets) self.targetDefs = config.add_targets(option("target"), self._targets)
@ -106,7 +107,7 @@ class Builder:
tDef for tDef in target_steps() if tDef[0] == "source" tDef for tDef in target_steps() if tDef[0] == "source"
) )
for sourceDef in sourceDefs: for sourceDef in sourceDefs:
print("prepare sources {} :".format(sourceDef[1])) print(f"prepare sources {sourceDef[1]} :")
source = get_target_step(sourceDef) source = get_target_step(sourceDef)
source.prepare() source.prepare()
@ -115,28 +116,24 @@ class Builder:
for builderDef in builderDefs: for builderDef in builderDefs:
builder = get_target_step(builderDef) builder = get_target_step(builderDef)
if option("make_dist") and builderDef[1] == option("target"): if option("make_dist") and builderDef[1] == option("target"):
print("make dist {} ({}):".format(builder.name, builderDef[0])) print(f"make dist {builder.name} ({builderDef[0]}):")
builder.make_dist() builder.make_dist()
continue continue
print("build {} ({}):".format(builder.name, builderDef[0])) print(f"build {builder.name} ({builderDef[0]}):")
add_target_step(builderDef, builder) add_target_step(builderDef, builder)
builder.build() builder.build()
def _get_packages(self): def _get_packages(self):
packages_list = [] packages_list = []
for config in ConfigInfo.all_running_configs.values(): for config in ConfigInfo.all_running_configs.values():
mapper_name = "{host}_{config}".format( mapper_name = f"{neutralEnv('distname')}_{config}"
host=neutralEnv("distname"), config=config
)
package_name_mapper = PACKAGE_NAME_MAPPERS.get(mapper_name, {}) package_name_mapper = PACKAGE_NAME_MAPPERS.get(mapper_name, {})
packages_list += package_name_mapper.get("COMMON", []) packages_list += package_name_mapper.get("COMMON", [])
to_drop = [] to_drop = []
for builderDef in self._targets: for builderDef in self._targets:
configName, builderName = builderDef configName, builderName = builderDef
mapper_name = "{host}_{config}".format( mapper_name = f"{neutralEnv('distname')}_{config}"
host=neutralEnv("distname"), config=configName
)
package_name_mapper = PACKAGE_NAME_MAPPERS.get(mapper_name, {}) package_name_mapper = PACKAGE_NAME_MAPPERS.get(mapper_name, {})
packages = package_name_mapper.get(builderName) packages = package_name_mapper.get(builderName)
if packages: if packages:
@ -169,7 +166,7 @@ class Builder:
packages_to_install = [] packages_to_install = []
for package in packages_to_have: for package in packages_to_have:
print(" - {} : ".format(package), end="") print(f" - {package} : ", end="")
command = package_checker.format(package) command = package_checker.format(package)
try: try:
subprocess.check_call(command, shell=True) subprocess.check_call(command, shell=True)

View File

@ -14,18 +14,18 @@ class AndroidConfigInfo(ConfigInfo):
@property @property
def libdir(self): def libdir(self):
return "lib/{}".format(self.arch_full) return f"lib/{self.arch_full}"
@property @property
def binaries_name(self): def binaries_name(self):
arch_full = self.arch_full arch_full = self.arch_full
return { return {
"CC": "{}-{}".format(arch_full, "clang"), "CC": f"{arch_full}-clang",
"CXX": "{}-{}".format(arch_full, "clang++"), "CXX": f"{arch_full}-clang++",
"AR": "{}-{}".format(arch_full, "ar"), "AR": f"{arch_full}-ar",
"STRIP": "{}-{}".format(arch_full, "strip"), "STRIP": f"{arch_full}-strip",
"RANLIB": "{}-{}".format(arch_full, "ranlib"), "RANLIB": f"{arch_full}-ranlib",
"LD": "{}-{}".format(arch_full, "ld"), "LD": f"{arch_full}-ld",
} }
def binaries(self): def binaries(self):
@ -44,12 +44,10 @@ class AndroidConfigInfo(ConfigInfo):
def get_cross_config(self): def get_cross_config(self):
extra_libs = ["-llog"] extra_libs = ["-llog"]
extra_cflags = [ extra_cflags = [f"-I{include_dir}" for include_dir in self.get_include_dirs()]
"-I{}".format(include_dir) for include_dir in self.get_include_dirs()
]
if hasattr(self, "march"): if hasattr(self, "march"):
extra_libs.append("-march={}".format(self.march)) extra_libs.append(f"-march={self.march}")
extra_cflags.append("-march={}".format(self.march)) extra_cflags.append(f"-march={self.march}")
return { return {
"exe_wrapper_def": "", "exe_wrapper_def": "",
"install_path": self.install_path, "install_path": self.install_path,
@ -80,20 +78,16 @@ class AndroidConfigInfo(ConfigInfo):
def set_comp_flags(self, env): def set_comp_flags(self, env):
super().set_comp_flags(env) super().set_comp_flags(env)
root_path = self.install_path / "sysroot" root_path = self.install_path / "sysroot"
march = "-march={}".format(self.march) if hasattr(self, "march") else "" march = f"-march={self.march}" if hasattr(self, "march") else ""
env["CFLAGS"] = ( env["CFLAGS"] = (
"-fPIC -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 --sysroot={} {} ".format( f"-fPIC -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 --sysroot={root_path} {march} "
root_path, march
)
+ env["CFLAGS"] + env["CFLAGS"]
) )
env["CXXFLAGS"] = ( env["CXXFLAGS"] = (
"-fPIC -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 --sysroot={} {} ".format( f"-fPIC -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 --sysroot={root_path} {march} "
root_path, march
)
+ env["CXXFLAGS"] + env["CXXFLAGS"]
) )
env["LDFLAGS"] = "--sysroot={} {} ".format(root_path, march) + env["LDFLAGS"] env["LDFLAGS"] = f"--sysroot={root_path} {march} " + env["LDFLAGS"]
def set_compiler(self, env): def set_compiler(self, env):
binaries = self.binaries() binaries = self.binaries()
@ -102,7 +96,7 @@ class AndroidConfigInfo(ConfigInfo):
@property @property
def configure_options(self): def configure_options(self):
yield "--host={}".format(self.arch_full) yield f"--host={self.arch_full}"
def finalize_setup(self): def finalize_setup(self):
super().finalize_setup() super().finalize_setup()
@ -151,7 +145,7 @@ class Android(MetaConfigInfo):
@property @property
def subConfigNames(self): def subConfigNames(self):
return ["android_{}".format(arch) for arch in option("android_arch")] return [f"android_{arch}" for arch in option("android_arch")]
def add_targets(self, targetName, targets): def add_targets(self, targetName, targets):
return super().add_targets(targetName, targets) return super().add_targets(targetName, targets)

View File

@ -15,7 +15,7 @@ class ArmConfigInfo(ConfigInfo):
"root_path": self.root_path, "root_path": self.root_path,
"extra_libs": [], "extra_libs": [],
"extra_cflags": [ "extra_cflags": [
"-I{}".format(include_dir) for include_dir in self.get_include_dirs() f"-I{include_dir}" for include_dir in self.get_include_dirs()
], ],
"host_machine": { "host_machine": {
"system": "linux", "system": "linux",
@ -29,7 +29,7 @@ class ArmConfigInfo(ConfigInfo):
@property @property
def libdir(self): def libdir(self):
return "lib/{}".format(self.arch_full) return f"lib/{self.arch_full}"
@property @property
def toolchain(self): def toolchain(self):
@ -42,7 +42,7 @@ class ArmConfigInfo(ConfigInfo):
@property @property
def binaries(self): def binaries(self):
binaries = ( binaries = (
(k, "{}-{}".format(self.arch_full, v)) (k, f"{self.arch_full}-{v}")
for k, v in ( for k, v in (
("CC", "gcc"), ("CC", "gcc"),
("CXX", "g++"), ("CXX", "g++"),
@ -69,7 +69,7 @@ class ArmConfigInfo(ConfigInfo):
@property @property
def configure_options(self): def configure_options(self):
yield "--host={}".format(self.arch_full) yield f"--host={self.arch_full}"
def get_bin_dir(self): def get_bin_dir(self):
return [self.root_path / "bin"] return [self.root_path / "bin"]

View File

@ -48,7 +48,8 @@ class ConfigInfo(metaclass=_MetaConfig):
self.setup_toolchains(targets) self.setup_toolchains(targets)
def __str__(self): def __str__(self):
return "{}_{}".format(self.build, "static" if self.static else "dyn") postfix = "static" if self.static else "dyn"
return f"{self.build}_{postfix}"
def setup_toolchains(self, targets): def setup_toolchains(self, targets):
for tlc_name in self.toolchain_names: for tlc_name in self.toolchain_names:

View File

@ -18,10 +18,7 @@ class I586ConfigInfo(ConfigInfo):
"-m32", "-m32",
"-march=i586", "-march=i586",
"-mno-sse", "-mno-sse",
*( *(f"-I{include_dir}" for include_dir in self.get_include_dirs()),
"-I{}".format(include_dir)
for include_dir in self.get_include_dirs()
),
], ],
"host_machine": { "host_machine": {
"system": "linux", "system": "linux",

View File

@ -32,7 +32,7 @@ class AppleConfigInfo(ConfigInfo):
@property @property
def root_path(self) -> Path: def root_path(self) -> Path:
if self._root_path is None: if self._root_path is None:
command = "xcrun --sdk {} --show-sdk-path".format(self.sdk_name) command = f"xcrun --sdk {self.sdk_name} --show-sdk-path"
self._root_path = Path( self._root_path = Path(
subprocess.check_output(command, shell=True)[:-1].decode() subprocess.check_output(command, shell=True)[:-1].decode()
) )
@ -70,10 +70,7 @@ class AppleConfigInfo(ConfigInfo):
self.arch, self.arch,
"-target", "-target",
self.target, self.target,
*( *(f"-I{include_dir}" for include_dir in self.get_include_dirs()),
"-I{}".format(include_dir)
for include_dir in self.get_include_dirs()
),
], ],
"host_machine": { "host_machine": {
"system": "Darwin", "system": "Darwin",
@ -86,17 +83,17 @@ class AppleConfigInfo(ConfigInfo):
} }
if self.min_iphoneos_version: if self.min_iphoneos_version:
config["extra_libs"].append( config["extra_libs"].append(
"-miphoneos-version-min={}".format(self.min_iphoneos_version) f"-miphoneos-version-min={self.min_iphoneos_version}"
) )
config["extra_cflags"].append( config["extra_cflags"].append(
"-miphoneos-version-min={}".format(self.min_iphoneos_version) f"-miphoneos-version-min={self.min_iphoneos_version}"
) )
if self.min_macos_version: if self.min_macos_version:
config["extra_libs"].append( config["extra_libs"].append(
"-mmacosx-version-min={}".format(self.min_macos_version) f"-mmacosx-version-min={self.min_macos_version}"
) )
config["extra_cflags"].append( config["extra_cflags"].append(
"-mmacosx-version-min={}".format(self.min_macos_version) f"-mmacosx-version-min={self.min_macos_version}"
) )
return config return config
@ -104,22 +101,22 @@ class AppleConfigInfo(ConfigInfo):
env = super().get_env() env = super().get_env()
cflags = [env["CFLAGS"]] cflags = [env["CFLAGS"]]
if self.min_iphoneos_version: if self.min_iphoneos_version:
cflags.append("-miphoneos-version-min={}".format(self.min_iphoneos_version)) cflags.append(f"-miphoneos-version-min={self.min_iphoneos_version}")
if self.min_macos_version: if self.min_macos_version:
cflags.append("-mmacosx-version-min={}".format(self.min_macos_version)) cflags.append(f"-mmacosx-version-min={self.min_macos_version}")
env["CFLAGS"] = " ".join(cflags) env["CFLAGS"] = " ".join(cflags)
return env return env
def set_comp_flags(self, env): def set_comp_flags(self, env):
super().set_comp_flags(env) super().set_comp_flags(env)
cflags = [ cflags = [
"-isysroot {}".format(self.root_path), f"-isysroot {self.root_path}",
"-arch {}".format(self.arch), f"-arch {self.arch}",
"-target {}".format(self.target), f"-target {self.target}",
env["CFLAGS"], env["CFLAGS"],
] ]
if self.min_iphoneos_version: if self.min_iphoneos_version:
cflags.append("-miphoneos-version-min={}".format(self.min_iphoneos_version)) cflags.append(f"-miphoneos-version-min={self.min_iphoneos_version}")
env["CFLAGS"] = " ".join(cflags) env["CFLAGS"] = " ".join(cflags)
env["CXXFLAGS"] = " ".join( env["CXXFLAGS"] = " ".join(
[ [
@ -130,8 +127,8 @@ class AppleConfigInfo(ConfigInfo):
) )
env["LDFLAGS"] = " ".join( env["LDFLAGS"] = " ".join(
[ [
" -arch {}".format(self.arch), f" -arch {self.arch}",
"-isysroot {}".format(self.root_path), f"-isysroot {self.root_path}",
] ]
) )
@ -222,7 +219,7 @@ class IOS(MetaConfigInfo):
@property @property
def subConfigNames(self): def subConfigNames(self):
return ["iOS_{}".format(arch) for arch in option("ios_arch")] return [f"iOS_{arch}" for arch in option("ios_arch")]
def add_targets(self, targetName, targets): def add_targets(self, targetName, targets):
super().add_targets(targetName, targets) super().add_targets(targetName, targets)

View File

@ -14,7 +14,7 @@ class MuslConfigInfo(ConfigInfo):
"root_path": self.root_path, "root_path": self.root_path,
"extra_libs": [], "extra_libs": [],
"extra_cflags": [ "extra_cflags": [
"-I{}".format(include_dir) for include_dir in self.get_include_dirs() f"-I{include_dir}" for include_dir in self.get_include_dirs()
], ],
"host_machine": { "host_machine": {
"system": "linux", "system": "linux",
@ -37,7 +37,7 @@ class MuslConfigInfo(ConfigInfo):
@property @property
def binaries(self): def binaries(self):
binaries = ( binaries = (
(k, "{}-{}".format(self.arch_full, v)) (k, f"{self.arch_full}-{v}")
for k, v in ( for k, v in (
("CC", "gcc"), ("CC", "gcc"),
("CXX", "g++"), ("CXX", "g++"),

View File

@ -21,10 +21,7 @@ class Win32ConfigInfo(ConfigInfo):
"extra_libs": self.extra_libs, "extra_libs": self.extra_libs,
"extra_cflags": [ "extra_cflags": [
"-DWIN32", "-DWIN32",
*( *(f"-I{include_dir}" for include_dir in self.get_include_dirs()),
"-I{}".format(include_dir)
for include_dir in self.get_include_dirs()
),
], ],
"host_machine": { "host_machine": {
"system": "Windows", "system": "Windows",
@ -52,7 +49,7 @@ class Win32ConfigInfo(ConfigInfo):
@property @property
def binaries(self): def binaries(self):
return { return {
k: which("{}-{}".format(self.arch_full, v)) k: which(f"{self.arch_full}-{v}")
for k, v in ( for k, v in (
("CC", "gcc"), ("CC", "gcc"),
("CXX", "g++"), ("CXX", "g++"),

View File

@ -55,7 +55,7 @@ class Win64ConfigInfo(ConfigInfo):
@property @property
def binaries(self): def binaries(self):
return { return {
k: which("{}-{}".format(self.arch_full, v)) k: which(f"{self.arch_full}-{v}")
for k, v in ( for k, v in (
("CC", "gcc"), ("CC", "gcc"),
("CXX", "g++"), ("CXX", "g++"),

View File

@ -46,7 +46,7 @@ class Dependency(metaclass=_MetaDependency):
@classmethod @classmethod
def full_name(cls): def full_name(cls):
if cls.version(): if cls.version():
return "{}-{}".format(cls.name, cls.version()) return f"{cls.name}-{cls.version()}"
return cls.name return cls.name
@ -86,15 +86,15 @@ class Source:
run_command(patch_command, self.source_path, context) run_command(patch_command, self.source_path, context)
def command(self, name, function, *args): def command(self, name, function, *args):
print(" {} {} : ".format(name, self.name), end="", flush=True) print(f" {name} {self.name} : ", end="", flush=True)
log = self._log_dir / "cmd_{}_{}.log".format(name, self.name) log = self._log_dir / f"cmd_{name}_{self.name}.log"
context = Context(name, log, True) context = Context(name, log, True)
try: try:
start_time = time.time() start_time = time.time()
ret = function(*args, context=context) ret = function(*args, context=context)
context._finalise() context._finalise()
duration = time.time() - start_time duration = time.time() - start_time
print(colorize("OK"), "({:.1f}s)".format(duration)) print(colorize("OK"), f"({duration:.1f}s)")
return ret return ret
except WarningMessage as e: except WarningMessage as e:
print(e) print(e)
@ -175,7 +175,7 @@ class GitClone(Source):
@property @property
def source_dir(self): def source_dir(self):
if option("make_release"): if option("make_release"):
return "{}_release".format(self.git_dir) return f"{self.git_dir}_release"
else: else:
return self.git_dir return self.git_dir
@ -269,8 +269,8 @@ class Builder:
return self.buildEnv.log_dir return self.buildEnv.log_dir
def command(self, name, function, *args): def command(self, name, function, *args):
print(" {} {} : ".format(name, self.name), end="", flush=True) print(f" {name} {self.name} : ", end="", flush=True)
log = self._log_dir / "cmd_{}_{}.log".format(name, self.name) log = self._log_dir / f"cmd_{name}_{self.name}.log"
context = Context(name, log, self.target.force_native_build) context = Context(name, log, self.target.force_native_build)
if self.target.force_build: if self.target.force_build:
context.no_skip = True context.no_skip = True
@ -279,7 +279,7 @@ class Builder:
ret = function(*args, context=context) ret = function(*args, context=context)
context._finalise() context._finalise()
duration = time.time() - start_time duration = time.time() - start_time
print(colorize("OK"), "({:.1f}s)".format(duration)) print(colorize("OK"), f"({duration:.1f}s)")
return ret return ret
except SkipCommand as e: except SkipCommand as e:
print(e) print(e)

View File

@ -15,10 +15,10 @@ class IOSFatLib(Dependency):
@classmethod @classmethod
def get_dependencies(self, platfomInfo, alldeps): def get_dependencies(self, platfomInfo, alldeps):
base_target = option("target") base_target = option("target")
return [("iOS_{}".format(arch), base_target) for arch in option("ios_arch")] return [(f"iOS_{arch}", base_target) for arch in option("ios_arch")]
def _copy_headers(self, context): def _copy_headers(self, context):
plt = ConfigInfo.get_config("iOS_{}".format(option("ios_arch")[0])) plt = ConfigInfo.get_config(f"iOS_{option('ios_arch')[0]}")
include_src = plt.buildEnv.install_dir / "include" include_src = plt.buildEnv.install_dir / "include"
include_dst = self.buildEnv.install_dir / "include" include_dst = self.buildEnv.install_dir / "include"
copy_tree(include_src, include_dst) copy_tree(include_src, include_dst)
@ -26,7 +26,7 @@ class IOSFatLib(Dependency):
def _merge_libs(self, context): def _merge_libs(self, context):
lib_dirs = [] lib_dirs = []
for arch in option("ios_arch"): for arch in option("ios_arch"):
plt = ConfigInfo.get_config("iOS_{}".format(arch)) plt = ConfigInfo.get_config(f"iOS_{arch}")
lib_dirs.append(plt.buildEnv.install_dir / "lib") lib_dirs.append(plt.buildEnv.install_dir / "lib")
libs = [] libs = []
for f in lib_dirs[0].iterdir(): for f in lib_dirs[0].iterdir():

View File

@ -50,7 +50,7 @@ class Libzim(Dependency):
yield "-DUSE_MMAP=false" yield "-DUSE_MMAP=false"
if configInfo.name not in ("flatpak", "wasm"): if configInfo.name not in ("flatpak", "wasm"):
zim_testing_suite = get_target_step("zim-testing-suite", "source") zim_testing_suite = get_target_step("zim-testing-suite", "source")
yield "-Dtest_data_dir={}".format(zim_testing_suite.source_path) yield f"-Dtest_data_dir={zim_testing_suite.source_path}"
@property @property
def library_type(self): def library_type(self):

View File

@ -62,7 +62,7 @@ class android_ndk(Dependency):
context.try_skip(self.build_path) context.try_skip(self.build_path)
bin_dirs = [ bin_dirs = [
self.install_path / "bin", self.install_path / "bin",
self.install_pat / self.arch_full / "bin", self.install_path / self.arch_full / "bin",
self.install_path self.install_path
/ "libexec" / "libexec"
/ "gcc" / "gcc"

View File

@ -82,9 +82,9 @@ class FlatpakBuilder:
if neutralEnv("distname") not in self.config.compatible_hosts: if neutralEnv("distname") not in self.config.compatible_hosts:
print( print(
( (
"ERROR: The config {} cannot be build on host {}.\n" f"ERROR: The config {self.config.name} cannot be build on host {neutralEnv('distname')}.\n"
"Select another config or change your host system." "Select another config or change your host system."
).format(self.config.name, neutralEnv("distname")) )
) )
self.targetDefs = self.config.add_targets(option("target"), self._targets) self.targetDefs = self.config.add_targets(option("target"), self._targets)
@ -205,7 +205,7 @@ class FlatpakBuilder:
del m["sources"] del m["sources"]
m["sources"] = temp m["sources"] = temp
manifest["modules"] = modules manifest["modules"] = modules
manifest_name = "{}.json".format(MANIFEST["app-id"]) manifest_name = f"{MANIFEST['app-id']}.json"
manifest_path = self.config.buildEnv.build_dir / manifest_name manifest_path = self.config.buildEnv.build_dir / manifest_name
manifest_path.write_text(json.dumps(manifest, indent=4)) manifest_path.write_text(json.dumps(manifest, indent=4))
@ -294,7 +294,7 @@ class FlatpakBuilder:
tlc = Dependency.all_deps[tlcName] tlc = Dependency.all_deps[tlcName]
builderDef = (cfgName, tlcName) builderDef = (cfgName, tlcName)
builder = get_target_step(builderDef) builder = get_target_step(builderDef)
print("build {} ({}):".format(builder.name, cfgName[0])) print(f"build {builder.name} ({cfgName[0]}):")
add_target_step(builderDef, builder) add_target_step(builderDef, builder)
builder.build() builder.build()
print("[GENERATE FLATPAK MANIFEST]") print("[GENERATE FLATPAK MANIFEST]")

View File

@ -28,13 +28,13 @@ REMOTE_PREFIX = "http://mirror.download.kiwix.org/dev/kiwix-build/"
def which(name): def which(name):
command = "which {}".format(name) command = f"which {name}"
output = subprocess.check_output(command, shell=True) output = subprocess.check_output(command, shell=True)
return output[:-1].decode() return output[:-1].decode()
def xrun_find(name): def xrun_find(name):
command = "xcrun -find {}".format(name) command = f"xcrun -find {name}"
output = subprocess.check_output(command, shell=True) output = subprocess.check_output(command, shell=True)
return output[:-1].decode() return output[:-1].decode()
@ -117,12 +117,12 @@ def get_sha256(path: Path):
def colorize(text, color=None): def colorize(text, color=None):
if color is None: if color is None:
color = text color = text
return "{}{}{}".format(COLORS[color], text, COLORS[""]) return f"{COLORS[color]}{text}{COLORS['']}"
def print_progress(progress): def print_progress(progress):
if option("show_progress"): if option("show_progress"):
text = "{}\033[{}D".format(progress, len(progress)) text = f"{progress}\033[{len(progress)}D"
print(text, end="") print(text, end="")
@ -181,17 +181,17 @@ def download_remote(what: Remotefile, where: Path):
break break
if tsize: if tsize:
current += batch_size current += batch_size
print_progress("{:.2%}".format(current / tsize)) print_progress(f"{current/tsize:.2%}")
else: else:
print_progress(progress_chars[current]) print_progress(progress_chars[current])
current = (current + 1) % 4 current = (current + 1) % 4
file.write(batch) file.write(batch)
except urllib.error.URLError as e: except urllib.error.URLError as e:
print("Cannot download url {}:\n{}".format(what.url, e.reason)) print(f"Cannot download url {what.url}:\n{e.reason}")
raise StopBuild() raise StopBuild()
if not what.sha256: if not what.sha256:
print("Sha256 for {} not set, do no verify download".format(what.name)) print(f"Sha256 for {what.name} not set, do no verify download")
elif what.sha256 != get_sha256(file_path): elif what.sha256 != get_sha256(file_path):
file_path.unlink() file_path.unlink()
raise StopBuild("Sha 256 doesn't correspond") raise StopBuild("Sha 256 doesn't correspond")
@ -208,13 +208,13 @@ class BaseCommandResult(Exception):
class SkipCommand(BaseCommandResult): class SkipCommand(BaseCommandResult):
def __str__(self): def __str__(self):
if self.msg: if self.msg:
return colorize("SKIP") + " : {}".format(self.msg) return colorize("SKIP") + f" : {self.msg}"
return colorize("SKIP") return colorize("SKIP")
class WarningMessage(BaseCommandResult): class WarningMessage(BaseCommandResult):
def __str__(self): def __str__(self):
return colorize("WARNING") + " : {}".format(self.msg) return colorize("WARNING") + f" : {self.msg}"
class StopBuild(BaseCommandResult): class StopBuild(BaseCommandResult):
@ -236,8 +236,8 @@ class Context:
if self.no_skip: if self.no_skip:
return return
if extra_name: if extra_name:
extra_name = "_{}".format(extra_name) extra_name = f"_{extra_name}"
self.autoskip_file = path / ".{}{}_ok".format(self.command_name, extra_name) self.autoskip_file = path / f".{self.command_name}{extra_name}_ok"
if self.autoskip_file.exists(): if self.autoskip_file.exists():
raise SkipCommand() raise SkipCommand()
@ -331,12 +331,12 @@ def run_command(command, cwd, context, *, env=None, input=None):
try: try:
if not option("verbose"): if not option("verbose"):
log = open(context.log_file, "w") log = open(context.log_file, "w")
print("run command '{}'".format(command), file=log) print(f"run command '{command}'", file=log)
print("current directory is '{}'".format(cwd), file=log) print(f"current directory is '{cwd}'", file=log)
print("env is :", file=log) print("env is :", file=log)
env = {k: str(v) for k, v in env.items()} env = {k: str(v) for k, v in env.items()}
for k, v in env.items(): for k, v in env.items():
print(" {} : {!r}".format(k, v), file=log) print(f" {k} : {v!r}", file=log)
if log: if log:
log.flush() log.flush()
@ -349,7 +349,7 @@ def run_command(command, cwd, context, *, env=None, input=None):
env=env, env=env,
stdout=log or sys.stdout, stdout=log or sys.stdout,
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
**kwargs **kwargs,
) )
if input: if input:
input = input.encode() input = input.encode()