Skip to content

Commit e9f70c8

Browse files
testwheel.py: Fix up the error handling
When no PySide was present, the too would error out: testwheel.py", line 520, in <module> VERSION[0] = path_version TypeError: 'tuple' object does not support item assignment This apparently resulted from some old code trying to determine the version from the path. Split out the code trying to find the root into a helper function and reorder the code for clarity. Print out errors to stderr. Change-Id: I3f4e878cf3e3d09466180c65e92da98946ee6826 Reviewed-by: Shyamnath Premnadh <[email protected]>
1 parent c2586b6 commit e9f70c8

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

scripts/packagetesting/testwheel.py

+25-22
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,26 @@ def get_pyside_version_from_import():
5757
from PySide2.QtCore import qVersion
5858
qversion_string = qVersion()
5959
except ImportError:
60-
print('Unable to determine PySide version; could not import any version',
61-
file=sys.stderr)
60+
pass
6261
if qversion_string:
6362
major, minor, patch = qVersion().split('.')
6463
return int(major), int(minor), int(patch)
6564
return 0, 0, 0
6665

6766

67+
def find_pyside_root():
68+
for p in map(Path, sys.path):
69+
if p.name == 'site-packages':
70+
root = p / 'PySide6'
71+
if root.is_dir():
72+
return root
73+
root = p / 'PySide2'
74+
if root.is_dir():
75+
return root
76+
break
77+
return None
78+
79+
6880
def list_modules():
6981
"""List the installed Qt modules."""
7082
if VERSION[0] > 5:
@@ -500,35 +512,26 @@ def install_wheels(wheel_dir):
500512
install_wheels(tmpdir)
501513

502514
VERSION = get_pyside_version_from_import()
515+
if VERSION[0] == 0:
516+
print('Unable to determine PySide version; could not import any version',
517+
file=sys.stderr)
518+
sys.exit(1)
503519
if do_pyinst and sys.version_info[0] < 3: # Note: PyInstaller no longer supports Python 2
504520
print('PyInstaller requires Python 3, test disabled')
505521
do_pyinst = False
506-
root = None
507-
path_version = 0
508-
for p in map(Path, sys.path):
509-
if p.name == 'site-packages':
510-
root = p / 'PySide6'
511-
if root.is_dir():
512-
path_version = 6
513-
else:
514-
root = p / 'PySide2'
515-
path_version = 2
516-
if not root_ex:
517-
root_ex = root / 'examples'
518-
break
519-
if VERSION[0] == 0:
520-
VERSION[0] = path_version
521-
print('Detected Qt version ', VERSION)
522-
if not root or not root.is_dir():
523-
print('Could not locate any PySide module.')
522+
root = find_pyside_root()
523+
if not root:
524+
print('Could not locate any PySide module.', file=sys.stderr)
524525
sys.exit(1)
526+
if not root_ex:
527+
root_ex = root / 'examples'
525528
if not root_ex.is_dir():
526529
m = f"PySide{VERSION} module found without examples. "
527530
m += ("Specify --examples <dir>." if VERSION >= (6, 5, 0)
528531
else "Did you forget to install wheels?")
529-
print(m)
532+
print(m, file=sys.stderr)
530533
sys.exit(1)
531-
print(f'Detected PySide{VERSION} at {root}.')
534+
print(f'Detected PySide {VERSION[0]}.{VERSION[1]}.{VERSION[2]} at {root}.')
532535

533536
list_modules()
534537

0 commit comments

Comments
 (0)