From 559c56b140410bcfa0ce6f19b47d1ba0daa9a201 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 2 Nov 2020 08:37:44 +0100 Subject: build scripts: Introduce variables for the versions Change-Id: Iac73fcf6e60f882968463d1c612f5ca5dc206222 Reviewed-by: Cristian Maureira-Fredes --- build_scripts/build_scripts.pyproject | 3 +- build_scripts/config.py | 47 +++++++++++++------------ build_scripts/main.py | 56 ++++++++++++++++-------------- build_scripts/platforms/linux.py | 2 +- build_scripts/platforms/macos.py | 3 +- build_scripts/platforms/unix.py | 15 ++++---- build_scripts/platforms/windows_desktop.py | 21 +++++------ build_scripts/versions.py | 43 +++++++++++++++++++++++ build_scripts/wheel_utils.py | 3 +- 9 files changed, 122 insertions(+), 71 deletions(-) create mode 100644 build_scripts/versions.py (limited to 'build_scripts') diff --git a/build_scripts/build_scripts.pyproject b/build_scripts/build_scripts.pyproject index 80df4d386..4cc497bc7 100644 --- a/build_scripts/build_scripts.pyproject +++ b/build_scripts/build_scripts.pyproject @@ -1,6 +1,7 @@ { "files": ["main.py", "__init__.py", "config.py", "options.py", "qtinfo.py", - "setup_runner.py", "utils.py", "wheel_override.py", "wheel_utils.py", + "setup_runner.py", "utils.py", "wheel_override.py", + "versions.py", "wheel_utils.py", "platforms/__init__.py", "platforms/linux.py", "platforms/macos.py", "platforms/unix.py", "platforms/windows_desktop.py", diff --git a/build_scripts/config.py b/build_scripts/config.py index 242e39d68..2e96efa7a 100644 --- a/build_scripts/config.py +++ b/build_scripts/config.py @@ -39,6 +39,7 @@ import os import distutils.log as log +from .versions import PYSIDE, PYSIDE_MODULE, SHIBOKEN class Config(object): @@ -70,16 +71,16 @@ class Config(object): # Options that can be given to --build-type and # --internal-build-type - self.shiboken_module_option_name = "shiboken6" - self.shiboken_generator_option_name = "shiboken6-generator" - self.pyside_option_name = "pyside2" + self.shiboken_module_option_name = SHIBOKEN + self.shiboken_generator_option_name = f"{SHIBOKEN}-generator" + self.pyside_option_name = PYSIDE # Names to be passed to setuptools.setup() name key, # so not package name, but rather project name as it appears # in the wheel name and on PyPi. - self.shiboken_module_st_name = "shiboken6" - self.shiboken_generator_st_name = "shiboken6-generator" - self.pyside_st_name = "PySide2" + self.shiboken_module_st_name = SHIBOKEN + self.shiboken_generator_st_name = f"{SHIBOKEN}-generator" + self.pyside_st_name = PYSIDE_MODULE # Used by check_allowed_python_version to validate the # interpreter version. @@ -189,6 +190,8 @@ class Config(object): 'Topic :: Software Development :: Widget Sets']) setup_kwargs['classifiers'] = common_classifiers + package_name = self.package_name() + if self.internal_build_type == self.shiboken_module_option_name: setup_kwargs['name'] = self.shiboken_module_st_name setup_kwargs['description'] = "Python / C++ bindings helper module" @@ -200,7 +203,7 @@ class Config(object): setup_kwargs['install_requires'] = ["{}=={}".format(self.shiboken_module_st_name, package_version)] setup_kwargs['entry_points'] = { 'console_scripts': [ - 'shiboken6 = {}.scripts.shiboken_tool:main'.format(self.package_name()), + f'{SHIBOKEN} = {package_name}.scripts.shiboken_tool:main' ] } @@ -210,10 +213,10 @@ class Config(object): setup_kwargs['install_requires'] = ["{}=={}".format(self.shiboken_module_st_name, package_version)] setup_kwargs['entry_points'] = { 'console_scripts': [ - 'pyside2-uic = {}.scripts.pyside_tool:uic'.format(self.package_name()), - 'pyside2-rcc = {}.scripts.pyside_tool:rcc'.format(self.package_name()), - 'pyside2-designer= {}.scripts.pyside_tool:designer'.format(self.package_name()), - 'pyside2-lupdate = {}.scripts.pyside_tool:main'.format(self.package_name()), + f'{PYSIDE}-uic = {package_name}.scripts.pyside_tool:uic', + f'{PYSIDE}-rcc = {package_name}.scripts.pyside_tool:rcc', + f'{PYSIDE}-designer= {package_name}.scripts.pyside_tool:designer', + f'{PYSIDE}-lupdate = {package_name}.scripts.pyside_tool:main', ] } self.setup_kwargs = setup_kwargs @@ -223,11 +226,11 @@ class Config(object): changes_filename = 'CHANGES.rst' if self.is_internal_shiboken_module_build(): - readme_filename = 'README.shiboken6.md' + readme_filename = f'README.{SHIBOKEN}.md' elif self.is_internal_shiboken_generator_build(): - readme_filename = 'README.shiboken6-generator.md' + readme_filename = f'README.{SHIBOKEN}-generator.md' elif self.is_internal_pyside_build(): - readme_filename = 'README.pyside2.md' + readme_filename = f'README.{PYSIDE}.md' content = '' changes = '' @@ -264,11 +267,11 @@ class Config(object): dashes. """ if self.is_internal_shiboken_module_build(): - return "shiboken6" + return SHIBOKEN elif self.is_internal_shiboken_generator_build(): - return "shiboken6_generator" + return f"{SHIBOKEN}_generator" elif self.is_internal_pyside_build(): - return "PySide2" + return PYSIDE_MODULE else: return None @@ -299,7 +302,7 @@ class Config(object): For example when building the shiboken module, setuptools will expect to find the "shiboken6" module sources under - "sources/shiboken6/shibokenmodule". + "sources/{SHIBOKEN}/shibokenmodule". This is really just to satisfy some checks in setuptools build_py command, and if we ever properly implement the develop @@ -307,7 +310,7 @@ class Config(object): """ if self.is_internal_shiboken_module_build(): return { - self.package_name(): "sources/shiboken6/shibokenmodule" + self.package_name(): f"sources/{SHIBOKEN}/shibokenmodule" } elif self.is_internal_shiboken_generator_build(): # This is left empty on purpose, because the shiboken @@ -315,7 +318,7 @@ class Config(object): return {} elif self.is_internal_pyside_build(): return { - self.package_name(): "sources/pyside2/PySide2", + self.package_name(): f"sources/{PYSIDE}/{PYSIDE_MODULE}", } else: return {} @@ -326,9 +329,9 @@ class Config(object): :return: A list of directory names under the sources directory. """ if self.is_internal_shiboken_module_build() or self.is_internal_shiboken_generator_build(): - return ['shiboken6'] + return [SHIBOKEN] elif self.is_internal_pyside_build(): - return ['pyside2', 'pyside-tools'] + return [PYSIDE, 'pyside-tools'] return None def set_is_top_level_invocation(self): diff --git a/build_scripts/main.py b/build_scripts/main.py index fb445ea2e..99fdd286c 100644 --- a/build_scripts/main.py +++ b/build_scripts/main.py @@ -49,10 +49,12 @@ import time from .config import config from .utils import get_python_dict from .options import DistUtilsCommandMixin, OPTION +from .versions import PYSIDE, PYSIDE_MODULE, SHIBOKEN from .wheel_utils import (get_package_version, get_qt_version, get_package_timestamp, macos_plat_name, macos_pyside_min_deployment_target) + setup_script_dir = os.getcwd() build_scripts_dir = os.path.join(setup_script_dir, 'build_scripts') setup_py_path = os.path.join(setup_script_dir, "setup.py") @@ -114,8 +116,8 @@ def get_make(platform_arch, build_type): if not os.path.isabs(make_path): found_path = find_executable(make_path) if not found_path or not os.path.exists(found_path): - raise DistutilsSetupError("You need the program '{}' on your system path to " - "compile PySide2.".format(make_path)) + m = f"You need the program '{make_path}' on your system path to compile {PYSIDE_MODULE}." + raise DistutilsSetupError(m) make_path = found_path return (make_path, make_generator) @@ -278,8 +280,8 @@ def prefix(): # Initialize, pull and checkout submodules def prepare_sub_modules(): - print("Initializing submodules for PySide2 version: {}".format( - get_package_version())) + v = get_package_version() + print(f"Initializing submodules for {PYSIDE_MODULE} version: {v}") submodules_dir = os.path.join(setup_script_dir, "sources") # Create list of [name, desired branch, absolute path, desired @@ -560,7 +562,7 @@ class PysideBuild(_build, DistUtilsCommandMixin): # Save the shiboken build dir path for clang deployment # purposes. - self.shiboken_build_dir = os.path.join(self.build_dir, "shiboken6") + self.shiboken_build_dir = os.path.join(self.build_dir, SHIBOKEN) self.log_pre_build_info() @@ -740,13 +742,13 @@ class PysideBuild(_build, DistUtilsCommandMixin): # 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(): - if os.path.exists(OPTION["SHIBOKEN_CONFIG_DIR"]): - log.info("Using custom provided shiboken6 installation: {}" - .format(OPTION["SHIBOKEN_CONFIG_DIR"])) - cmake_cmd.append("-DShiboken6_DIR={}".format(OPTION["SHIBOKEN_CONFIG_DIR"])) + config_dir = OPTION["SHIBOKEN_CONFIG_DIR"] + if os.path.exists(config_dir): + log.info(f"Using custom provided {SHIBOKEN} installation: {config_dir}") + cmake_cmd.append(f"-DShiboken6_DIR={config_dir}") else: - log.info("Custom provided shiboken6 installation not found. Path given: {}" - .format(OPTION["SHIBOKEN_CONFIG_DIR"])) + + log.info(f"Custom provided {SHIBOKEN} installation not found. Path given: {config_dir}") if OPTION["MODULE_SUBSET"]: module_sub_set = '' @@ -796,7 +798,7 @@ class PysideBuild(_build, DistUtilsCommandMixin): else: raise DistutilsSetupError("Address sanitizer can only be used on Linux and macOS.") - if extension.lower() == "pyside2": + if extension.lower() == PYSIDE: pyside_qt_conf_prefix = '' if OPTION["QT_CONF_PREFIX"]: pyside_qt_conf_prefix = OPTION["QT_CONF_PREFIX"] @@ -821,7 +823,7 @@ class PysideBuild(_build, DistUtilsCommandMixin): timestamp = get_package_timestamp() cmake_cmd.append("-DPACKAGE_SETUP_PY_PACKAGE_TIMESTAMP={}".format(timestamp)) - if extension.lower() in ["shiboken6"]: + if extension.lower() in [SHIBOKEN]: cmake_cmd.append("-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=yes") cmake_cmd.append("-DUSE_PYTHON_VERSION=3.6") @@ -890,7 +892,7 @@ class PysideBuild(_build, DistUtilsCommandMixin): raise DistutilsSetupError("Error compiling {}".format(extension)) if not OPTION["SKIP_DOCS"]: - if extension.lower() == "shiboken6": + if extension.lower() == SHIBOKEN: try: # Check if sphinx is installed to proceed. import sphinx @@ -1144,12 +1146,12 @@ class PysideRstDocs(Command, DistUtilsCommandMixin): try: # Check if sphinx is installed to proceed. import sphinx - if self.name == "shiboken6": + if self.name == SHIBOKEN: log.info("-- Generating Shiboken documentation") - log.info("-- Documentation directory: 'html/pyside2/shiboken6/'") - elif self.name == "pyside2": + log.info(f"-- Documentation directory: 'html/{PYSIDE}/{SHIBOKEN}/'") + elif self.name == PYSIDE: log.info("-- Generating PySide documentation") - log.info("-- Documentation directory: 'html/pyside2/'") + log.info(f"-- Documentation directory: 'html/{PYSIDE}/'") except ImportError: raise DistutilsSetupError("Sphinx not found - aborting") self.html_dir = "html" @@ -1158,18 +1160,18 @@ class PysideRstDocs(Command, DistUtilsCommandMixin): try: if not os.path.isdir(self.html_dir): os.mkdir(self.html_dir) - if self.name == "shiboken6": - out_pyside = os.path.join(self.html_dir, "pyside2") + if self.name == SHIBOKEN: + out_pyside = os.path.join(self.html_dir, PYSIDE) if not os.path.isdir(out_pyside): os.mkdir(out_pyside) - out_shiboken = os.path.join(out_pyside, "shiboken6") + out_shiboken = os.path.join(out_pyside, SHIBOKEN) if not os.path.isdir(out_shiboken): os.mkdir(out_shiboken) self.out_dir = out_shiboken # We know that on the shiboken step, we already created the # 'pyside2' directory - elif self.name == "pyside2": - self.out_dir = os.path.join(self.html_dir, "pyside2") + 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)) @@ -1185,9 +1187,9 @@ class PysideRstDocs(Command, DistUtilsCommandMixin): if run_process(cmake_cmd) != 0: raise DistutilsSetupError("Error running CMake for {}".format(self.doc_dir)) - if self.name == "pyside2": + if self.name == PYSIDE: self.sphinx_src = os.path.join(self.out_dir, "rst") - elif self.name == "shiboken6": + elif self.name == SHIBOKEN: self.sphinx_src = self.out_dir sphinx_cmd = ["sphinx-build", "-b", "html", "-c", self.sphinx_src, @@ -1195,8 +1197,8 @@ class PysideRstDocs(Command, DistUtilsCommandMixin): if run_process(sphinx_cmd) != 0: raise DistutilsSetupError("Error running CMake for {}".format(self.doc_dir)) # Last message - if not self.skip and self.name == "pyside2": - log.info("-- The documentation was built. Check html/pyside2/index.html") + if not self.skip and self.name == PYSIDE: + log.info(f"-- The documentation was built. Check html/{PYSIDE}/index.html") def finalize_options(self): DistUtilsCommandMixin.mixin_finalize_options(self) diff --git a/build_scripts/platforms/linux.py b/build_scripts/platforms/linux.py index ddfd8e21a..00687be42 100644 --- a/build_scripts/platforms/linux.py +++ b/build_scripts/platforms/linux.py @@ -141,6 +141,6 @@ def prepare_standalone_package_linux(self, vars): if copy_qt_conf: # Copy the qt.conf file to libexec. copyfile( - "{build_dir}/pyside2/{st_package_name}/qt.conf", + f"{{build_dir}}/{PYSIDE}/{{st_package_name}}/qt.conf", "{st_build_dir}/{st_package_name}/Qt/libexec", vars=vars) diff --git a/build_scripts/platforms/macos.py b/build_scripts/platforms/macos.py index 614d6acbc..82681caf6 100644 --- a/build_scripts/platforms/macos.py +++ b/build_scripts/platforms/macos.py @@ -41,6 +41,7 @@ import fnmatch import os from ..utils import copydir, copyfile, macos_fix_rpaths_for_library, macos_add_rpath from ..config import config +from ..versions import PYSIDE, SHIBOKEN def prepare_standalone_package_macos(self, vars): @@ -174,7 +175,7 @@ def prepare_standalone_package_macos(self, vars): if copy_qt_conf: # Copy the qt.conf file to libexec. copyfile( - "{build_dir}/pyside2/{st_package_name}/qt.conf", + f"{{build_dir}}/{PYSIDE}/{{st_package_name}}/qt.conf", "{st_build_dir}/{st_package_name}/Qt/libexec", vars=vars) diff --git a/build_scripts/platforms/unix.py b/build_scripts/platforms/unix.py index 1e1c1e4a8..482f2b82c 100644 --- a/build_scripts/platforms/unix.py +++ b/build_scripts/platforms/unix.py @@ -47,6 +47,7 @@ from ..config import config from ..options import OPTION from ..utils import copydir, copyfile, makefile from ..utils import regenerate_qt_resources +from ..versions import PYSIDE, SHIBOKEN def prepare_packages_posix(self, vars): @@ -75,8 +76,8 @@ def prepare_packages_posix(self, vars): # /shiboken6/doc/html/* -> # /{st_package_name}/docs/shiboken6 copydir( - "{build_dir}/shiboken6/doc/html", - "{st_build_dir}/{st_package_name}/docs/shiboken6", + f"{{build_dir}}/{SHIBOKEN}/doc/html", + f"{{st_build_dir}}/{{st_package_name}}/docs/{SHIBOKEN}", force=False, vars=vars) # /lib/lib* -> {st_package_name}/ @@ -94,9 +95,7 @@ def prepare_packages_posix(self, vars): executables.extend(copydir( "{install_dir}/bin/", "{st_build_dir}/{st_package_name}", - filter=[ - "shiboken6", - ], + filter=[SHIBOKEN], recursive=False, vars=vars)) # Used to create scripts directory. @@ -133,7 +132,7 @@ def prepare_packages_posix(self, vars): "{install_dir}/bin/", "{st_build_dir}/{st_package_name}", filter=[ - "pyside2-lupdate", + f"{PYSIDE}-lupdate", "uic", "rcc", ], @@ -179,14 +178,14 @@ def prepare_packages_posix(self, vars): # /pyside2/{st_package_name}/support/* -> # /{st_package_name}/support/* copydir( - "{build_dir}/pyside2/{st_package_name}/support", + f"{{build_dir}}/{PYSIDE}/{{st_package_name}}/support", "{st_build_dir}/{st_package_name}/support", vars=vars) # /pyside2/{st_package_name}/*.pyi -> # /{st_package_name}/*.pyi copydir( - "{build_dir}/pyside2/{st_package_name}", + f"{{build_dir}}/{PYSIDE}/{{st_package_name}}", "{st_build_dir}/{st_package_name}", filter=["*.pyi", "py.typed"], vars=vars) diff --git a/build_scripts/platforms/windows_desktop.py b/build_scripts/platforms/windows_desktop.py index 83485e1d7..2f58c0cc9 100644 --- a/build_scripts/platforms/windows_desktop.py +++ b/build_scripts/platforms/windows_desktop.py @@ -47,6 +47,7 @@ from ..options import OPTION from ..utils import copydir, copyfile, makefile from ..utils import regenerate_qt_resources, filter_match from ..utils import download_and_extract_7z +from ..versions import PYSIDE, SHIBOKEN def prepare_packages_win32(self, vars): @@ -69,8 +70,8 @@ def prepare_packages_win32(self, vars): # /shiboken6/doc/html/* -> # /{st_package_name}/docs/shiboken6 copydir( - "{build_dir}/shiboken6/doc/html", - "{st_build_dir}/{st_package_name}/docs/shiboken6", + f"{{build_dir}}/{SHIBOKEN}/doc/html", + f"{{st_build_dir}}/{{st_package_name}}/docs/{SHIBOKEN}", force=False, vars=vars) # /bin/*.dll -> {st_package_name}/ @@ -91,14 +92,14 @@ def prepare_packages_win32(self, vars): # {shibokengenerator}.pdb file. # Task-number: PYSIDE-615 copydir( - "{build_dir}/shiboken6/shibokenmodule", + f"{{build_dir}}/{SHIBOKEN}/shibokenmodule", "{st_build_dir}/{st_package_name}", filter=pdbs, recursive=False, vars=vars) # pdb files for libshiboken and libpyside copydir( - "{build_dir}/shiboken6/libshiboken", + f"{{build_dir}}/{SHIBOKEN}/libshiboken", "{st_build_dir}/{st_package_name}", filter=pdbs, recursive=False, vars=vars) @@ -126,7 +127,7 @@ def prepare_packages_win32(self, vars): # {shibokenmodule}.pdb file. # Task-number: PYSIDE-615 copydir( - "{build_dir}/shiboken6/generator", + f"{{build_dir}}/{SHIBOKEN}/generator", "{st_build_dir}/{st_package_name}", filter=pdbs, recursive=False, vars=vars) @@ -142,7 +143,7 @@ def prepare_packages_win32(self, vars): # /pyside2/{st_package_name}/*.pdb -> # /{st_package_name} copydir( - "{build_dir}/pyside2/{st_package_name}", + f"{{build_dir}}/{PYSIDE}/{{st_package_name}}", "{st_build_dir}/{st_package_name}", filter=pdbs, recursive=False, vars=vars) @@ -188,20 +189,20 @@ def prepare_packages_win32(self, vars): # /pyside2/{st_package_name}/support/* -> # /{st_package_name}/support/* copydir( - "{build_dir}/pyside2/{st_package_name}/support", + f"{{build_dir}}/{PYSIDE}/{{st_package_name}}/support", "{st_build_dir}/{st_package_name}/support", vars=vars) # /pyside2/{st_package_name}/*.pyi -> # /{st_package_name}/*.pyi copydir( - "{build_dir}/pyside2/{st_package_name}", + "{build_dir}/{PYSIDE}/{st_package_name}", "{st_build_dir}/{st_package_name}", filter=["*.pyi", "py.typed"], vars=vars) copydir( - "{build_dir}/pyside2/libpyside", + f"{{build_dir}}/{PYSIDE}/libpyside", "{st_build_dir}/{st_package_name}", filter=pdbs, recursive=False, vars=vars) @@ -468,7 +469,7 @@ def copy_qt_artifacts(self, copy_pdbs, vars): if copy_qt_conf: # Copy the qt.conf file to prefix dir. - copyfile("{build_dir}/pyside2/{st_package_name}/qt.conf", + copyfile(f"{{build_dir}}/{PYSIDE}/{{st_package_name}}/qt.conf", "{st_build_dir}/{st_package_name}", vars=vars) diff --git a/build_scripts/versions.py b/build_scripts/versions.py new file mode 100644 index 000000000..ff340d479 --- /dev/null +++ b/build_scripts/versions.py @@ -0,0 +1,43 @@ +############################################################################# +## +## Copyright (C) 2020 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$ +## +############################################################################# + + +PYSIDE = 'pyside2' +PYSIDE_MODULE = 'PySide2' +SHIBOKEN = 'shiboken6' diff --git a/build_scripts/wheel_utils.py b/build_scripts/wheel_utils.py index 71b4e0acf..0b15c1a89 100644 --- a/build_scripts/wheel_utils.py +++ b/build_scripts/wheel_utils.py @@ -50,6 +50,7 @@ from distutils.version import LooseVersion from .options import OPTION from .qtinfo import QtInfo from .utils import memoize, get_python_dict +from .versions import PYSIDE, SHIBOKEN @memoize @@ -81,7 +82,7 @@ def get_package_version(): """ Returns the version string for the PySide2 package. """ setup_script_dir = os.getcwd() pyside_version_py = os.path.join( - setup_script_dir, "sources", "pyside2", "pyside_version.py") + setup_script_dir, "sources", PYSIDE, "pyside_version.py") d = get_python_dict(pyside_version_py) final_version = "{}.{}.{}".format( -- cgit v1.2.3