aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristian Maureira-Fredes <Cristian.Maureira-Fredes@qt.io>2020-12-29 18:22:54 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-01-04 17:03:46 +0000
commit98919e94556eb96a7a0afb5e160c7634c4fbf4ef (patch)
tree3411e9d2ebe38cbcf87cfe89ba82d931e86bfc0d
parent3f1abffcbc1149ad8876ad0ef842968963a8015b (diff)
build_scripts: use f-strings instead of format()
Change-Id: I165e9a39f968f67f9eae3a632739908d5f8fda59 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Christian Tismer <tismer@stackless.com> (cherry picked from commit 6cc55fefc8ddf12ecc9dcce33e367148e6216b1f) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--build_scripts/config.py8
-rw-r--r--build_scripts/main.py222
-rw-r--r--build_scripts/options.py12
-rw-r--r--build_scripts/platforms/macos.py2
-rw-r--r--build_scripts/platforms/windows_desktop.py2
-rw-r--r--build_scripts/qtinfo.py4
-rw-r--r--build_scripts/setup_runner.py21
-rw-r--r--build_scripts/utils.py151
-rw-r--r--build_scripts/wheel_override.py4
-rw-r--r--build_scripts/wheel_utils.py21
10 files changed, 215 insertions, 232 deletions
diff --git a/build_scripts/config.py b/build_scripts/config.py
index eb632fe3f..bcbc0b6e4 100644
--- a/build_scripts/config.py
+++ b/build_scripts/config.py
@@ -200,7 +200,7 @@ class Config(object):
elif self.internal_build_type == self.shiboken_generator_option_name:
setup_kwargs['name'] = self.shiboken_generator_st_name
setup_kwargs['description'] = "Python / C++ bindings generator"
- setup_kwargs['install_requires'] = ["{}=={}".format(self.shiboken_module_st_name, package_version)]
+ setup_kwargs['install_requires'] = [f"{self.shiboken_module_st_name}=={package_version}"]
setup_kwargs['entry_points'] = {
'console_scripts': [
f'{SHIBOKEN} = {package_name}.scripts.shiboken_tool:main'
@@ -210,7 +210,7 @@ class Config(object):
elif self.internal_build_type == self.pyside_option_name:
setup_kwargs['name'] = self.pyside_st_name
setup_kwargs['description'] = "Python bindings for the Qt cross-platform application and UI framework"
- setup_kwargs['install_requires'] = ["{}=={}".format(self.shiboken_module_st_name, package_version)]
+ setup_kwargs['install_requires'] = [f"{self.shiboken_module_st_name}=={package_version}"]
setup_kwargs['entry_points'] = {
'console_scripts': [
f'{PYSIDE}-uic = {package_name}.scripts.pyside_tool:uic',
@@ -238,7 +238,7 @@ class Config(object):
with open(os.path.join(self.setup_script_dir, readme_filename)) as f:
readme = f.read()
except Exception as e:
- log.error("Couldn't read contents of {}.".format(readme_filename))
+ log.error(f"Couldn't read contents of {readme_filename}. {e}")
raise
# Don't include CHANGES.rst for now, because we have not decided
@@ -249,7 +249,7 @@ class Config(object):
with open(os.path.join(self.setup_script_dir, changes_filename)) as f:
changes = f.read()
except Exception as e:
- log.error("Couldn't read contents of {}".format(changes_filename))
+ log.error(f"Couldn't read contents of {changes_filename}. {e}")
raise
content += readme
diff --git a/build_scripts/main.py b/build_scripts/main.py
index 773460de1..1d79621c8 100644
--- a/build_scripts/main.py
+++ b/build_scripts/main.py
@@ -94,9 +94,9 @@ def _get_make(platform_arch, build_type):
if not OPTION["NO_JOM"]:
jom_path = find_executable("jom")
if jom_path:
- log.info("jom was found in {}".format(jom_path))
+ log.info(f"jom was found in {jom_path}")
return (jom_path, "NMake Makefiles JOM")
- log.info("nmake was found in {}".format(nmake_path))
+ log.info(f"nmake was found in {nmake_path}")
if OPTION["JOBS"]:
msg = "Option --jobs can only be used with 'jom' on Windows."
raise DistutilsSetupError(msg)
@@ -105,8 +105,7 @@ def _get_make(platform_arch, build_type):
return ("mingw32-make", "mingw32-make")
if makespec == "ninja":
return ("ninja", "Ninja")
- m = 'Invalid option --make-spec "{}".'.format(makespec)
- raise DistutilsSetupError(m)
+ raise DistutilsSetupError(f'Invalid option --make-spec "{makespec}".')
def get_make(platform_arch, build_type):
@@ -136,11 +135,10 @@ def _get_py_library_win(build_type, py_version, py_prefix, py_libdir,
raise DistutilsSetupError("Failed to locate the 'libs' directory")
dbg_postfix = "_d" if build_type == "Debug" else ""
if OPTION["MAKESPEC"] == "mingw":
- static_lib_name = "libpython{}{}.a".format(
- py_version.replace(".", ""), dbg_postfix)
+ static_lib_name = f"libpython{py_version.replace('.', '')}{dbg_postfix}.a"
return os.path.join(py_libdir, static_lib_name)
v = py_version.replace(".", "")
- python_lib_name = "python{}{}.lib".format(v, dbg_postfix)
+ python_lib_name = f"python{v}{dbg_postfix}.lib"
return os.path.join(py_libdir, python_lib_name)
@@ -150,7 +148,7 @@ def _get_py_library_unix(build_type, py_version, py_prefix, py_libdir,
if py_libdir is None or not os.path.exists(py_libdir):
py_libdir = os.path.join(py_prefix, "lib")
if py_include_dir is None or not os.path.exists(py_include_dir):
- dir = "include/python{}".format(py_version)
+ dir = f"include/python{py_version}"
py_include_dir = os.path.join(py_prefix, dir)
dbg_postfix = "_d" if build_type == "Debug" else ""
lib_exts = ['.so']
@@ -165,7 +163,7 @@ def _get_py_library_unix(build_type, py_version, py_prefix, py_libdir,
libs_tried = []
for lib_ext in lib_exts:
- lib_name = "libpython{}{}{}".format(py_version, lib_suff, lib_ext)
+ lib_name = f"libpython{py_version}{lib_suff}{lib_ext}"
py_library = os.path.join(py_libdir, lib_name)
if os.path.exists(py_library):
return py_library
@@ -178,14 +176,13 @@ def _get_py_library_unix(build_type, py_version, py_prefix, py_libdir,
try_py_libdir = os.path.join(py_libdir, py_multiarch)
libs_tried = []
for lib_ext in lib_exts:
- lib_name = "libpython{}{}{}".format(py_version, lib_suff, lib_ext)
+ lib_name = f"libpython{py_version}{lib_suff}{lib_ext}"
py_library = os.path.join(try_py_libdir, lib_name)
if os.path.exists(py_library):
return py_library
libs_tried.append(py_library)
- m = "Failed to locate the Python library with {}".format(", ".join(libs_tried))
- raise DistutilsSetupError(m)
+ raise DistutilsSetupError(f"Failed to locate the Python library with {', '.join(libs_tried)}")
def get_py_library(build_type, py_version, py_prefix, py_libdir, py_include_dir):
@@ -198,7 +195,7 @@ def get_py_library(build_type, py_version, py_prefix, py_libdir, py_include_dir)
py_libdir, py_include_dir)
if py_library.endswith('.a'):
# Python was compiled as a static library
- log.error("Failed to locate a dynamic Python library, using {}".format(py_library))
+ log.error(f"Failed to locate a dynamic Python library, using {py_library}")
return py_library
@@ -316,7 +313,7 @@ def prepare_build():
for n in ["build"]:
d = os.path.join(setup_script_dir, n)
if os.path.isdir(d):
- log.info("Removing {}".format(d))
+ log.info(f"Removing {d}")
try:
rmtree(d)
except Exception as e:
@@ -422,7 +419,7 @@ class PysideInstallLib(_install_lib):
# Using our own copydir makes sure to preserve symlinks.
outfiles = copydir(os.path.abspath(self.build_dir), os.path.abspath(self.install_dir))
else:
- self.warn("'{}' does not exist -- no Python modules to install".format(self.build_dir))
+ self.warn(f"'{self.build_dir}' does not exist -- no Python modules to install")
return
return outfiles
@@ -474,7 +471,7 @@ class PysideBuild(_build, DistUtilsCommandMixin):
def run(self):
prepare_build()
platform_arch = platform.architecture()[0]
- log.info("Python architecture is {}".format(platform_arch))
+ log.info(f"Python architecture is {platform_arch}")
self.py_arch = platform_arch[:-3]
build_type = "Debug" if OPTION["DEBUG"] else "Release"
@@ -489,7 +486,7 @@ class PysideBuild(_build, DistUtilsCommandMixin):
# Prepare parameters
py_executable = sys.executable
- py_version = "{}.{}".format(sys.version_info[0], sys.version_info[1])
+ py_version = f"{sys.version_info[0]}.{sys.version_info[1]}"
py_include_dir = get_config_var("INCLUDEPY")
py_libdir = get_config_var("LIBDIR")
py_prefix = get_config_var("prefix")
@@ -517,8 +514,7 @@ class PysideBuild(_build, DistUtilsCommandMixin):
if clang_dir[0]:
clangBinDir = os.path.join(clang_dir[0], 'bin')
if clangBinDir not in os.environ.get('PATH'):
- log.info("Adding {} as detected by {} to PATH".format(clangBinDir,
- clang_dir[1]))
+ log.info(f"Adding {clangBinDir} as detected by {clang_dir[1]} to PATH")
additional_paths.append(clangBinDir)
else:
raise DistutilsSetupError("Failed to detect Clang when checking "
@@ -527,18 +523,18 @@ class PysideBuild(_build, DistUtilsCommandMixin):
update_env_path(additional_paths)
# Used for test blacklists and registry test.
- self.build_classifiers = "py{}-qt{}-{}-{}".format(py_version, qt_version,
- platform.architecture()[0],
- build_type.lower())
+ self.build_classifiers = (f"py{py_version}-qt{qt_version}-{platform.architecture()[0]}-"
+ f"{build_type.lower()}")
+
if OPTION["SHORTER_PATHS"]:
- build_name = "p{}".format(py_version)
+ build_name = f"p{py_version}"
else:
build_name = self.build_classifiers
script_dir = setup_script_dir
sources_dir = os.path.join(script_dir, "sources")
- build_dir = os.path.join(script_dir, prefix() + "_build", "{}".format(build_name))
- install_dir = os.path.join(script_dir, prefix() + "_install", "{}".format(build_name))
+ build_dir = os.path.join(script_dir, f"{prefix()}_build", f"{build_name}")
+ install_dir = os.path.join(script_dir, f"{prefix()}_install", f"{build_name}")
self.make_path = make_path
self.make_generator = make_generator
@@ -564,13 +560,13 @@ class PysideBuild(_build, DistUtilsCommandMixin):
# Prepare folders
if not os.path.exists(self.sources_dir):
- log.info("Creating sources folder {}...".format(self.sources_dir))
+ log.info(f"Creating sources folder {self.sources_dir}...")
os.makedirs(self.sources_dir)
if not os.path.exists(self.build_dir):
- log.info("Creating build folder {}...".format(self.build_dir))
+ log.info(f"Creating build folder {self.build_dir}...")
os.makedirs(self.build_dir)
if not os.path.exists(self.install_dir):
- log.info("Creating install folder {}...".format(self.install_dir))
+ log.info(f"Creating install folder {self.install_dir}...")
os.makedirs(self.install_dir)
if (not OPTION["ONLYPACKAGE"]
@@ -590,7 +586,7 @@ class PysideBuild(_build, DistUtilsCommandMixin):
with open(fpath, 'w') as f:
print(build_dir, file=f)
print(self.build_classifiers, file=f)
- log.info("Created {}".format(build_history))
+ log.info(f"Created {build_history}")
if not OPTION["SKIP_PACKAGING"]:
# Build patchelf if needed
@@ -613,57 +609,53 @@ class PysideBuild(_build, DistUtilsCommandMixin):
if OPTION["FINAL_INSTALL_PREFIX"]:
setuptools_install_prefix = OPTION["FINAL_INSTALL_PREFIX"]
log.info("=" * 30)
- log.info("Package version: {}".format(get_package_version()))
- log.info("Build type: {}".format(self.build_type))
- log.info("Build tests: {}".format(self.build_tests))
+ log.info(f"Package version: {get_package_version()}")
+ log.info(f"Build type: {self.build_type}")
+ log.info(f"Build tests: {self.build_tests}")
log.info("-" * 3)
- log.info("Make path: {}".format(self.make_path))
- log.info("Make generator: {}".format(self.make_generator))
- log.info("Make jobs: {}".format(OPTION["JOBS"]))
+ log.info(f"Make path: {self.make_path}")
+ log.info(f"Make generator: {self.make_generator}")
+ log.info(f"Make jobs: {OPTION['JOBS']}")
log.info("-" * 3)
- log.info("setup.py directory: {}".format(self.script_dir))
- log.info("Build scripts directory: {}".format(build_scripts_dir))
- log.info("Sources directory: {}".format(self.sources_dir))
- log.info(dedent("""
- Building {st_package_name} will create and touch directories
+ log.info(f"setup.py directory: {self.script_dir}")
+ log.info(f"Build scripts directory: {build_scripts_dir}")
+ log.info(f"Sources directory: {self.sources_dir}")
+ log.info(dedent(f"""
+ Building {config.package_name()} will create and touch directories
in the following order:
make build directory (py*_build/*/*) ->
make install directory (py*_install/*/*) ->
setuptools build directory (build/*/*) ->
setuptools install directory
(usually path-installed-python/lib/python*/site-packages/*)
- """).format(st_package_name=config.package_name()))
- log.info("make build directory: {}".format(self.build_dir))
- log.info("make install directory: {}".format(self.install_dir))
- log.info("setuptools build directory: {}".format(self.st_build_dir))
- log.info("setuptools install directory: {}".format(setuptools_install_prefix))
- log.info(dedent("""
- make-installed site-packages directory: {}
+ """))
+ log.info(f"make build directory: {self.build_dir}")
+ log.info(f"make install directory: {self.install_dir}")
+ log.info(f"setuptools build directory: {self.st_build_dir}")
+ log.info(f"setuptools install directory: {setuptools_install_prefix}")
+ log.info(dedent(f"""
+ make-installed site-packages directory: {self.site_packages_dir}
(only relevant for copying files from 'make install directory'
to 'setuptools build directory'
- """).format(
- self.site_packages_dir))
+ """))
log.info("-" * 3)
- log.info("Python executable: {}".format(self.py_executable))
- log.info("Python includes: {}".format(self.py_include_dir))
- log.info("Python library: {}".format(self.py_library))
- log.info("Python prefix: {}".format(self.py_prefix))
- log.info("Python scripts: {}".format(self.py_scripts_dir))
+ log.info(f"Python executable: {self.py_executable}")
+ log.info(f"Python includes: {self.py_include_dir}")
+ log.info(f"Python library: {self.py_library}")
+ log.info(f"Python prefix: {self.py_prefix}")
+ log.info(f"Python scripts: {self.py_scripts_dir}")
log.info("-" * 3)
- log.info("Qt qmake: {}".format(self.qtinfo.qmake_command))
- log.info("Qt version: {}".format(self.qtinfo.version))
- log.info("Qt bins: {}".format(self.qtinfo.bins_dir))
- log.info("Qt docs: {}".format(self.qtinfo.docs_dir))
- log.info("Qt plugins: {}".format(self.qtinfo.plugins_dir))
+ log.info(f"Qt qmake: {self.qtinfo.qmake_command}")
+ log.info(f"Qt version: {self.qtinfo.version}")
+ log.info(f"Qt bins: {self.qtinfo.bins_dir}")
+ log.info(f"Qt docs: {self.qtinfo.docs_dir}")
+ log.info(f"Qt plugins: {self.qtinfo.plugins_dir}")
log.info("-" * 3)
if sys.platform == 'win32':
- log.info("OpenSSL dll directory: {}".format(OPTION["OPENSSL"]))
+ log.info(f"OpenSSL dll directory: {OPTION['OPENSSL']}")
if sys.platform == 'darwin':
- pyside_macos_deployment_target = (
- macos_pyside_min_deployment_target()
- )
- log.info("MACOSX_DEPLOYMENT_TARGET set to: {}".format(
- pyside_macos_deployment_target))
+ pyside_macos_deployment_target = (macos_pyside_min_deployment_target())
+ log.info(f"MACOSX_DEPLOYMENT_TARGET set to: {pyside_macos_deployment_target}")
log.info("=" * 30)
def build_patchelf(self):
@@ -673,11 +665,11 @@ class PysideBuild(_build, DistUtilsCommandMixin):
if self._patchelf_path:
if not os.path.isabs(self._patchelf_path):
self._patchelf_path = os.path.join(os.getcwd(), self._patchelf_path)
- log.info("Using {} ...".format(self._patchelf_path))
+ log.info(f"Using {self._patchelf_path} ...")
return
log.info("Building patchelf...")
module_src_dir = os.path.join(self.sources_dir, "patchelf")
- build_cmd = ["g++", "{}/patchelf.cc".format(module_src_dir), "-o", "patchelf"]
+ build_cmd = ["g++", f"{module_src_dir}/patchelf.cc", "-o", "patchelf"]
if run_process(build_cmd) != 0:
raise DistutilsSetupError("Error building patchelf")
self._patchelf_path = os.path.join(self.script_dir, "patchelf")
@@ -685,29 +677,29 @@ class PysideBuild(_build, DistUtilsCommandMixin):
def build_extension(self, extension):
# calculate the subrepos folder name
- log.info("Building module {}...".format(extension))
+ log.info(f"Building module {extension}...")
# Prepare folders
os.chdir(self.build_dir)
module_build_dir = os.path.join(self.build_dir, extension)
- skipflag_file = "{} -skip".format(module_build_dir)
+ skipflag_file = f"{module_build_dir} -skip"
if os.path.exists(skipflag_file):
- log.info("Skipping {} because {} exists".format(extension, skipflag_file))
+ log.info(f"Skipping {extension} because {skipflag_file} exists")
return
module_build_exists = os.path.exists(module_build_dir)
if module_build_exists:
if not OPTION["REUSE_BUILD"]:
- log.info("Deleting module build folder {}...".format(module_build_dir))
+ log.info(f"Deleting module build folder {module_build_dir}...")
try:
rmtree(module_build_dir)
except Exception as e:
- print('***** problem removing "{}"'.format(module_build_dir))
- print('ignored error: {}'.format(e))
+ log.error(f'***** problem removing "{module_build_dir}"')
+ log.error(f'ignored error: {e}')
else:
- log.info("Reusing module build folder {}...".format(module_build_dir))
+ log.info(f"Reusing module build folder {module_build_dir}...")
if not os.path.exists(module_build_dir):
- log.info("Creating module build folder {}...".format(module_build_dir))
+ log.info(f"Creating module build folder {module_build_dir}...")
os.makedirs(module_build_dir)
os.chdir(module_build_dir)
@@ -726,15 +718,15 @@ class PysideBuild(_build, DistUtilsCommandMixin):
cmake_cmd += [
"-G", self.make_generator,
- "-DBUILD_TESTS={}".format(self.build_tests),
- "-DQt5Help_DIR={}".format(self.qtinfo.docs_dir),
- "-DCMAKE_BUILD_TYPE={}".format(self.build_type),
- "-DCMAKE_INSTALL_PREFIX={}".format(self.install_dir),
+ f"-DBUILD_TESTS={self.build_tests}",
+ f"-DQt5Help_DIR={self.qtinfo.docs_dir}",
+ f"-DCMAKE_BUILD_TYPE={self.build_type}",
+ f"-DCMAKE_INSTALL_PREFIX={self.install_dir}",
module_src_dir
]
- cmake_cmd.append("-DPYTHON_EXECUTABLE={}".format(self.py_executable))
- cmake_cmd.append("-DPYTHON_INCLUDE_DIR={}".format(self.py_include_dir))
- cmake_cmd.append("-DPYTHON_LIBRARY={}".format(self.py_library))
+ cmake_cmd.append(f"-DPYTHON_EXECUTABLE={self.py_executable}")
+ cmake_cmd.append(f"-DPYTHON_INCLUDE_DIR={self.py_include_dir}")
+ cmake_cmd.append(f"-DPYTHON_LIBRARY={self.py_library}")
# If a custom shiboken cmake config directory path was provided, pass it to CMake.
if OPTION["SHIBOKEN_CONFIG_DIR"] and config.is_internal_pyside_build():
@@ -754,7 +746,7 @@ class PysideBuild(_build, DistUtilsCommandMixin):
if module_sub_set:
module_sub_set += ';'
module_sub_set += m
- cmake_cmd.append("-DMODULES={}".format(module_sub_set))
+ cmake_cmd.append(f"-DMODULES={module_sub_set}")
if OPTION["SKIP_MODULES"]:
skip_modules = ''
for m in OPTION["SKIP_MODULES"].split(','):
@@ -763,15 +755,14 @@ class PysideBuild(_build, DistUtilsCommandMixin):
if skip_modules:
skip_modules += ';'
skip_modules += m
- cmake_cmd.append("-DSKIP_MODULES={}".format(skip_modules))
+ cmake_cmd.append(f"-DSKIP_MODULES={skip_modules}")
# Add source location for generating documentation
cmake_src_dir = OPTION["QT_SRC"] if OPTION["QT_SRC"] else qt_src_dir
- cmake_cmd.append("-DQT_SRC_DIR={}".format(cmake_src_dir))
- log.info("Qt Source dir: {}".format(cmake_src_dir))
+ cmake_cmd.append(f"-DQT_SRC_DIR={cmake_src_dir}")
+ log.info(f"Qt Source dir: {cmake_src_dir}")
if self.build_type.lower() == 'debug':
- cmake_cmd.append("-DPYTHON_DEBUG_LIBRARY={}".format(
- self.py_library))
+ cmake_cmd.append(f"-DPYTHON_DEBUG_LIBRARY={self.py_library}")
if OPTION["LIMITED_API"] == "yes":
cmake_cmd.append("-DFORCE_LIMITED_API=yes")
@@ -803,13 +794,12 @@ class PysideBuild(_build, DistUtilsCommandMixin):
pyside_qt_conf_prefix = '"Qt"'
if sys.platform == 'win32':
pyside_qt_conf_prefix = '"."'
- cmake_cmd.append("-DPYSIDE_QT_CONF_PREFIX={}".format(
- pyside_qt_conf_prefix))
+ cmake_cmd.append(f"-DPYSIDE_QT_CONF_PREFIX={pyside_qt_conf_prefix}")
# Pass package version to CMake, so this string can be
# embedded into _config.py file.
package_version = get_package_version()
- cmake_cmd.append("-DPACKAGE_SETUP_PY_PACKAGE_VERSION={}".format(package_version))
+ cmake_cmd.append(f"-DPACKAGE_SETUP_PY_PACKAGE_VERSION={package_version}")
# In case if this is a snapshot build, also pass the
# timestamp as a separate value, because it is the only
@@ -817,7 +807,7 @@ class PysideBuild(_build, DistUtilsCommandMixin):
timestamp = ''
if OPTION["SNAPSHOT_BUILD"]:
timestamp = get_package_timestamp()
- cmake_cmd.append("-DPACKAGE_SETUP_PY_PACKAGE_TIMESTAMP={}".format(timestamp))
+ cmake_cmd.append(f"-DPACKAGE_SETUP_PY_PACKAGE_TIMESTAMP={timestamp}")
if extension.lower() in [SHIBOKEN]:
cmake_cmd.append("-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=yes")
@@ -826,7 +816,7 @@ class PysideBuild(_build, DistUtilsCommandMixin):
if sys.platform == 'darwin':
if OPTION["MACOS_ARCH"]:
# also tell cmake which architecture to use
- cmake_cmd.append("-DCMAKE_OSX_ARCHITECTURES:STRING={}".format(OPTION["MACOS_ARCH"]))
+ cmake_cmd.append(f"-DCMAKE_OSX_ARCHITECTURES:STRING={OPTION['MACOS_ARCH']}")
if OPTION["MACOS_USE_LIBCPP"]:
# Explicitly link the libc++ standard library (useful
@@ -840,15 +830,13 @@ class PysideBuild(_build, DistUtilsCommandMixin):
cmake_cmd.append("-DOSX_USE_LIBCPP=ON")
if OPTION["MACOS_SYSROOT"]:
- cmake_cmd.append("-DCMAKE_OSX_SYSROOT={}".format(
- OPTION["MACOS_SYSROOT"]))
+ cmake_cmd.append(f"-DCMAKE_OSX_SYSROOT={OPTION['MACOS_SYSROOT']}")
else:
latest_sdk_path = run_process_output(['xcrun', '--sdk', 'macosx',
'--show-sdk-path'])
if latest_sdk_path:
latest_sdk_path = latest_sdk_path[0]
- cmake_cmd.append("-DCMAKE_OSX_SYSROOT={}".format(
- latest_sdk_path))
+ cmake_cmd.append(f"-DCMAKE_OSX_SYSROOT={latest_sdk_path}")
# Set macOS minimum deployment target (version).
# This is required so that calling
@@ -859,7 +847,7 @@ class PysideBuild(_build, DistUtilsCommandMixin):
# Doing so could break the detected clang include paths
# for example.
deployment_target = macos_pyside_min_deployment_target()
- cmake_cmd.append("-DCMAKE_OSX_DEPLOYMENT_TARGET={}".format(deployment_target))
+ cmake_cmd.append(f"-DCMAKE_OSX_DEPLOYMENT_TARGET={deployment_target}")
os.environ['MACOSX_DEPLOYMENT_TARGET'] = deployment_target
elif sys.platform == 'win32':
# Prevent cmake from auto-detecting clang if it is in path.
@@ -877,19 +865,18 @@ class PysideBuild(_build, DistUtilsCommandMixin):
cmake_cmd.append("-DFULLDOCSBUILD=1")
if not OPTION["SKIP_CMAKE"]:
- log.info("Configuring module {} ({})...".format(extension, module_src_dir))
+ log.info(f"Configuring module {extension} ({module_src_dir})...")
if run_process(cmake_cmd) != 0:
- raise DistutilsSetupError("Error configuring {}".format(extension))
+ raise DistutilsSetupError(f"Error configuring {extension}")
else:
- log.info("Reusing old configuration for module {} ({})...".format(
- extension, module_src_dir))
+ log.info(f"Reusing old configuration for module {extension} ({module_src_dir})...")
- log.info("-- Compiling module {}...".format(extension))
+ log.info(f"-- Compiling module {extension}...")
cmd_make = [self.make_path]
if OPTION["JOBS"]:
cmd_make.append(OPTION["JOBS"])
if run_process(cmd_make) != 0:
- raise DistutilsSetupError("Error compiling {}".format(extension))
+ raise DistutilsSetupError(f"Error compiling {extension}")
if not OPTION["SKIP_DOCS"]:
if extension.lower() == SHIBOKEN:
@@ -900,14 +887,14 @@ class PysideBuild(_build, DistUtilsCommandMixin):
log.info("Generating Shiboken documentation")
if run_process([self.make_path, "doc"]) != 0:
raise DistutilsSetupError("Error generating documentation "
- "for {}".format(extension))
+ f"for {extension}")
except ImportError:
log.info("Sphinx not found, skipping documentation build")
else:
log.info("Skipped documentation generation")
if not OPTION["SKIP_MAKE_INSTALL"]:
- log.info("Installing module {}...".format(extension))
+ log.info(f"Installing module {extension}...")
# Need to wait a second, so installed file timestamps are
# older than build file timestamps.
# See https://gitlab.kitware.com/cmake/cmake/issues/16155
@@ -918,10 +905,9 @@ class PysideBuild(_build, DistUtilsCommandMixin):
# ninja: error: unknown target 'install/fast'
target = 'install/fast' if self.make_generator != 'Ninja' else 'install'
if run_process([self.make_path, target]) != 0:
- raise DistutilsSetupError("Error pseudo installing {}".format(
- extension))
+ raise DistutilsSetupError(f"Error pseudo installing {extension}")
else:
- log.info("Skipped installing module {}".format(extension))
+ log.info(f"Skipped installing module {extension}")
os.chdir(self.script_dir)
@@ -1058,8 +1044,8 @@ class PysideBuild(_build, DistUtilsCommandMixin):
if os.path.exists(clang_lib_path):
basename = os.path.basename(clang_lib_path)
- log.info('Copying libclang shared library {} to the package folder as {}.'.format(
- clang_lib_path, basename))
+ log.info(f"Copying libclang shared library {clang_lib_path} to the package "
+ f"folder as {basename}.")
destination_path = os.path.join(destination_dir, basename)
# Need to modify permissions in case file is not writable
@@ -1070,7 +1056,7 @@ class PysideBuild(_build, DistUtilsCommandMixin):
make_writable_by_owner=True)
else:
raise RuntimeError("Error copying libclang library "
- "from {} to {}. ".format(clang_lib_path, destination_dir))
+ f"from {clang_lib_path} to {destination_dir}. ")
def update_rpath(self, package_path, executables):
if sys.platform.startswith('linux'):
@@ -1111,7 +1097,7 @@ class PysideBuild(_build, DistUtilsCommandMixin):
macos_fix_rpaths_for_library(srcpath, final_rpath)
else:
- raise RuntimeError('Not configured for platform {}'.format(sys.platform))
+ raise RuntimeError(f"Not configured for platform {sys.platform}")
pyside_libs.extend(executables)
@@ -1124,7 +1110,7 @@ class PysideBuild(_build, DistUtilsCommandMixin):
continue
rpath_cmd(srcpath)
log.info("Patched rpath to '$ORIGIN/' (Linux) or "
- "updated rpath (OS/X) in {}.".format(srcpath))
+ f"updated rpath (OS/X) in {srcpath}.")
class PysideRstDocs(Command, DistUtilsCommandMixin):
@@ -1172,8 +1158,8 @@ class PysideRstDocs(Command, DistUtilsCommandMixin):
# 'pyside6' directory
elif self.name == PYSIDE:
self.out_dir = os.path.join(self.html_dir, PYSIDE)
- except:
- raise DistutilsSetupError("Error while creating directories for {}".format(self.doc_dir))
+ except (PermissionError, FileExistsError):
+ raise DistutilsSetupError(f"Error while creating directories for {self.doc_dir}")
def run(self):
if not self.skip:
@@ -1185,7 +1171,7 @@ class PysideRstDocs(Command, DistUtilsCommandMixin):
"-DFULLDOCSBUILD=0",
]
if run_process(cmake_cmd) != 0:
- raise DistutilsSetupError("Error running CMake for {}".format(self.doc_dir))
+ raise DistutilsSetupError(f"Error running CMake for {self.doc_dir}")
if self.name == PYSIDE:
self.sphinx_src = os.path.join(self.out_dir, "rst")
@@ -1195,7 +1181,7 @@ class PysideRstDocs(Command, DistUtilsCommandMixin):
sphinx_cmd = ["sphinx-build", "-b", "html", "-c", self.sphinx_src,
self.doc_dir, self.out_dir]
if run_process(sphinx_cmd) != 0:
- raise DistutilsSetupError("Error running CMake for {}".format(self.doc_dir))
+ raise DistutilsSetupError(f"Error running CMake for {self.doc_dir}")
# Last message
if not self.skip and self.name == PYSIDE:
log.info(f"-- The documentation was built. Check html/{PYSIDE}/index.html")
diff --git a/build_scripts/options.py b/build_scripts/options.py
index ab45c915c..d7f878519 100644
--- a/build_scripts/options.py
+++ b/build_scripts/options.py
@@ -60,13 +60,13 @@ Additional options:
def _warn_multiple_option(option):
- warnings.warn('Option "{}" occurs multiple times on the command line.'.format(option))
+ warnings.warn(f'Option "{option}" occurs multiple times on the command line.')
def _warn_deprecated_option(option, replacement=None):
- w = 'Option "{}" is deprecated and may be removed in a future release.'.format(option)
+ w = f'Option "{option}" is deprecated and may be removed in a future release.'
if replacement:
- w = '{}\nUse "{}" instead.'.format(w, replacement)
+ w = f'{w}\nUse "{replacement}" instead.'
warnings.warn(w)
@@ -79,12 +79,12 @@ class Options(object):
def has_option(self, name, remove=True):
""" Returns True if argument '--name' was passed on the command
line. """
- option = '--{}'.format(name)
+ option = f"--{name}"
count = sys.argv.count(option)
remove_count = count
if not remove and count > 0:
remove_count -= 1
- for i in range(remove_count):
+ for _ in range(remove_count):
sys.argv.remove(option)
if count > 1:
_warn_multiple_option(option)
@@ -115,7 +115,7 @@ class Options(object):
_warn_multiple_option(option)
else:
if index + 1 >= len(sys.argv):
- raise RuntimeError("The option {} requires a value".format(option))
+ raise RuntimeError(f"The option {option} requires a value")
value = sys.argv[index + 1]
if remove:
diff --git a/build_scripts/platforms/macos.py b/build_scripts/platforms/macos.py
index a3b1df91a..8448929a0 100644
--- a/build_scripts/platforms/macos.py
+++ b/build_scripts/platforms/macos.py
@@ -81,7 +81,7 @@ def prepare_standalone_package_macos(self, vars):
# Patching designer to use the Qt libraries provided in the wheel
if config.is_internal_pyside_build():
designer_bundle = "{st_build_dir}/{st_package_name}/Designer.app".format(**vars)
- designer_binary = "{}/Contents/MacOS/Designer".format(designer_bundle)
+ designer_binary = f"{designer_bundle}/Contents/MacOS/Designer"
rpath = "@loader_path/../../../Qt/lib"
macos_add_rpath(rpath, designer_binary)
diff --git a/build_scripts/platforms/windows_desktop.py b/build_scripts/platforms/windows_desktop.py
index a17f1da6a..a6c59b16a 100644
--- a/build_scripts/platforms/windows_desktop.py
+++ b/build_scripts/platforms/windows_desktop.py
@@ -384,7 +384,7 @@ def copy_qt_artifacts(self, copy_pdbs, vars):
# e.g. "/home/work/qt/qtbase/bin"
file_path_dir_name = os.path.dirname(file_full_path)
# e.g. "Qt6Coredd"
- maybe_debug_name = "{}d".format(file_base_name)
+ maybe_debug_name = f"{file_base_name}d"
if self.debug:
filter = debug
diff --git a/build_scripts/qtinfo.py b/build_scripts/qtinfo.py
index 4ab3b8ede..6c20f3f9d 100644
--- a/build_scripts/qtinfo.py
+++ b/build_scripts/qtinfo.py
@@ -55,7 +55,7 @@ def _effective_qmake_command(qmake, qt_version):
sys.exit(-1)
# Set -qt=X here.
if "qtchooser" in os.readlink(qmake):
- result.append("-qt={}".format(qt_version))
+ result.append(f"-qt={qt_version}")
return result
@@ -74,7 +74,7 @@ class QtInfo(object):
def get_qmake_command(self):
qmake_command_string = self._qmake_command[0]
for entry in self._qmake_command[1:]:
- qmake_command_string += " {}".format(entry)
+ qmake_command_string = f"{qmake_command_string} {entry}"
return qmake_command_string
def get_version(self):
diff --git a/build_scripts/setup_runner.py b/build_scripts/setup_runner.py
index 21e00063b..23eaff3fe 100644
--- a/build_scripts/setup_runner.py
+++ b/build_scripts/setup_runner.py
@@ -76,8 +76,8 @@ class SetupRunner(object):
def construct_cmd_line_argument(name, value=None):
""" Constructs a command line argument given name and value. """
if not value:
- return "--{}".format(name)
- return "--{}={}".format(name, value)
+ return f"--{name}"
+ return f"--{name}={value}"
@staticmethod
def construct_internal_build_type_cmd_line_argument(internal_build_type):
@@ -120,8 +120,8 @@ class SetupRunner(object):
# build.
if config.is_internal_invocation():
if config.internal_build_type not in config.get_allowed_internal_build_values():
- raise RuntimeError("Invalid '{}' option given to --internal-build-type. "
- .format(config.internal_build_type))
+ raise RuntimeError(f"Invalid '{config.internal_build_type}' option given to "
+ "--internal-build-type. ")
self.run_setuptools_setup()
return
@@ -129,8 +129,7 @@ class SetupRunner(object):
# modules we will build and depending on that, call setup.py
# multiple times with different arguments.
if config.build_type not in config.get_allowed_top_level_build_values():
- raise RuntimeError("Invalid '{}' option given to --build-type. "
- .format(config.build_type))
+ raise RuntimeError(f"Invalid '{config.build_type}' option given to --build-type. ")
# Build everything: shiboken6, shiboken6-generator and PySide6.
help_requested = '--help' in self.sub_argv or '-h' in self.sub_argv
@@ -158,13 +157,13 @@ class SetupRunner(object):
for cmd in self.invocations_list:
cmd_as_string = " ".join(cmd)
- log.info("\nRunning setup: {}\n".format(cmd_as_string))
+ log.info(f"\nRunning setup: {cmd_as_string}\n")
exit_code = run_process(cmd)
if exit_code != 0:
- msg = textwrap.dedent("""
- setup.py invocation failed with exit code: {}.\n\n
- setup.py invocation was: {}
- """).format(exit_code, cmd_as_string)
+ msg = textwrap.dedent(f"""
+ setup.py invocation failed with exit code: {exit_code}.\n\n
+ setup.py invocation was: {cmd_as_string}
+ """)
raise RuntimeError(msg)
if help_requested:
diff --git a/build_scripts/utils.py b/build_scripts/utils.py
index 2555c7c7e..8919cff75 100644
--- a/build_scripts/utils.py
+++ b/build_scripts/utils.py
@@ -78,9 +78,9 @@ def update_env_path(newpaths):
paths = os.environ['PATH'].lower().split(os.pathsep)
for path in newpaths:
if not path.lower() in paths:
- log.info("Inserting path '{}' to environment".format(path))
+ log.info(f"Inserting path '{path}' to environment")
paths.insert(0, path)
- os.environ['PATH'] = "{}{}{}".format(path, os.pathsep, os.environ['PATH'])
+ os.environ['PATH'] = f"{path}{os.pathsep}{os.environ['PATH']}"
def winsdk_setenv(platform_arch, build_type):
@@ -97,13 +97,13 @@ def winsdk_setenv(platform_arch, build_type):
"v7.1": 10.0
}
- log.info("Searching Windows SDK with MSVC compiler version {}".format(MSVC_VERSION))
+ log.info(f"Searching Windows SDK with MSVC compiler version {MSVC_VERSION}")
setenv_paths = []
for base in HKEYS:
sdk_versions = Reg.read_keys(base, WINSDK_BASE)
if sdk_versions:
for sdk_version in sdk_versions:
- installationfolder = Reg.get_value("{}\\{}".format(WINSDK_BASE, sdk_version),
+ installationfolder = Reg.get_value(f"{WINSDK_BASE}\\{sdk_version}",
"installationfolder")
# productversion = Reg.get_value("{}\\{}".format(WINSDK_BASE, sdk_version),
# "productversion")
@@ -117,13 +117,13 @@ def winsdk_setenv(platform_arch, build_type):
setenv_paths.append(setenv_path)
if len(setenv_paths) == 0:
raise DistutilsSetupError("Failed to find the Windows SDK with MSVC compiler "
- "version {}".format(MSVC_VERSION))
+ f"version {MSVC_VERSION}")
for setenv_path in setenv_paths:
- log.info("Found {}".format(setenv_path))
+ log.info(f"Found {setenv_path}")
# Get SDK env (use latest SDK version installed on system)
setenv_path = setenv_paths[-1]
- log.info("Using {} ".format(setenv_path))
+ log.info(f"Using {setenv_path} ")
build_arch = "/x86" if platform_arch.startswith("32") else "/x64"
build_type = "/Debug" if build_type.lower() == "debug" else "/Release"
setenv_cmd = [setenv_path, build_arch, build_type]
@@ -136,7 +136,7 @@ def winsdk_setenv(platform_arch, build_type):
update_env_path(setenv_env_paths)
for k in sorted(setenv_env_without_paths):
v = setenv_env_without_paths[k]
- log.info("Inserting '{} = {}' to environment".format(k, v))
+ log.info(f"Inserting '{k} = {v}' to environment")
os.environ[k] = v
log.info("Done initializing Windows SDK env")
@@ -150,7 +150,7 @@ def find_vcdir(version):
from distutils.msvc9compiler import Reg
vsbase = VS_BASE % version
try:
- productdir = Reg.get_value(r"{}\Setup\VC".format(vsbase), "productdir")
+ productdir = Reg.get_value(rf"{vsbase}\Setup\VC", "productdir")
except KeyError:
productdir = None
@@ -163,23 +163,23 @@ def find_vcdir(version):
else:
vsbase = VSEXPRESS_BASE % version
try:
- productdir = Reg.get_value(r"{}\Setup\VC".format(vsbase), "productdir")
+ productdir = Reg.get_value(rf"{vsbase}\Setup\VC", "productdir")
except KeyError:
productdir = None
log.debug("Unable to find productdir in registry")
if not productdir or not os.path.isdir(productdir):
- toolskey = "VS{:0.0f}0COMNTOOLS".format(version)
+ toolskey = f"VS{version:0.0f}0COMNTOOLS"
toolsdir = os.environ.get(toolskey, None)
if toolsdir and os.path.isdir(toolsdir):
productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")
productdir = os.path.abspath(productdir)
if not os.path.isdir(productdir):
- log.debug("{} is not a valid directory".format(productdir))
+ log.debug(f"{productdir} is not a valid directory")
return None
else:
- log.debug("Env var {} is not set or invalid".format(toolskey))
+ log.debug(f"Env var {toolskey} is not set or invalid")
if not productdir:
log.debug("No productdir found")
return None
@@ -189,15 +189,15 @@ def find_vcdir(version):
def init_msvc_env(platform_arch, build_type):
from distutils.msvc9compiler import VERSION as MSVC_VERSION
- log.info("Searching MSVC compiler version {}".format(MSVC_VERSION))
+ log.info(f"Searching MSVC compiler version {MSVC_VERSION}")
vcdir_path = find_vcdir(MSVC_VERSION)
if not vcdir_path:
- raise DistutilsSetupError("Failed to find the MSVC compiler version {} on your "
- "system.".format(MSVC_VERSION))
+ raise DistutilsSetupError(f"Failed to find the MSVC compiler version {MSVC_VERSION} on "
+ "your system.")
else:
- log.info("Found {}".format(vcdir_path))
+ log.info(f"Found {vcdir_path}")
- log.info("Searching MSVC compiler {} environment init script".format(MSVC_VERSION))
+ log.info(f"Searching MSVC compiler {MSVC_VERSION} environment init script")
if platform_arch.startswith("32"):
vcvars_path = os.path.join(vcdir_path, "bin", "vcvars32.bat")
else:
@@ -214,12 +214,12 @@ def init_msvc_env(platform_arch, build_type):
winsdk_setenv(platform_arch, build_type)
return
else:
- log.info("Found {}".format(vcvars_path))
+ log.info(f"Found {vcvars_path}")
# Get MSVC env
- log.info("Using MSVC {} in {}".format(MSVC_VERSION, vcvars_path))
+ log.info(f"Using MSVC {MSVC_VERSION} in {vcvars_path}")
msvc_arch = "x86" if platform_arch.startswith("32") else "amd64"
- log.info("Getting MSVC env for {} architecture".format(msvc_arch))
+ log.info(f"Getting MSVC env for {msvc_arch} architecture")
vcvars_cmd = [vcvars_path, msvc_arch]
msvc_env = get_environment_from_batch_command(vcvars_cmd)
msvc_env_paths = os.pathsep.join([msvc_env[k] for k in msvc_env if k.upper() == 'PATH']).split(os.pathsep)
@@ -230,7 +230,7 @@ def init_msvc_env(platform_arch, build_type):
update_env_path(msvc_env_paths)
for k in sorted(msvc_env_without_paths):
v = msvc_env_without_paths[k]
- log.info("Inserting '{} = {}' to environment".format(k, v))
+ log.info(f"Inserting '{k} = {v}' to environment")
os.environ[k] = v
log.info("Done initializing MSVC env")
@@ -242,11 +242,11 @@ def copyfile(src, dst, force=True, vars=None, force_copy_symlink=False,
dst = dst.format(**vars)
if not os.path.exists(src) and not force:
- log.info("**Skiping copy file {} to {}. Source does not exists.".format(src, dst))
+ log.info(f"**Skipping copy file {src} to {dst}. Source does not exists.")
return
if not os.path.islink(src) or force_copy_symlink:
- log.info("Copying file {} to {}.".format(src, dst))
+ log.info(f"Copying file {src} to {dst}.")
shutil.copy2(src, dst)
if make_writable_by_owner:
make_file_writable_by_owner(dst)
@@ -262,15 +262,15 @@ def copyfile(src, dst, force=True, vars=None, force_copy_symlink=False,
os.chdir(target_dir)
if os.path.exists(link_name):
os.remove(link_name)
- log.info("Symlinking {} -> {} in {}.".format(link_name, link_target, target_dir))
+ log.info(f"Symlinking {link_name} -> {link_target} in {target_dir}.")
os.symlink(link_target, link_name)
except OSError:
- log.error("{} -> {}: Error creating symlink".format(link_name, link_target))
+ log.error(f"{link_name} -> {link_target}: Error creating symlink")
finally:
os.chdir(current_directory)
else:
- log.error("{} -> {}: Can only create symlinks within the same "
- "directory".format(src, link_target_path))
+ log.error(f"{src} -> {link_target_path}: Can only create symlinks within the same "
+ "directory")
return dst
@@ -281,7 +281,7 @@ def makefile(dst, content=None, vars=None):
content = content.format(**vars)
dst = dst.format(**vars)
- log.info("Making file {}.".format(dst))
+ log.info(f"Making file {dst}.")
dstdir = os.path.dirname(dst)
if not os.path.exists(dstdir):
@@ -306,11 +306,11 @@ def copydir(src, dst, filter=None, ignore=None, force=True, recursive=True, vars
ignore[i] = ignore[i].format(**vars)
if not os.path.exists(src) and not force:
- log.info("**Skiping copy tree {} to {}. Source does not exists. "
- "filter={}. ignore={}.".format(src, dst, filter, ignore))
+ log.info(f"**Skipping copy tree {src} to {dst}. Source does not exists. "
+ f"filter={filter}. ignore={ignore}.")
return []
- log.info("Copying tree {} to {}. filter={}. ignore={}.".format(src, dst, filter, ignore))
+ log.info(f"Copying tree {src} to {dst}. filter={filter}. ignore={ignore}.")
names = os.listdir(src)
@@ -389,8 +389,8 @@ def run_process(args, initial_env=None):
Run process until completion and return the process exit code.
No output is captured.
"""
- command = " ".join([(" " in x and '"{}"'.format(x) or x) for x in args])
- log.info("In directory {}:\n\tRunning command: {}".format(os.getcwd(), command))
+ command = " ".join([(" " in x and f'"{x}"' or x) for x in args])
+ log.info(f"In directory {os.getcwd()}:\n\tRunning command: {command}")
if initial_env is None:
initial_env = os.environ
@@ -416,7 +416,7 @@ def get_environment_from_batch_command(env_cmd, initial=None):
def validate_pair(ob):
try:
if not (len(ob) == 2):
- print("Unexpected result: {}".format(ob))
+ log.error(f"Unexpected result: {ob}")
raise ValueError
except:
return False
@@ -436,7 +436,7 @@ def get_environment_from_batch_command(env_cmd, initial=None):
# create a tag so we can tell in the output when the proc is done
tag = 'Done running command'
# construct a cmd.exe command to do accomplish this
- cmd = 'cmd.exe /E:ON /V:ON /s /c "{} && echo "{}" && set"'.format(env_cmd, tag)
+ cmd = f'cmd.exe /E:ON /V:ON /s /c "{env_cmd} && echo "{tag}" && set"'
# launch the process
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=initial)
# parse the output sent to stdout
@@ -468,7 +468,7 @@ def regenerate_qt_resources(src, pyside_rcc_path, pyside_rcc_options):
srcname_split = srcname.rsplit('.qrc', 1)
dstname = '_rc.py'.join(srcname_split)
if os.path.exists(dstname):
- log.info('Regenerating {} from {}'.format(dstname, os.path.basename(srcname)))
+ log.info(f"Regenerating {dstname} from {os.path.basename(srcname)}")
run_process([pyside_rcc_path] + pyside_rcc_options + [srcname, '-o', dstname])
@@ -508,10 +508,9 @@ def back_tick(cmd, ret_err=False):
retcode = proc.returncode
if retcode is None and not ret_err:
proc.terminate()
- raise RuntimeError("{} process did not terminate".format(cmd))
+ raise RuntimeError(f"{cmd} process did not terminate")
if retcode != 0 and not ret_err:
- raise RuntimeError("{} process returned code {}\n*** {}".format(
- (cmd, retcode, err)))
+ raise RuntimeError(f"{cmd} process returned code {retcode}\n*** {err}")
out = out.strip()
if not ret_err:
return out
@@ -535,7 +534,7 @@ def macos_get_install_names(libpath):
install_names : list of str
install names in library `libpath`
"""
- out = back_tick("otool -L {}".format(libpath))
+ out = back_tick(f"otool -L {libpath}")
libs = [line for line in out.split('\n')][1:]
return [MACOS_OUTNAME_RE.sub('', lib).strip() for lib in libs]
@@ -560,7 +559,7 @@ def macos_get_rpaths(libpath):
-----
See ``man dyld`` for more information on rpaths in libraries
"""
- lines = back_tick('otool -l {}'.format(libpath)).split('\n')
+ lines = back_tick(f"otool -l {libpath}").split('\n')
ctr = 0
rpaths = []
while ctr < len(lines):
@@ -572,14 +571,14 @@ def macos_get_rpaths(libpath):
rpath_line = lines[ctr + 2].strip()
match = MACOS_RPATH_RE.match(rpath_line)
if match is None:
- raise RuntimeError("Unexpected path line: {}".format(rpath_line))
+ raise RuntimeError(f"Unexpected path line: {rpath_line}")
rpaths.append(match.groups()[0])
ctr += 3
return rpaths
def macos_add_rpath(rpath, library_path):
- back_tick("install_name_tool -add_rpath {} {}".format(rpath, library_path))
+ back_tick(f"install_name_tool -add_rpath {rpath} {library_path}")
def macos_fix_rpaths_for_library(library_path, qt_lib_dir):
@@ -700,29 +699,29 @@ def download_and_extract_7z(fileurl, target):
localfile = None
for i in range(1, 10):
try:
- print("Downloading fileUrl {}, attempt #{}".format(fileurl, i))
+ log.info(f"Downloading fileUrl {fileurl}, attempt #{i}")
localfile, info = urllib.urlretrieve(fileurl)
break
- except:
+ except urllib.URLError:
pass
if not localfile:
- print("Error downloading {} : {}".format(fileurl, info))
- raise RuntimeError(' Error downloading {}'.format(fileurl))
+ log.error(f"Error downloading {fileurl} : {info}")
+ raise RuntimeError(f" Error downloading {fileurl}")
try:
global _7z_binary
- outputDir = "-o{}".format(target)
+ outputDir = f"-o{target}"
if not _7z_binary:
- if sys.platform == 'win32':
- candidate = 'c:\\Program Files\\7-Zip\\7z.exe'
+ if sys.platform == "win32":
+ candidate = "c:\\Program Files\\7-Zip\\7z.exe"
if os.path.exists(candidate):
_7z_binary = candidate
if not _7z_binary:
_7z_binary = '7z'
- print("calling {} x {} {}".format(_7z_binary, localfile, outputDir))
+ log.info(f"calling {_7z_binary} x {localfile} {outputDir}")
subprocess.call([_7z_binary, "x", "-y", localfile, outputDir])
- except:
- raise RuntimeError(' Error extracting {}'.format(localfile))
+ except (subprocess.CalledProcessError, OSError):
+ raise RuntimeError(f"Error extracting {localfile}")
def split_and_strip(sinput):
@@ -819,7 +818,7 @@ def ldd(executable_path):
# Code 127 is returned by ld.so when called without any
# arguments (some kind of sanity check I guess).
if code == 127:
- (_, _, code) = back_tick("{} --verify {}".format(rtld, executable_path), True)
+ (_, _, code) = back_tick(f"{rtld} --verify {executable_path}", True)
# Codes 0 and 2 mean given executable_path can be
# understood by ld.so.
if code in [0, 2]:
@@ -831,13 +830,13 @@ def ldd(executable_path):
# Query for shared library dependencies.
rtld_env = "LD_TRACE_LOADED_OBJECTS=1"
- rtld_cmd = "{} {} {}".format(rtld_env, chosen_rtld, executable_path)
+ rtld_cmd = f"{rtld_env} {chosen_rtld} {executable_path}"
(out, _, return_code) = back_tick(rtld_cmd, True)
if return_code == 0:
return out
else:
raise RuntimeError("ld.so failed to query for dependent shared "
- "libraries of {} ".format(executable_path))
+ f"libraries of {executable_path}")
def find_files_using_glob(path, pattern):
@@ -868,8 +867,8 @@ def copy_icu_libs(patchelf, destination_lib_dir):
qt_core_library_path = find_qt_core_library_glob(destination_lib_dir)
if not qt_core_library_path or not os.path.exists(qt_core_library_path):
- raise RuntimeError('QtCore library does not exist at path: {}. '
- 'Failed to copy ICU libraries.'.format(qt_core_library_path))
+ raise RuntimeError(f"QtCore library does not exist at path: {qt_core_library_path}. "
+ "Failed to copy ICU libraries.")
dependencies = ldd_get_dependencies(qt_core_library_path)
@@ -911,11 +910,11 @@ def copy_icu_libs(patchelf, destination_lib_dir):
def linux_run_read_elf(executable_path):
- cmd = "readelf -d {}".format(executable_path)
+ cmd = f"readelf -d {executable_path}"
(out, err, code) = back_tick(cmd, True)
if code != 0:
- raise RuntimeError("Running `readelf -d {}` failed with error "
- "output:\n {}. ".format(executable_path, err))
+ raise RuntimeError(f"Running `readelf -d {executable_path}` failed with error "
+ f"output:\n {err}. ")
lines = split_and_strip(out)
return lines
@@ -926,7 +925,7 @@ def linux_set_rpaths(patchelf, executable_path, rpath_string):
cmd = [patchelf, '--set-rpath', rpath_string, executable_path]
if run_process(cmd) != 0:
- raise RuntimeError("Error patching rpath in {}".format(executable_path))
+ raise RuntimeError(f"Error patching rpath in {executable_path}")
def linux_get_dependent_libraries(executable_path):
@@ -1046,8 +1045,8 @@ def get_python_dict(python_script_path):
exec(code, {}, python_dict)
return python_dict
except IOError as e:
- print("get_python_dict: Couldn't get dict from python "
- "file: {}.".format(python_script_path))
+ print(f"get_python_dict: Couldn't get dict from python "
+ f"file: {python_script_path}. {e}")
raise
@@ -1056,7 +1055,7 @@ def install_pip_package_from_url_specifier(env_pip, url, upgrade=True):
if upgrade:
args.append("--upgrade")
args.append(url)
- run_instruction(args, "Failed to install {}".format(url))
+ run_instruction(args, f"Failed to install {url}")
def install_pip_dependencies(env_pip, packages, upgrade=True):
@@ -1065,14 +1064,14 @@ def install_pip_dependencies(env_pip, packages, upgrade=True):
if upgrade:
args.append("--upgrade")
args.append(p)
- run_instruction(args, "Failed to install {}".format(p))
+ run_instruction(args, f"Failed to install {p}")
def get_qtci_virtualEnv(python_ver, host, hostArch, targetArch):
_pExe = "python"
- _env = "env{}".format(str(python_ver))
- env_python = _env + "/bin/python"
- env_pip = _env + "/bin/pip"
+ _env = f"env{python_ver}"
+ env_python = f"{_env}/bin/python"
+ env_pip = f"{_env}/bin/pip"
if host == "Windows":
log.info("New virtualenv to build {targetArch} in {hostArch} host")
@@ -1098,8 +1097,8 @@ def get_qtci_virtualEnv(python_ver, host, hostArch, targetArch):
if not os.path.isfile(_pExe):
log.warn(f"Can't find python.exe from {_pExe}, using default python3")
_pExe = os.path.join(os.getenv("PYTHON3_PATH"), "python.exe")
- env_python = _env + "\\Scripts\\python.exe"
- env_pip = _env + "\\Scripts\\pip.exe"
+ env_python = f"{_env}\\Scripts\\python.exe"
+ env_pip = f"{_env}\\Scripts\\pip.exe"
else:
if python_ver == "3":
_pExe = "python3"
@@ -1134,10 +1133,10 @@ def acceptCITestConfiguration(hostOS, hostOSVer, targetArch, compiler):
def get_ci_qmake_path(ci_install_dir, ci_host_os):
- qmake_path = "--qmake={}".format(ci_install_dir)
+ qmake_path = f"--qmake={ci_install_dir}"
if ci_host_os == "MacOS":
- return qmake_path + "/bin/qmake"
+ return f"{qmake_path}/bin/qmake"
elif ci_host_os == "Windows":
- return qmake_path + "\\bin\\qmake.exe"
+ return f"{qmake_path}\\bin\\qmake.exe"
else:
- return qmake_path + "/bin/qmake"
+ return f"{qmake_path}/bin/qmake"
diff --git a/build_scripts/wheel_override.py b/build_scripts/wheel_override.py
index b5e59cfc2..534ae54e9 100644
--- a/build_scripts/wheel_override.py
+++ b/build_scripts/wheel_override.py
@@ -102,7 +102,7 @@ class PysideBuildWheel(_bdist_wheel, DistUtilsCommandMixin):
# PySide6-5.6-5.6.4-cp27-cp27m-macosx_10_10_intel.whl
# The PySide6 version is "5.6".
# The Qt version built against is "5.6.4".
- wheel_version = "{}-{}".format(self._package_version, get_qt_version())
+ wheel_version = f"{self._package_version}-{get_qt_version()}"
components = (_safer_name(self.distribution.get_name()), wheel_version)
if self.build_number:
components += (self.build_number,)
@@ -175,7 +175,7 @@ class PysideBuildWheel(_bdist_wheel, DistUtilsCommandMixin):
# XXX switch to this alternate implementation for non-pure:
if (self.py_limited_api) or (plat_name in ('manylinux1_x86_64')):
return tag
- assert tag in supported_tags, ("would build wheel with unsupported tag {}".format(tag))
+ assert tag in supported_tags, (f"would build wheel with unsupported tag {tag}")
return tag
# Copy of get_tag from bdist_wheel.py, to write a triplet Tag
diff --git a/build_scripts/wheel_utils.py b/build_scripts/wheel_utils.py
index d1d349120..a976e2bce 100644
--- a/build_scripts/wheel_utils.py
+++ b/build_scripts/wheel_utils.py
@@ -65,12 +65,12 @@ def get_qt_version():
qt_version = qtinfo.version
if not qt_version:
- m = "Failed to query the Qt version with qmake {0}".format(qtinfo.qmake_command)
- raise DistutilsSetupError(m)
+ raise DistutilsSetupError("Failed to query the Qt version with "
+ f"qmake {qtinfo.qmake_command}")
if LooseVersion(qtinfo.version) < LooseVersion("5.7"):
- m = "Incompatible Qt version detected: {}. A Qt version >= 5.7 is required.".format(qt_version)
- raise DistutilsSetupError(m)
+ raise DistutilsSetupError(f"Incompatible Qt version detected: {qt_version}. "
+ "A Qt version >= 5.7 is required.")
return qt_version
@@ -82,20 +82,19 @@ def get_package_version():
pyside_version_py = os.path.join(
setup_script_dir, "sources", PYSIDE, "pyside_version.py")
d = get_python_dict(pyside_version_py)
-
- final_version = "{}.{}.{}".format(
- d['major_version'], d['minor_version'], d['patch_version'])
+ final_version = f"{d['major_version']}.{d['minor_version']}.{d['patch_version']}"
release_version_type = d['release_version_type']
pre_release_version = d['pre_release_version']
if pre_release_version and release_version_type:
- final_version += release_version_type + pre_release_version
+ final_version = f"{final_version}{release_version_type}{pre_release_version}"
+
if release_version_type.startswith("comm"):
- final_version += "." + release_version_type
+ final_version = f"{final_version}.{release_version_type}"
# Add the current timestamp to the version number, to suggest it
# is a development snapshot build.
if OPTION["SNAPSHOT_BUILD"]:
- final_version += ".dev{}".format(get_package_timestamp())
+ final_version = f"{final_version}.dev{get_package_timestamp()}"
return final_version
@@ -157,5 +156,5 @@ def macos_plat_name():
deployment_target = macos_pyside_min_deployment_target()
# Example triple "macosx-10.12-x86_64".
plat = get_platform().split("-")
- plat_name = "{}-{}-{}".format(plat[0], deployment_target, plat[2])
+ plat_name = f"{plat[0]}-{deployment_target}-{plat[2]}"
return plat_name