diff options
author | Cristián Maureira-Fredes <Cristian.Maureira-Fredes@qt.io> | 2022-03-18 11:49:03 +0100 |
---|---|---|
committer | Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> | 2022-03-22 14:27:19 +0000 |
commit | a10efb90f048764527c1d26bc0362c6db8f4234e (patch) | |
tree | cb486768c8a6161f091bec2badb21c03b6539458 /build_scripts | |
parent | 6f20389eecdd3148b44ede8cd179d324ba79cb4f (diff) |
flake8: improve codestyling of build scripts
- Fixing f-strings
- Fixing indentation of some lines
- Removing unused variables and imports
- Changing the way of verifying if sphinx is installed
Change-Id: I3f361759682324c9b0c9d33c24583435f137f05a
Pick-to: 6.2
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'build_scripts')
-rw-r--r-- | build_scripts/__init__.py | 38 | ||||
-rw-r--r-- | build_scripts/build_info_collector.py | 4 | ||||
-rw-r--r-- | build_scripts/main.py | 26 | ||||
-rw-r--r-- | build_scripts/options.py | 5 | ||||
-rw-r--r-- | build_scripts/qp5_tool.py | 1 | ||||
-rw-r--r-- | build_scripts/qtinfo.py | 4 | ||||
-rw-r--r-- | build_scripts/setup_runner.py | 2 | ||||
-rw-r--r-- | build_scripts/utils.py | 36 | ||||
-rw-r--r-- | build_scripts/wheel_override.py | 10 | ||||
-rw-r--r-- | build_scripts/wheel_utils.py | 2 |
10 files changed, 40 insertions, 88 deletions
diff --git a/build_scripts/__init__.py b/build_scripts/__init__.py deleted file mode 100644 index 571d37492..000000000 --- a/build_scripts/__init__.py +++ /dev/null @@ -1,38 +0,0 @@ -############################################################################# -## -## Copyright (C) 2018 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of Qt for Python. -## -## $QT_BEGIN_LICENSE:LGPL$ -## Commercial License Usage -## Licensees holding valid commercial Qt licenses may use this file in -## accordance with the commercial license agreement provided with the -## Software or, alternatively, in accordance with the terms contained in -## a written agreement between you and The Qt Company. For licensing terms -## and conditions see https://www.qt.io/terms-conditions. For further -## information use the contact form at https://www.qt.io/contact-us. -## -## GNU Lesser General Public License Usage -## Alternatively, this file may be used under the terms of the GNU Lesser -## General Public License version 3 as published by the Free Software -## Foundation and appearing in the file LICENSE.LGPL3 included in the -## packaging of this file. Please review the following information to -## ensure the GNU Lesser General Public License version 3 requirements -## will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -## -## GNU General Public License Usage -## Alternatively, this file may be used under the terms of the GNU -## General Public License version 2.0 or (at your option) the GNU General -## Public license version 3 or any later version approved by the KDE Free -## Qt Foundation. The licenses are as published by the Free Software -## Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -## included in the packaging of this file. Please review the following -## information to ensure the GNU General Public License requirements will -## be met: https://www.gnu.org/licenses/gpl-2.0.html and -## https://www.gnu.org/licenses/gpl-3.0.html. -## -## $QT_END_LICENSE$ -## -############################################################################# diff --git a/build_scripts/build_info_collector.py b/build_scripts/build_info_collector.py index 592b4c873..46e20efe6 100644 --- a/build_scripts/build_info_collector.py +++ b/build_scripts/build_info_collector.py @@ -104,7 +104,6 @@ def _get_py_library_unix(build_type, py_version, py_prefix, py_libdir, if py_include_dir is None or not os.path.exists(py_include_dir): 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'] if sys.platform == 'darwin': lib_exts.append('.dylib') @@ -145,7 +144,8 @@ def _get_py_library_unix(build_type, py_version, py_prefix, py_libdir, if os.path.exists(pypy_library): return pypy_library libs_tried.append(pypy_library) - raise DistutilsSetupError(f"Failed to locate the Python library with {', '.join(libs_tried)}") + _libs_tried = ', '.join(libs_tried) + raise DistutilsSetupError(f"Failed to locate the Python library with {_libs_tried}") def get_py_library(build_type, py_version, py_prefix, py_libdir, py_include_dir): diff --git a/build_scripts/main.py b/build_scripts/main.py index 39ee4837e..e50ca791e 100644 --- a/build_scripts/main.py +++ b/build_scripts/main.py @@ -43,6 +43,7 @@ import os import platform import re import sys +import importlib from textwrap import dedent import time from .config import config @@ -67,7 +68,6 @@ from setuptools.command.build_py import build_py as _build_py # happens only with custom builds of Python without virtual environment. import setuptools.command.install_scripts -from sysconfig import get_config_var # Use the distutils implementation within setuptools from setuptools._distutils.errors import DistutilsSetupError from setuptools._distutils import log @@ -763,7 +763,7 @@ class PysideBuild(_build, DistUtilsCommandMixin, BuildInfoCollectorMixin): if self.is_cross_compile and (not OPTION["SHIBOKEN_HOST_PATH"] or not os.path.exists(OPTION["SHIBOKEN_HOST_PATH"])): raise DistutilsSetupError( - f"Please specify the location of host shiboken tools via --shiboken-host-path=") + "Please specify the location of host shiboken tools via --shiboken-host-path=") if self.shiboken_host_path: cmake_cmd.append(f"-DQFP_SHIBOKEN_HOST_PATH={self.shiboken_host_path}") @@ -803,10 +803,8 @@ class PysideBuild(_build, DistUtilsCommandMixin, BuildInfoCollectorMixin): if not OPTION["SKIP_DOCS"]: if extension.lower() == SHIBOKEN: - try: - # Check if sphinx is installed to proceed. - import sphinx - + found = importlib.util.find_spec("sphinx") + if found: log.info("Generating Shiboken documentation") make_doc_cmd = [self.make_path, "doc"] if OPTION["VERBOSE_BUILD"] and self.make_generator == "Ninja": @@ -814,7 +812,7 @@ class PysideBuild(_build, DistUtilsCommandMixin, BuildInfoCollectorMixin): if run_process(make_doc_cmd) != 0: raise DistutilsSetupError("Error generating documentation " f"for {extension}") - except ImportError: + else: log.info("Sphinx not found, skipping documentation build") else: log.info("Skipped documentation generation") @@ -1105,7 +1103,7 @@ class PysideBuild(_build, DistUtilsCommandMixin, BuildInfoCollectorMixin): if not (self.is_cross_compile and sys.platform.startswith('linux') and self.standalone): return - log.info(f"Patching rpath for Qt and QML plugins.") + log.info("Patching rpath for Qt and QML plugins.") for plugin in plugin_paths: if os.path.isdir(plugin) or os.path.islink(plugin): continue @@ -1164,16 +1162,16 @@ class PysideRstDocs(Command, DistUtilsCommandMixin): self.doc_dir = os.path.join(config.setup_script_dir, "sources") self.doc_dir = os.path.join(self.doc_dir, self.name) self.doc_dir = os.path.join(self.doc_dir, "doc") - try: - # Check if sphinx is installed to proceed. - import sphinx + # Check if sphinx is installed to proceed. + found = importlib.util.find_spec("sphinx") + if found: if self.name == SHIBOKEN: log.info("-- Generating Shiboken documentation") log.info(f"-- Documentation directory: 'html/{PYSIDE}/{SHIBOKEN}/'") elif self.name == PYSIDE: log.info("-- Generating PySide documentation") log.info(f"-- Documentation directory: 'html/{PYSIDE}/'") - except ImportError: + else: raise DistutilsSetupError("Sphinx not found - aborting") self.html_dir = "html" @@ -1198,8 +1196,8 @@ class PysideRstDocs(Command, DistUtilsCommandMixin): def run(self): if not self.skip: - cmake_cmd = [OPTION["CMAKE"]] - cmake_cmd += [ + cmake_cmd = [ + OPTION["CMAKE"], "-S", self.doc_dir, "-B", self.out_dir, "-DDOC_OUTPUT_FORMAT=html", diff --git a/build_scripts/options.py b/build_scripts/options.py index 76fb5ce9c..b33e27857 100644 --- a/build_scripts/options.py +++ b/build_scripts/options.py @@ -255,7 +255,7 @@ class DistUtilsCommandMixin(object): # We redeclare plat-name as an option so it's recognized by the # install command and doesn't throw an error. ('plat-name=', None, 'The platform name for which we are cross-compiling'), - ] + ] def __init__(self): self.avoid_protected_hack = False @@ -337,7 +337,6 @@ class DistUtilsCommandMixin(object): keys.add(name.rstrip("=").replace("-", "_")) return keys - def mixin_finalize_options(self): # The very first we finalize options, record that. if not DistUtilsCommandMixin._static_class_finalized_once: @@ -473,7 +472,7 @@ class DistUtilsCommandMixin(object): def _extra_checks(self): if self.is_cross_compile and not self.plat_name: - log.error(f"No value provided to --plat-name while cross-compiling.") + log.error("No value provided to --plat-name while cross-compiling.") return False return True diff --git a/build_scripts/qp5_tool.py b/build_scripts/qp5_tool.py index ad74edf47..4684018ea 100644 --- a/build_scripts/qp5_tool.py +++ b/build_scripts/qp5_tool.py @@ -287,6 +287,7 @@ def read_config_python_binary(): def get_config_file(base_name): + global user home = os.getenv('HOME') if IS_WINDOWS: # Set a HOME variable on Windows such that scp. etc. diff --git a/build_scripts/qtinfo.py b/build_scripts/qtinfo.py index 95e087096..ee4bbc955 100644 --- a/build_scripts/qtinfo.py +++ b/build_scripts/qtinfo.py @@ -38,16 +38,12 @@ ############################################################################# import os -import sys -import re import subprocess -import tempfile from pathlib import Path from .utils import configure_cmake_project, parse_cmake_project_message_info from .utils import platform_cmake_options - class QtInfo(object): _instance = None # singleton helpers diff --git a/build_scripts/setup_runner.py b/build_scripts/setup_runner.py index 362432d2a..9971815d4 100644 --- a/build_scripts/setup_runner.py +++ b/build_scripts/setup_runner.py @@ -128,7 +128,7 @@ class SetupRunner(object): # Add --reuse-build option if requested and not already present. if (reuse_build and command in ('bdist_wheel', 'build', 'build_rst_docs', 'install') - and not self.cmd_line_argument_is_in_args("reuse-build", modified_argv)): + and not self.cmd_line_argument_is_in_args("reuse-build", modified_argv)): setup_cmd.append(self.construct_cmd_line_argument("reuse-build")) return setup_cmd diff --git a/build_scripts/utils.py b/build_scripts/utils.py index ea3679ffa..cd64bd7bf 100644 --- a/build_scripts/utils.py +++ b/build_scripts/utils.py @@ -57,7 +57,7 @@ import urllib.request as urllib try: # Using the distutils implementation within setuptools from setuptools._distutils import log - from setuptools._distutils.errors import DistutilsError + from setuptools._distutils.errors import DistutilsSetupError except ModuleNotFoundError: # This is motivated by our CI using an old version of setuptools # so then the coin_build_instructions.py script is executed, and @@ -94,7 +94,7 @@ def get_numpy_location(): if 'site-' in p: numpy = Path(p).resolve() / 'numpy' if numpy.is_dir(): - return os.fspath(numpy / 'core' / 'include') + return os.fspath(numpy / 'core' / 'include') return None @@ -116,7 +116,7 @@ def winsdk_setenv(platform_arch, build_type): if sdk_versions: for sdk_version in sdk_versions: installationfolder = msvc9.Reg.get_value(f"{msvc9.WINSDK_BASE}\\{sdk_version}", - "installationfolder") + "installationfolder") # productversion = msvc9.Reg.get_value("{}\\{}".format(msvc9.WINSDK_BASE, sdk_version), # "productversion") setenv_path = os.path.join(installationfolder, os.path.join('bin', 'SetEnv.cmd')) @@ -273,8 +273,8 @@ def copyfile(src, dst, force=True, vars=None, force_copy_symlink=False, if os.path.isfile(dst): src_stat = os.stat(src) dst_stat = os.stat(dst) - if (src_stat.st_size == dst_stat.st_size and - src_stat.st_mtime <= dst_stat.st_mtime): + if (src_stat.st_size == dst_stat.st_size + and src_stat.st_mtime <= dst_stat.st_mtime): log.info(f"{dst} is up to date.") return dst @@ -294,8 +294,8 @@ def copyfile(src, dst, force=True, vars=None, force_copy_symlink=False, target_dir = dst if os.path.isdir(dst) else os.path.dirname(dst) os.chdir(target_dir) if os.path.exists(link_name): - if (os.path.islink(link_name) and - os.readlink(link_name) == link_target): + if (os.path.islink(link_name) + and os.readlink(link_name) == link_target): log.info(f"Symlink already exists\n {link_name} ->\n {link_target}") return dst os.remove(link_name) @@ -352,7 +352,7 @@ def copydir(src, dst, filter=None, ignore=None, force=True, recursive=True, vars names = os.listdir(src) results = [] - errors = [] + copy_errors = [] for name in names: srcname = os.path.join(src, name) dstname = os.path.join(dst, name) @@ -375,9 +375,9 @@ def copydir(src, dst, filter=None, ignore=None, force=True, recursive=True, vars # catch the Error from the recursive copytree so that we can # continue with other files except shutil.Error as err: - errors.extend(err.args[0]) + copy_errors.extend(err.args[0]) except EnvironmentError as why: - errors.append((srcname, dstname, str(why))) + copy_errors.append((srcname, dstname, str(why))) try: if os.path.exists(dst): shutil.copystat(src, dst) @@ -386,9 +386,9 @@ def copydir(src, dst, filter=None, ignore=None, force=True, recursive=True, vars # Copying file access times may fail on Windows pass else: - errors.extend((src, dst, str(why))) - if errors: - raise EnvironmentError(errors) + copy_errors.extend((src, dst, str(why))) + if copy_errors: + raise EnvironmentError(copy_errors) return results @@ -450,11 +450,8 @@ def get_environment_from_batch_command(env_cmd, initial=None): """ def validate_pair(ob): - try: - if not (len(ob) == 2): - log.error(f"Unexpected result: {ob}") - raise ValueError - except: + if len(ob) != 2: + log.error(f"Unexpected result: {ob}") return False return True @@ -945,7 +942,7 @@ def copy_icu_libs(patchelf, destination_lib_dir): if not qt_core_library_path or not os.path.exists(qt_core_library_path): raise RuntimeError(f"QtCore library does not exist at path: {qt_core_library_path}. " - "Failed to copy ICU libraries.") + "Failed to copy ICU libraries.") dependencies = ldd_get_dependencies(qt_core_library_path) @@ -1007,7 +1004,6 @@ def linux_prepend_rpath(patchelf, executable_path, new_path): rpaths.insert(0, new_path) new_rpaths_string = ":".join(rpaths) linux_set_rpaths(patchelf, executable_path, new_rpaths_string) - result = True def linux_patch_executable(patchelf, executable_path): diff --git a/build_scripts/wheel_override.py b/build_scripts/wheel_override.py index ce5ba11ab..b4f8844ea 100644 --- a/build_scripts/wheel_override.py +++ b/build_scripts/wheel_override.py @@ -59,7 +59,7 @@ try: except Exception as e: _bdist_wheel, wheel_version = type, "" # dummy to make class statement happy logger.warn(f"***** Exception while trying to prepare bdist_wheel override class: {e}. " - "Skipping wheel overriding.") + "Skipping wheel overriding.") def get_bdist_wheel_override(): @@ -153,8 +153,8 @@ class PysideBuildWheel(_bdist_wheel, DistUtilsCommandMixin): linux_prefix = "linux_" if old_plat_name.startswith(linux_prefix): # Extract the arch suffix like -armv7l or -aarch64 - plat_name_arch_suffix = \ - old_plat_name[old_plat_name.index(linux_prefix) + len(linux_prefix):] + _index = old_plat_name.index(linux_prefix) + len(linux_prefix) + plat_name_arch_suffix = old_plat_name[_index:] new_plat_name = f"{many_linux_prefix}_{plat_name_arch_suffix}" @@ -268,7 +268,7 @@ class PysideBuildWheel(_bdist_wheel, DistUtilsCommandMixin): # Copy of get_tag from bdist_wheel.py, to write a triplet Tag # only once for the limited_api case. - def write_wheelfile(self, wheelfile_base, generator='bdist_wheel (' + wheel_version + ')'): + def write_wheelfile(self, wheelfile_base, generator=f'bdist_wheel ({wheel_version})'): from email.message import Message msg = Message() msg['Wheel-Version'] = '1.0' # of the spec @@ -293,7 +293,7 @@ class PysideBuildWheel(_bdist_wheel, DistUtilsCommandMixin): writeTag(impl) wheelfile_path = os.path.join(wheelfile_base, 'WHEEL') - logger.info('creating %s', wheelfile_path) + logger.info(f'creating {wheelfile_path}') with open(wheelfile_path, 'w') as f: Generator(f, maxheaderlen=0).flatten(msg) diff --git a/build_scripts/wheel_utils.py b/build_scripts/wheel_utils.py index 6f42e004d..7f2249146 100644 --- a/build_scripts/wheel_utils.py +++ b/build_scripts/wheel_utils.py @@ -40,7 +40,7 @@ import os import time -from setuptools._distutils.errors import DistutilsError +from setuptools._distutils.errors import DistutilsSetupError from sysconfig import get_platform, get_config_var from packaging.version import parse as parse_version |