aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristián Maureira-Fredes <Cristian.Maureira-Fredes@qt.io>2022-06-27 23:33:10 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-07-07 05:44:10 +0000
commit87b90b5f5d5d05a84245b2254dd58450ec405434 (patch)
tree3c6df6f03a41de9a4a450e09a98d25db23420e23
parent8b063f5ed084e5885d753eb2f850973e7f6105d6 (diff)
build: fix readability details
Removing some leftover common anti-patterns: - remove unnecessary dict() usage - remove unnecessary map() - avoid index-based loops - use capitalize() instead of index-based capitalization - use f-strings for concatenation Change-Id: I0ffdf73ec47c6ef537789015052dea0fd047350d Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> (cherry picked from commit 39b38b0cfc81d352c60c44efeb890b10c3e1bc88) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--build_scripts/options.py8
-rw-r--r--build_scripts/platforms/macos.py4
-rw-r--r--build_scripts/platforms/unix.py6
-rw-r--r--build_scripts/platforms/windows_desktop.py6
-rw-r--r--build_scripts/qp5_tool.py6
-rw-r--r--build_scripts/utils.py14
6 files changed, 21 insertions, 23 deletions
diff --git a/build_scripts/options.py b/build_scripts/options.py
index 80b92e887..f044a270d 100644
--- a/build_scripts/options.py
+++ b/build_scripts/options.py
@@ -117,9 +117,9 @@ class Options(object):
:return: Either the option value or None.
"""
- option = '--' + name
- short_option = '-' + short_option_name if short_option_name else None
- single_option_prefix = option + '='
+ option = f"--{name}"
+ short_option = f"-{short_option_name}" if short_option_name else None
+ single_option_prefix = f"{option}="
value = None
for index in reversed(range(len(sys.argv))):
arg = sys.argv[index]
@@ -165,7 +165,7 @@ def _jobs_option_value():
"""Option value for parallel builds."""
value = option_value('parallel', short_option_name='j')
if value:
- return '-j' + value if not value.startswith('-j') else value
+ return f"-j{value}" if not value.startswith('-j') else value
return ''
diff --git a/build_scripts/platforms/macos.py b/build_scripts/platforms/macos.py
index 0f615991c..69c2a436c 100644
--- a/build_scripts/platforms/macos.py
+++ b/build_scripts/platforms/macos.py
@@ -48,7 +48,7 @@ from ..versions import PYSIDE
def _macos_patch_executable(name, _vars=None):
""" Patch an executable to run with the Qt libraries. """
- upper_name = name[0:1].upper() + name[1:]
+ upper_name = name.capitalize()
bundle = f"{{st_build_dir}}/{{st_package_name}}/{upper_name}.app".format(**_vars)
binary = f"{bundle}/Contents/MacOS/{upper_name}"
rpath = "@loader_path/../../../Qt/lib"
@@ -66,7 +66,7 @@ def prepare_standalone_package_macos(self, _vars):
if config.is_internal_shiboken_generator_build():
constrain_modules = ["Core", "Network", "Xml", "XmlPatterns"]
- constrain_frameworks = ['Qt' + name + '.framework' for name in constrain_modules]
+ constrain_frameworks = [f"Qt{name}.framework" for name in constrain_modules]
copy_plugins = False
copy_qml = False
copy_translations = False
diff --git a/build_scripts/platforms/unix.py b/build_scripts/platforms/unix.py
index dd7a1510d..904ae9c0e 100644
--- a/build_scripts/platforms/unix.py
+++ b/build_scripts/platforms/unix.py
@@ -52,7 +52,7 @@ from .macos import prepare_standalone_package_macos
def _macos_copy_gui_executable(name, _vars=None):
"""macOS helper: Copy a GUI executable from the .app folder and return the
files"""
- app_name = name[:1].upper() + name[1:] + '.app'
+ app_name = f"{name.capitalize()}.app"
return copydir(f"{{install_dir}}/bin/{app_name}",
f"{{st_build_dir}}/{{st_package_name}}/{app_name}",
_filter=None, recursive=True,
@@ -92,9 +92,9 @@ def prepare_packages_posix(self, _vars):
def adjusted_lib_name(name, version):
postfix = ''
if sys.platform.startswith('linux'):
- postfix = '.so.' + version
+ postfix = f".so.{version}"
elif sys.platform == 'darwin':
- postfix = '.' + version + '.dylib'
+ postfix = f".{version}.dylib"
return name + postfix
if config.is_internal_shiboken_module_build():
diff --git a/build_scripts/platforms/windows_desktop.py b/build_scripts/platforms/windows_desktop.py
index 2c801a0a7..e6d4cc334 100644
--- a/build_scripts/platforms/windows_desktop.py
+++ b/build_scripts/platforms/windows_desktop.py
@@ -475,11 +475,11 @@ def copy_qt_artifacts(self, copy_pdbs, _vars):
recursive=False,
_vars=_vars)
- _filter = 'QtWebEngineProcess{}.exe'.format(
- 'd' if self.debug else '')
+ _ext = "d" if self.debug else ""
+ _filter = [f"QtWebEngineProcess{_ext}.exe"]
copydir("{qt_bin_dir}",
"{st_build_dir}/{st_package_name}",
- _filter=[_filter],
+ _filter=_filter,
recursive=False, _vars=_vars)
if copy_qt_conf:
diff --git a/build_scripts/qp5_tool.py b/build_scripts/qp5_tool.py
index 4e8c09bf6..e1b95d3a9 100644
--- a/build_scripts/qp5_tool.py
+++ b/build_scripts/qp5_tool.py
@@ -228,7 +228,7 @@ def read_config(key):
"""
if not config_dict:
read_config_file(config_file)
- repo_value = config_dict.get(key + '-' + base_dir)
+ repo_value = config_dict.get(f"{key}-{base_dir}")
return repo_value if repo_value else config_dict.get(key)
@@ -261,7 +261,7 @@ def read_config_build_arguments():
def read_config_modules_argument():
value = read_config(MODULES_KEY)
if value and value != '' and value != 'all':
- return '--module-subset=' + value
+ return f"--module-subset={value}"
return None
@@ -302,7 +302,7 @@ def get_config_file(base_name):
if os.path.exists(config_dir):
config_file = os.path.join(config_dir, base_name)
else:
- config_file = os.path.join(home, '.' + base_name)
+ config_file = os.path.join(home, f".{base_name}")
return config_file
diff --git a/build_scripts/utils.py b/build_scripts/utils.py
index 4f808249e..6f44ae5c2 100644
--- a/build_scripts/utils.py
+++ b/build_scripts/utils.py
@@ -145,7 +145,7 @@ def winsdk_setenv(platform_arch, build_type):
setenv_env = get_environment_from_batch_command(setenv_cmd)
_setenv_paths = [setenv_env[k] for k in setenv_env if k.upper() == 'PATH']
setenv_env_paths = os.pathsep.join(_setenv_paths).split(os.pathsep)
- setenv_env_without_paths = dict([(k, setenv_env[k]) for k in setenv_env if k.upper() != 'PATH'])
+ setenv_env_without_paths = {k: setenv_env[k] for k in setenv_env if k.upper() != 'PATH'}
# Extend os.environ with SDK env
log.info("Initializing Windows SDK env...")
@@ -239,7 +239,7 @@ def init_msvc_env(platform_arch, build_type):
msvc_env = get_environment_from_batch_command(vcvars_cmd)
_msvc_paths = [msvc_env[k] for k in msvc_env if k.upper() == 'PATH']
msvc_env_paths = os.pathsep.join(_msvc_paths).split(os.pathsep)
- msvc_env_without_paths = dict([(k, msvc_env[k]) for k in msvc_env if k.upper() != 'PATH'])
+ msvc_env_without_paths = {k: msvc_env[k] for k in msvc_env if k.upper() != 'PATH'}
# Extend os.environ with MSVC env
log.info("Initializing MSVC env...")
@@ -341,11 +341,9 @@ def copydir(src, dst, _filter=None, ignore=None, force=True, recursive=True, _va
src = src.format(**_vars)
dst = dst.format(**_vars)
if _filter is not None:
- for i in range(len(_filter)):
- _filter[i] = _filter[i].format(**_vars)
+ _filter = [i.format(**_vars) for i in _filter]
if ignore is not None:
- for i in range(len(ignore)):
- ignore[i] = ignore[i].format(**_vars)
+ ignore = [i.format(**_vars) for i in ignore]
if not os.path.exists(src) and not force:
log.info(f"**Skipping copy tree\n {src} to\n {dst}\n Source does not exist. "
@@ -481,12 +479,12 @@ def get_environment_from_batch_command(env_cmd, initial=None):
# parse the output sent to stdout
lines = proc.stdout
# make sure the lines are strings
- lines = map(lambda s: s.decode(), lines)
+ lines = [s.decode() for s in lines]
# consume whatever output occurs until the tag is reached
consume(itertools.takewhile(lambda l: tag not in l, lines))
# define a way to handle each KEY=VALUE line
# parse key/values into pairs
- pairs = map(lambda l: l.rstrip().split('=', 1), lines)
+ pairs = [l.rstrip().split('=', 1) for l in lines]
# make sure the pairs are valid
valid_pairs = filter(validate_pair, pairs)
# construct a dictionary of the pairs