diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-02-12 09:44:04 +0100 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-02-28 15:06:47 +0100 |
| commit | 4a8a2713433154aee21f1f83ef3e9e7dc9466275 (patch) | |
| tree | 7d874494c9de67bb92377b9c1a8f6d2752a375c4 /sources/pyside2/tests/init_paths.py | |
| parent | 6d1177b36d4fc89012377d3dbe19867737b80c2e (diff) | |
Fix running the PySide2 tests for Python 3.8/Windows
On Windows, DLL directories can no longer be specified
via the PATH environment variable. They need to be added
via os.add_dll_directory().
In order to fix this, move the entire environment setup
from CMake to a python helper and set the environment
variables BUILD_DIR and QT_DIR pointing to the build
directory and Qt directory, respectively, from CMake.
In addition, this has a huge advantage: The tests can
also be executed much more easily without ctest from the
command line by just setting BUILD_DIR and QT_DIR instead
of a complex manipulation of PATH/LD_LIBRARY_PATH.
Change-Id: I7d518ccab19ca184c3112a126c779d4a6d7c6c5e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Tismer <tismer@stackless.com>
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside2/tests/init_paths.py')
| -rw-r--r-- | sources/pyside2/tests/init_paths.py | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/sources/pyside2/tests/init_paths.py b/sources/pyside2/tests/init_paths.py new file mode 100644 index 000000000..9cfdebc86 --- /dev/null +++ b/sources/pyside2/tests/init_paths.py @@ -0,0 +1,104 @@ +############################################################################# +## +## Copyright (C) 2020 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of Qt for Python. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## 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 General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## 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-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +from __future__ import print_function + +import os +import sys + +SRC_DIR = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(os.path.join(os.path.dirname(os.path.dirname(SRC_DIR)), + 'shiboken2', 'tests')) +from shiboken_paths import (get_dir_env_var, get_build_dir, add_python_dirs, + add_lib_dirs, shiboken_paths) + + +def _get_qt_dir(): + """Retrieve the location of Qt.""" + result = None + try: + result = get_dir_env_var('QT_DIR') + except Exception: + # This is just a convenience for command line invocation independent + # of ctest. Normally, QT_DIR should be set to avoid repetitive patch + # searches. + print('The environment variable QT_DIR is not set; falling back to path search', + file=sys.stderr) + qmake = 'qmake.exe' if sys.platform == 'win32' else 'qmake' + for path in os.environ.get('PATH').split(os.pathsep): + if path and os.path.isfile(os.path.join(path, qmake)): + result = os.path.dirname(path) + break + if not result: + raise ValueError('Unable to locate Qt. Please set the environment variable QT_DIR') + print('Qt as determined by path search: {}'.format(result), file=sys.stderr) + return result + + +def _get_qt_lib_dir(): + """Retrieve the location of the Qt library directory.""" + sub_dir = 'bin' if sys.platform == 'win32' else 'lib' + return os.path.join(_get_qt_dir(), sub_dir) # For testbinding + + +def _init_test_paths(shiboken_tests=False, testbindings_module=False): + """Sets the correct import paths (Python modules and C++ library paths) + for PySide tests and shiboken2 tests using depending on the environment + variables BUILD_DIR and QT_DIR pointing to the build directory and + Qt directory, respectively.""" + src_dir = os.path.dirname(os.path.abspath(__file__)) + + python_dirs = [os.path.join(src_dir, 'util')] # Helper module + + pyside_build_dir = os.path.join(get_build_dir(), 'pyside2') + python_dirs.append(pyside_build_dir) # for PySide2 + lib_dirs = [os.path.join(pyside_build_dir, 'libpyside')] + + if testbindings_module: + python_dirs.append(os.path.join(pyside_build_dir, + 'tests', 'pysidetest')) + lib_dirs.append(_get_qt_lib_dir()) + + shiboken_path_tuple = shiboken_paths(shiboken_tests) + python_dirs.extend(shiboken_path_tuple[0]) + lib_dirs.extend(shiboken_path_tuple[1]) + + add_python_dirs(python_dirs) + add_lib_dirs(lib_dirs) + + +def init_test_paths(testbindings_module=False): + """Sets the correct import paths for PySide2 tests, optionally including + testbindings.""" + _init_test_paths(False, testbindings_module) + + +def init_all_test_paths(): + """Sets the correct import paths for PySide2 and shiboken2 tests + (for registry checking only).""" + _init_test_paths(True, True) |
