Use fstring instead of `.format`
This commit is contained in:
parent
908b90190c
commit
6b08e12910
|
@ -50,7 +50,7 @@ class NeutralEnv:
|
|||
def _detect_command(self, name, default=None, options=["--version"], required=True):
|
||||
if default is None:
|
||||
default = [[name]]
|
||||
env_key = "KBUILD_{}_COMMAND".format(name.upper())
|
||||
env_key = f"KBUILD_{name.upper()}_COMMAND"
|
||||
if env_key in os.environ:
|
||||
default = [os.environ[env_key].split()] + default
|
||||
for command in default:
|
||||
|
@ -65,10 +65,10 @@ class NeutralEnv:
|
|||
return command
|
||||
else:
|
||||
if required:
|
||||
sys.exit("ERROR: {} command not found".format(name))
|
||||
sys.exit(f"ERROR: {name} command not found")
|
||||
else:
|
||||
print("WARNING: {} command not found".format(name), file=sys.stderr)
|
||||
return ["{}_NOT_FOUND".format(name.upper())]
|
||||
print(f"WARNING: {name} command not found", file=sys.stderr)
|
||||
return [f"{name.upper()}_NOT_FOUND"]
|
||||
|
||||
|
||||
class BuildEnv:
|
||||
|
|
|
@ -26,9 +26,10 @@ class Builder:
|
|||
if neutralEnv("distname") not in config.compatible_hosts:
|
||||
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."
|
||||
).format(config.name, neutralEnv("distname"))
|
||||
)
|
||||
)
|
||||
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"
|
||||
)
|
||||
for sourceDef in sourceDefs:
|
||||
print("prepare sources {} :".format(sourceDef[1]))
|
||||
print(f"prepare sources {sourceDef[1]} :")
|
||||
source = get_target_step(sourceDef)
|
||||
source.prepare()
|
||||
|
||||
|
@ -115,28 +116,24 @@ class Builder:
|
|||
for builderDef in builderDefs:
|
||||
builder = get_target_step(builderDef)
|
||||
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()
|
||||
continue
|
||||
print("build {} ({}):".format(builder.name, builderDef[0]))
|
||||
print(f"build {builder.name} ({builderDef[0]}):")
|
||||
add_target_step(builderDef, builder)
|
||||
builder.build()
|
||||
|
||||
def _get_packages(self):
|
||||
packages_list = []
|
||||
for config in ConfigInfo.all_running_configs.values():
|
||||
mapper_name = "{host}_{config}".format(
|
||||
host=neutralEnv("distname"), config=config
|
||||
)
|
||||
mapper_name = f"{neutralEnv('distname')}_{config}"
|
||||
package_name_mapper = PACKAGE_NAME_MAPPERS.get(mapper_name, {})
|
||||
packages_list += package_name_mapper.get("COMMON", [])
|
||||
|
||||
to_drop = []
|
||||
for builderDef in self._targets:
|
||||
configName, builderName = builderDef
|
||||
mapper_name = "{host}_{config}".format(
|
||||
host=neutralEnv("distname"), config=configName
|
||||
)
|
||||
mapper_name = f"{neutralEnv('distname')}_{config}"
|
||||
package_name_mapper = PACKAGE_NAME_MAPPERS.get(mapper_name, {})
|
||||
packages = package_name_mapper.get(builderName)
|
||||
if packages:
|
||||
|
@ -169,7 +166,7 @@ class Builder:
|
|||
|
||||
packages_to_install = []
|
||||
for package in packages_to_have:
|
||||
print(" - {} : ".format(package), end="")
|
||||
print(f" - {package} : ", end="")
|
||||
command = package_checker.format(package)
|
||||
try:
|
||||
subprocess.check_call(command, shell=True)
|
||||
|
|
|
@ -14,18 +14,18 @@ class AndroidConfigInfo(ConfigInfo):
|
|||
|
||||
@property
|
||||
def libdir(self):
|
||||
return "lib/{}".format(self.arch_full)
|
||||
return f"lib/{self.arch_full}"
|
||||
|
||||
@property
|
||||
def binaries_name(self):
|
||||
arch_full = self.arch_full
|
||||
return {
|
||||
"CC": "{}-{}".format(arch_full, "clang"),
|
||||
"CXX": "{}-{}".format(arch_full, "clang++"),
|
||||
"AR": "{}-{}".format(arch_full, "ar"),
|
||||
"STRIP": "{}-{}".format(arch_full, "strip"),
|
||||
"RANLIB": "{}-{}".format(arch_full, "ranlib"),
|
||||
"LD": "{}-{}".format(arch_full, "ld"),
|
||||
"CC": f"{arch_full}-clang",
|
||||
"CXX": f"{arch_full}-clang++",
|
||||
"AR": f"{arch_full}-ar",
|
||||
"STRIP": f"{arch_full}-strip",
|
||||
"RANLIB": f"{arch_full}-ranlib",
|
||||
"LD": f"{arch_full}-ld",
|
||||
}
|
||||
|
||||
def binaries(self):
|
||||
|
@ -44,12 +44,10 @@ class AndroidConfigInfo(ConfigInfo):
|
|||
|
||||
def get_cross_config(self):
|
||||
extra_libs = ["-llog"]
|
||||
extra_cflags = [
|
||||
"-I{}".format(include_dir) for include_dir in self.get_include_dirs()
|
||||
]
|
||||
extra_cflags = [f"-I{include_dir}" for include_dir in self.get_include_dirs()]
|
||||
if hasattr(self, "march"):
|
||||
extra_libs.append("-march={}".format(self.march))
|
||||
extra_cflags.append("-march={}".format(self.march))
|
||||
extra_libs.append(f"-march={self.march}")
|
||||
extra_cflags.append(f"-march={self.march}")
|
||||
return {
|
||||
"exe_wrapper_def": "",
|
||||
"install_path": self.install_path,
|
||||
|
@ -80,20 +78,16 @@ class AndroidConfigInfo(ConfigInfo):
|
|||
def set_comp_flags(self, env):
|
||||
super().set_comp_flags(env)
|
||||
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"] = (
|
||||
"-fPIC -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 --sysroot={} {} ".format(
|
||||
root_path, march
|
||||
)
|
||||
f"-fPIC -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 --sysroot={root_path} {march} "
|
||||
+ env["CFLAGS"]
|
||||
)
|
||||
env["CXXFLAGS"] = (
|
||||
"-fPIC -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 --sysroot={} {} ".format(
|
||||
root_path, march
|
||||
)
|
||||
f"-fPIC -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 --sysroot={root_path} {march} "
|
||||
+ 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):
|
||||
binaries = self.binaries()
|
||||
|
@ -102,7 +96,7 @@ class AndroidConfigInfo(ConfigInfo):
|
|||
|
||||
@property
|
||||
def configure_options(self):
|
||||
yield "--host={}".format(self.arch_full)
|
||||
yield f"--host={self.arch_full}"
|
||||
|
||||
def finalize_setup(self):
|
||||
super().finalize_setup()
|
||||
|
@ -151,7 +145,7 @@ class Android(MetaConfigInfo):
|
|||
|
||||
@property
|
||||
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):
|
||||
return super().add_targets(targetName, targets)
|
||||
|
|
|
@ -15,7 +15,7 @@ class ArmConfigInfo(ConfigInfo):
|
|||
"root_path": self.root_path,
|
||||
"extra_libs": [],
|
||||
"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": {
|
||||
"system": "linux",
|
||||
|
@ -29,7 +29,7 @@ class ArmConfigInfo(ConfigInfo):
|
|||
|
||||
@property
|
||||
def libdir(self):
|
||||
return "lib/{}".format(self.arch_full)
|
||||
return f"lib/{self.arch_full}"
|
||||
|
||||
@property
|
||||
def toolchain(self):
|
||||
|
@ -42,7 +42,7 @@ class ArmConfigInfo(ConfigInfo):
|
|||
@property
|
||||
def binaries(self):
|
||||
binaries = (
|
||||
(k, "{}-{}".format(self.arch_full, v))
|
||||
(k, f"{self.arch_full}-{v}")
|
||||
for k, v in (
|
||||
("CC", "gcc"),
|
||||
("CXX", "g++"),
|
||||
|
@ -69,7 +69,7 @@ class ArmConfigInfo(ConfigInfo):
|
|||
|
||||
@property
|
||||
def configure_options(self):
|
||||
yield "--host={}".format(self.arch_full)
|
||||
yield f"--host={self.arch_full}"
|
||||
|
||||
def get_bin_dir(self):
|
||||
return [self.root_path / "bin"]
|
||||
|
|
|
@ -48,7 +48,8 @@ class ConfigInfo(metaclass=_MetaConfig):
|
|||
self.setup_toolchains(targets)
|
||||
|
||||
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):
|
||||
for tlc_name in self.toolchain_names:
|
||||
|
|
|
@ -18,10 +18,7 @@ class I586ConfigInfo(ConfigInfo):
|
|||
"-m32",
|
||||
"-march=i586",
|
||||
"-mno-sse",
|
||||
*(
|
||||
"-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": {
|
||||
"system": "linux",
|
||||
|
|
|
@ -32,7 +32,7 @@ class AppleConfigInfo(ConfigInfo):
|
|||
@property
|
||||
def root_path(self) -> Path:
|
||||
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(
|
||||
subprocess.check_output(command, shell=True)[:-1].decode()
|
||||
)
|
||||
|
@ -70,10 +70,7 @@ class AppleConfigInfo(ConfigInfo):
|
|||
self.arch,
|
||||
"-target",
|
||||
self.target,
|
||||
*(
|
||||
"-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": {
|
||||
"system": "Darwin",
|
||||
|
@ -86,17 +83,17 @@ class AppleConfigInfo(ConfigInfo):
|
|||
}
|
||||
if self.min_iphoneos_version:
|
||||
config["extra_libs"].append(
|
||||
"-miphoneos-version-min={}".format(self.min_iphoneos_version)
|
||||
f"-miphoneos-version-min={self.min_iphoneos_version}"
|
||||
)
|
||||
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:
|
||||
config["extra_libs"].append(
|
||||
"-mmacosx-version-min={}".format(self.min_macos_version)
|
||||
f"-mmacosx-version-min={self.min_macos_version}"
|
||||
)
|
||||
config["extra_cflags"].append(
|
||||
"-mmacosx-version-min={}".format(self.min_macos_version)
|
||||
f"-mmacosx-version-min={self.min_macos_version}"
|
||||
)
|
||||
return config
|
||||
|
||||
|
@ -104,22 +101,22 @@ class AppleConfigInfo(ConfigInfo):
|
|||
env = super().get_env()
|
||||
cflags = [env["CFLAGS"]]
|
||||
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:
|
||||
cflags.append("-mmacosx-version-min={}".format(self.min_macos_version))
|
||||
cflags.append(f"-mmacosx-version-min={self.min_macos_version}")
|
||||
env["CFLAGS"] = " ".join(cflags)
|
||||
return env
|
||||
|
||||
def set_comp_flags(self, env):
|
||||
super().set_comp_flags(env)
|
||||
cflags = [
|
||||
"-isysroot {}".format(self.root_path),
|
||||
"-arch {}".format(self.arch),
|
||||
"-target {}".format(self.target),
|
||||
f"-isysroot {self.root_path}",
|
||||
f"-arch {self.arch}",
|
||||
f"-target {self.target}",
|
||||
env["CFLAGS"],
|
||||
]
|
||||
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["CXXFLAGS"] = " ".join(
|
||||
[
|
||||
|
@ -130,8 +127,8 @@ class AppleConfigInfo(ConfigInfo):
|
|||
)
|
||||
env["LDFLAGS"] = " ".join(
|
||||
[
|
||||
" -arch {}".format(self.arch),
|
||||
"-isysroot {}".format(self.root_path),
|
||||
f" -arch {self.arch}",
|
||||
f"-isysroot {self.root_path}",
|
||||
]
|
||||
)
|
||||
|
||||
|
@ -222,7 +219,7 @@ class IOS(MetaConfigInfo):
|
|||
|
||||
@property
|
||||
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):
|
||||
super().add_targets(targetName, targets)
|
||||
|
|
|
@ -14,7 +14,7 @@ class MuslConfigInfo(ConfigInfo):
|
|||
"root_path": self.root_path,
|
||||
"extra_libs": [],
|
||||
"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": {
|
||||
"system": "linux",
|
||||
|
@ -37,7 +37,7 @@ class MuslConfigInfo(ConfigInfo):
|
|||
@property
|
||||
def binaries(self):
|
||||
binaries = (
|
||||
(k, "{}-{}".format(self.arch_full, v))
|
||||
(k, f"{self.arch_full}-{v}")
|
||||
for k, v in (
|
||||
("CC", "gcc"),
|
||||
("CXX", "g++"),
|
||||
|
|
|
@ -21,10 +21,7 @@ class Win32ConfigInfo(ConfigInfo):
|
|||
"extra_libs": self.extra_libs,
|
||||
"extra_cflags": [
|
||||
"-DWIN32",
|
||||
*(
|
||||
"-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": {
|
||||
"system": "Windows",
|
||||
|
@ -52,7 +49,7 @@ class Win32ConfigInfo(ConfigInfo):
|
|||
@property
|
||||
def binaries(self):
|
||||
return {
|
||||
k: which("{}-{}".format(self.arch_full, v))
|
||||
k: which(f"{self.arch_full}-{v}")
|
||||
for k, v in (
|
||||
("CC", "gcc"),
|
||||
("CXX", "g++"),
|
||||
|
|
|
@ -55,7 +55,7 @@ class Win64ConfigInfo(ConfigInfo):
|
|||
@property
|
||||
def binaries(self):
|
||||
return {
|
||||
k: which("{}-{}".format(self.arch_full, v))
|
||||
k: which(f"{self.arch_full}-{v}")
|
||||
for k, v in (
|
||||
("CC", "gcc"),
|
||||
("CXX", "g++"),
|
||||
|
|
|
@ -46,7 +46,7 @@ class Dependency(metaclass=_MetaDependency):
|
|||
@classmethod
|
||||
def full_name(cls):
|
||||
if cls.version():
|
||||
return "{}-{}".format(cls.name, cls.version())
|
||||
return f"{cls.name}-{cls.version()}"
|
||||
return cls.name
|
||||
|
||||
|
||||
|
@ -86,15 +86,15 @@ class Source:
|
|||
run_command(patch_command, self.source_path, context)
|
||||
|
||||
def command(self, name, function, *args):
|
||||
print(" {} {} : ".format(name, self.name), end="", flush=True)
|
||||
log = self._log_dir / "cmd_{}_{}.log".format(name, self.name)
|
||||
print(f" {name} {self.name} : ", end="", flush=True)
|
||||
log = self._log_dir / f"cmd_{name}_{self.name}.log"
|
||||
context = Context(name, log, True)
|
||||
try:
|
||||
start_time = time.time()
|
||||
ret = function(*args, context=context)
|
||||
context._finalise()
|
||||
duration = time.time() - start_time
|
||||
print(colorize("OK"), "({:.1f}s)".format(duration))
|
||||
print(colorize("OK"), f"({duration:.1f}s)")
|
||||
return ret
|
||||
except WarningMessage as e:
|
||||
print(e)
|
||||
|
@ -175,7 +175,7 @@ class GitClone(Source):
|
|||
@property
|
||||
def source_dir(self):
|
||||
if option("make_release"):
|
||||
return "{}_release".format(self.git_dir)
|
||||
return f"{self.git_dir}_release"
|
||||
else:
|
||||
return self.git_dir
|
||||
|
||||
|
@ -269,8 +269,8 @@ class Builder:
|
|||
return self.buildEnv.log_dir
|
||||
|
||||
def command(self, name, function, *args):
|
||||
print(" {} {} : ".format(name, self.name), end="", flush=True)
|
||||
log = self._log_dir / "cmd_{}_{}.log".format(name, self.name)
|
||||
print(f" {name} {self.name} : ", end="", flush=True)
|
||||
log = self._log_dir / f"cmd_{name}_{self.name}.log"
|
||||
context = Context(name, log, self.target.force_native_build)
|
||||
if self.target.force_build:
|
||||
context.no_skip = True
|
||||
|
@ -279,7 +279,7 @@ class Builder:
|
|||
ret = function(*args, context=context)
|
||||
context._finalise()
|
||||
duration = time.time() - start_time
|
||||
print(colorize("OK"), "({:.1f}s)".format(duration))
|
||||
print(colorize("OK"), f"({duration:.1f}s)")
|
||||
return ret
|
||||
except SkipCommand as e:
|
||||
print(e)
|
||||
|
|
|
@ -15,10 +15,10 @@ class IOSFatLib(Dependency):
|
|||
@classmethod
|
||||
def get_dependencies(self, platfomInfo, alldeps):
|
||||
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):
|
||||
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_dst = self.buildEnv.install_dir / "include"
|
||||
copy_tree(include_src, include_dst)
|
||||
|
@ -26,7 +26,7 @@ class IOSFatLib(Dependency):
|
|||
def _merge_libs(self, context):
|
||||
lib_dirs = []
|
||||
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")
|
||||
libs = []
|
||||
for f in lib_dirs[0].iterdir():
|
||||
|
|
|
@ -50,7 +50,7 @@ class Libzim(Dependency):
|
|||
yield "-DUSE_MMAP=false"
|
||||
if configInfo.name not in ("flatpak", "wasm"):
|
||||
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
|
||||
def library_type(self):
|
||||
|
|
|
@ -62,7 +62,7 @@ class android_ndk(Dependency):
|
|||
context.try_skip(self.build_path)
|
||||
bin_dirs = [
|
||||
self.install_path / "bin",
|
||||
self.install_pat / self.arch_full / "bin",
|
||||
self.install_path / self.arch_full / "bin",
|
||||
self.install_path
|
||||
/ "libexec"
|
||||
/ "gcc"
|
||||
|
|
|
@ -82,9 +82,9 @@ class FlatpakBuilder:
|
|||
if neutralEnv("distname") not in self.config.compatible_hosts:
|
||||
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."
|
||||
).format(self.config.name, neutralEnv("distname"))
|
||||
)
|
||||
)
|
||||
self.targetDefs = self.config.add_targets(option("target"), self._targets)
|
||||
|
||||
|
@ -205,7 +205,7 @@ class FlatpakBuilder:
|
|||
del m["sources"]
|
||||
m["sources"] = temp
|
||||
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.write_text(json.dumps(manifest, indent=4))
|
||||
|
||||
|
@ -294,7 +294,7 @@ class FlatpakBuilder:
|
|||
tlc = Dependency.all_deps[tlcName]
|
||||
builderDef = (cfgName, tlcName)
|
||||
builder = get_target_step(builderDef)
|
||||
print("build {} ({}):".format(builder.name, cfgName[0]))
|
||||
print(f"build {builder.name} ({cfgName[0]}):")
|
||||
add_target_step(builderDef, builder)
|
||||
builder.build()
|
||||
print("[GENERATE FLATPAK MANIFEST]")
|
||||
|
|
|
@ -28,13 +28,13 @@ REMOTE_PREFIX = "http://mirror.download.kiwix.org/dev/kiwix-build/"
|
|||
|
||||
|
||||
def which(name):
|
||||
command = "which {}".format(name)
|
||||
command = f"which {name}"
|
||||
output = subprocess.check_output(command, shell=True)
|
||||
return output[:-1].decode()
|
||||
|
||||
|
||||
def xrun_find(name):
|
||||
command = "xcrun -find {}".format(name)
|
||||
command = f"xcrun -find {name}"
|
||||
output = subprocess.check_output(command, shell=True)
|
||||
return output[:-1].decode()
|
||||
|
||||
|
@ -117,12 +117,12 @@ def get_sha256(path: Path):
|
|||
def colorize(text, color=None):
|
||||
if color is None:
|
||||
color = text
|
||||
return "{}{}{}".format(COLORS[color], text, COLORS[""])
|
||||
return f"{COLORS[color]}{text}{COLORS['']}"
|
||||
|
||||
|
||||
def print_progress(progress):
|
||||
if option("show_progress"):
|
||||
text = "{}\033[{}D".format(progress, len(progress))
|
||||
text = f"{progress}\033[{len(progress)}D"
|
||||
print(text, end="")
|
||||
|
||||
|
||||
|
@ -181,17 +181,17 @@ def download_remote(what: Remotefile, where: Path):
|
|||
break
|
||||
if tsize:
|
||||
current += batch_size
|
||||
print_progress("{:.2%}".format(current / tsize))
|
||||
print_progress(f"{current/tsize:.2%}")
|
||||
else:
|
||||
print_progress(progress_chars[current])
|
||||
current = (current + 1) % 4
|
||||
file.write(batch)
|
||||
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()
|
||||
|
||||
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):
|
||||
file_path.unlink()
|
||||
raise StopBuild("Sha 256 doesn't correspond")
|
||||
|
@ -208,13 +208,13 @@ class BaseCommandResult(Exception):
|
|||
class SkipCommand(BaseCommandResult):
|
||||
def __str__(self):
|
||||
if self.msg:
|
||||
return colorize("SKIP") + " : {}".format(self.msg)
|
||||
return colorize("SKIP") + f" : {self.msg}"
|
||||
return colorize("SKIP")
|
||||
|
||||
|
||||
class WarningMessage(BaseCommandResult):
|
||||
def __str__(self):
|
||||
return colorize("WARNING") + " : {}".format(self.msg)
|
||||
return colorize("WARNING") + f" : {self.msg}"
|
||||
|
||||
|
||||
class StopBuild(BaseCommandResult):
|
||||
|
@ -236,8 +236,8 @@ class Context:
|
|||
if self.no_skip:
|
||||
return
|
||||
if extra_name:
|
||||
extra_name = "_{}".format(extra_name)
|
||||
self.autoskip_file = path / ".{}{}_ok".format(self.command_name, extra_name)
|
||||
extra_name = f"_{extra_name}"
|
||||
self.autoskip_file = path / f".{self.command_name}{extra_name}_ok"
|
||||
if self.autoskip_file.exists():
|
||||
raise SkipCommand()
|
||||
|
||||
|
@ -331,12 +331,12 @@ def run_command(command, cwd, context, *, env=None, input=None):
|
|||
try:
|
||||
if not option("verbose"):
|
||||
log = open(context.log_file, "w")
|
||||
print("run command '{}'".format(command), file=log)
|
||||
print("current directory is '{}'".format(cwd), file=log)
|
||||
print(f"run command '{command}'", file=log)
|
||||
print(f"current directory is '{cwd}'", file=log)
|
||||
print("env is :", file=log)
|
||||
env = {k: str(v) 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:
|
||||
log.flush()
|
||||
|
@ -349,7 +349,7 @@ def run_command(command, cwd, context, *, env=None, input=None):
|
|||
env=env,
|
||||
stdout=log or sys.stdout,
|
||||
stderr=subprocess.STDOUT,
|
||||
**kwargs
|
||||
**kwargs,
|
||||
)
|
||||
if input:
|
||||
input = input.encode()
|
||||
|
|
Loading…
Reference in New Issue