diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-01-29 14:23:28 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-02-07 15:14:20 +0100 |
commit | c395219c6a9967f82dc4d4c9f841331497119fc8 (patch) | |
tree | b178377586d808f7e091acbfa636a9669dc07844 | |
parent | d9cfec8e010b48036e5e879ccc99879538a4f7d2 (diff) |
Fix testrunner for Python 3.8/Linux
When running tests with Python 3.8/Linux, the existence_test fails:
File "pyside-setup/sources/pyside2/tests/registry/existence_test.py", line 73
from init_platform import enum_all, generate_all
File "pyside-setup/sources/pyside2/tests/registry/init_platform.py", line 59
from util import get_refpath, get_script_dir
File "pyside-setup/sources/pyside2/tests/registry/util.py", line 113
platform_name = "".join(distro.linux_distribution()[:2]).lower()
AttributeError module 'platform' has no attribute 'linux_distribution'
since platform.linux_distribution() was removed in 3.8. Extract
into a separate method and warn to install distro.
Task-number: PYSIDE-939
Change-Id: I42d04830d51563cc3fbaddc3941c927402514480
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r-- | sources/pyside2/tests/registry/util.py | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/sources/pyside2/tests/registry/util.py b/sources/pyside2/tests/registry/util.py index 3fcba921a..2a5ec322a 100644 --- a/sources/pyside2/tests/registry/util.py +++ b/sources/pyside2/tests/registry/util.py @@ -99,18 +99,32 @@ def warn(message, category=None, stacklevel=2): warnings.warn(message, category, stacklevel) -# Python2 legacy: Correct 'linux2' to 'linux', recommended way. -if sys.platform.startswith('linux'): +def linux_distribution(): + """Returns the Linux distribution""" # We have to be more specific because we had differences between # RHEL 6.6 and RHEL 7.4 . # Note: The platform module is deprecated. We need to switch to the # distro package, ASAP! The distro has been extracted from Python, # because it changes more often than the Python version. + distribution = [] try: import distro + distribution = distro.linux_distribution() except ImportError: - import platform as distro - platform_name = "".join(distro.linux_distribution()[:2]).lower() + # platform.linux_distribution() was removed in 3.8 + if sys.version_info[0] < 3 or sys.version_info[1] < 8: + import platform + distribution = platform.linux_distribution() + if distribution: + return "".join(distribution[:2]).lower() + warnings.warn('Cannot determine Linux distribution, please install distro', + UserWarning) + return "" + + +# Python2 legacy: Correct 'linux2' to 'linux', recommended way. +if sys.platform.startswith('linux'): + platform_name = linux_distribution() # this currently happens on opensuse in 5.14: if not platform_name: # We intentionally crash when that last resort is also absent: |