Skip to content

Commit 817fae3

Browse files
committed
wheel_tester: Enable it again for Qt >= 6 with Nuitka
With the usage of nuitka, we have a working compiled test, again. Only the scriptableapplication fails, and only for CMake. This will be fixed in another check-in. The PyInstaller test remains in the code for being re-enabled. Task-number: PYSIDE-1523 Change-Id: Ic831fa5b110bbff4150a01cb8a7344ae050aae02 Reviewed-by: Friedemann Kleint <[email protected]>
1 parent e641c22 commit 817fae3

File tree

6 files changed

+67
-25
lines changed

6 files changed

+67
-25
lines changed

coin_test_instructions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ def call_testrunner(python_ver, buildnro):
9898
if CI_RELEASE_CONF:
9999
wheel_tester_path = os.path.join("testing", "wheel_tester.py")
100100
cmd = [env_python, wheel_tester_path, qmake_path]
101-
print("Disabled running wheel_tester.py while failing with qt6")
102-
# run_instruction(cmd, "Error while running wheel_tester.py")
101+
run_instruction(cmd, "Error while running wheel_tester.py")
103102

104103
def run_test_instructions():
105104
# Remove some environment variables that impact cmake

examples/installer_test/hello.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@
4646
4747
This simple script shows a label with changing "Hello World" messages.
4848
It can be used directly as a script, but we use it also to automatically
49-
test PyInstaller. See testing/wheel_tester.py .
49+
test PyInstaller or Nuitka. See testing/wheel_tester.py .
5050
51-
When used with PyInstaller, it automatically stops its execution after
52-
2 seconds.
51+
When compiled with Nuitka or used with PyInstaller, it automatically
52+
stops its execution after 2 seconds.
5353
"""
5454

5555
import sys
@@ -61,6 +61,11 @@
6161
QVBoxLayout, QWidget)
6262
from PySide6.QtCore import Slot, Qt, QTimer
6363

64+
is_compiled = "__compiled__" in globals() # Nuitka
65+
uses_embedding = sys.pyside_uses_embedding # PyInstaller
66+
auto_quit = "Nuitka" if is_compiled else "PyInst" if uses_embedding else False
67+
68+
6469
class MyWidget(QWidget):
6570
def __init__(self):
6671
QWidget.__init__(self)
@@ -69,7 +74,7 @@ def __init__(self):
6974
"Hola Mundo", "Привет мир"]
7075

7176
self.button = QPushButton("Click me!")
72-
self.text = QLabel("Hello World embedded={}".format(sys.pyside_uses_embedding))
77+
self.text = QLabel("Hello World auto_quit={}".format(auto_quit))
7378
self.text.setAlignment(Qt.AlignCenter)
7479

7580
self.layout = QVBoxLayout()
@@ -94,7 +99,7 @@ def magic(self):
9499
widget = MyWidget()
95100
widget.resize(800, 600)
96101
widget.show()
97-
if sys.pyside_uses_embedding:
102+
if auto_quit:
98103
milliseconds = 2 * 1000 # run 2 second
99104
QTimer.singleShot(milliseconds, app.quit)
100105
retcode = app.exec_()

examples/scriptableapplication/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ endforeach()
7474
# On macOS, check if Qt is a framework build. This affects how include paths should be handled.
7575
get_target_property(QtCore_is_framework Qt6::Core FRAMEWORK)
7676
if (QtCore_is_framework)
77-
get_target_property(qt_core_library_location Qt5::Core LOCATION)
77+
get_target_property(qt_core_library_location Qt6::Core LOCATION)
7878
get_filename_component(qt_core_library_location_dir "${qt_core_library_location}" DIRECTORY)
7979
get_filename_component(lib_dir "${qt_core_library_location_dir}/../" ABSOLUTE)
8080
list(APPEND INCLUDES "--framework-include-paths=${lib_dir}")

examples/widgetbinding/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ endforeach()
126126
# On macOS, check if Qt is a framework build. This affects how include paths should be handled.
127127
get_target_property(QtCore_is_framework Qt6::Core FRAMEWORK)
128128
if (QtCore_is_framework)
129-
get_target_property(qt_core_library_location Qt5::Core LOCATION)
129+
get_target_property(qt_core_library_location Qt6::Core LOCATION)
130130
get_filename_component(qt_core_library_location_dir "${qt_core_library_location}" DIRECTORY)
131131
get_filename_component(lib_dir "${qt_core_library_location_dir}/../" ABSOLUTE)
132132
list(APPEND INCLUDES "--framework-include-paths=${lib_dir}")

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ six
55
wheel>=0.35
66
PyOpenGL
77
pyinstaller==3.6
8+
nuitka

testing/wheel_tester.py

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@
5353
"""
5454

5555
from argparse import ArgumentParser, RawTextHelpFormatter
56+
from pathlib import Path
5657
import os
5758
import sys
59+
import tempfile
5860

5961
try:
6062
this_file = __file__
@@ -111,7 +113,7 @@ def get_examples_dir():
111113

112114

113115
def package_prefix_names():
114-
# Note: shiboken6_generator is not needed for compile_using_pyinstaller,
116+
# Note: shiboken6_generator is not needed for compile_using_nuitka,
115117
# but building modules with cmake needs it.
116118
return ["shiboken6", "shiboken6_generator", "PySide6"]
117119

@@ -225,6 +227,33 @@ def compile_using_pyinstaller():
225227
log.info("")
226228

227229

230+
def test_nuitka(example):
231+
testprog = "Nuitka"
232+
name = os.path.splitext(os.path.basename(example))[0]
233+
print(f"Running {testprog} test of {name}")
234+
current_dir = os.getcwd()
235+
result = False
236+
tmpdirname = tempfile.mkdtemp()
237+
try:
238+
os.chdir(tmpdirname)
239+
cmd = [sys.executable, "-m", "nuitka", "--run", example]#, "--standalone"]
240+
exit_code = run_process(cmd)
241+
result = True
242+
except RuntimeError as e:
243+
print(str(e))
244+
finally:
245+
os.chdir(current_dir)
246+
print(f"Executable is in {tmpdirname}")
247+
return result
248+
249+
250+
def run_nuitka_test(example):
251+
if test_nuitka(example):
252+
log.info("")
253+
else:
254+
raise RuntimeError(f"Failure running {example} with Nuitka.")
255+
256+
228257
def run_make():
229258
args = []
230259
if is_unix():
@@ -287,17 +316,24 @@ def prepare_build_folder(src_path, build_folder_name):
287316
def try_build_examples():
288317
examples_dir = get_examples_dir()
289318

290-
# This script should better go to the last place, here.
291-
# But because it is most likely to break, we put it here for now.
292-
log.info("Attempting to build hello.py using PyInstaller.")
293-
# PyInstaller is loaded by coin_build_instructions.py, but not when
294-
# testing directly this script.
295-
src_path = os.path.join(examples_dir, "installer_test")
296-
prepare_build_folder(src_path, "pyinstaller")
297319

298-
compile_using_pyinstaller()
299-
run_compiled_script(os.path.join(src_path,
300-
"pyinstaller", "dist", "hello_app", "hello_app"))
320+
# Disabled PyInstaller until it supports PySide 6
321+
if False:
322+
# But because it is most likely to break, we put it here for now.
323+
log.info("Attempting to build hello.py using PyInstaller.")
324+
# PyInstaller is loaded by coin_build_instructions.py, but not when
325+
# testing directly this script.
326+
src_path = os.path.join(examples_dir, "installer_test")
327+
prepare_build_folder(src_path, "pyinstaller")
328+
compile_using_pyinstaller()
329+
run_compiled_script(os.path.join(src_path,
330+
"pyinstaller", "dist", "hello_app", "hello_app"))
331+
332+
src_path = Path(examples_dir) / "installer_test"
333+
log.info("Attempting to build hello.py using Nuitka.")
334+
# Nuitka is loaded by coin_build_instructions.py, but not when
335+
# testing directly this script.
336+
run_nuitka_test(os.fspath(src_path / "hello.py"))
301337

302338
log.info("Attempting to build and run samplebinding using cmake.")
303339
src_path = os.path.join(examples_dir, "samplebinding")
@@ -307,11 +343,12 @@ def try_build_examples():
307343
run_make_install()
308344
execute_script(os.path.join(src_path, "main.py"))
309345

310-
log.info("Attempting to build scriptableapplication using cmake.")
311-
src_path = os.path.join(examples_dir, "scriptableapplication")
312-
prepare_build_folder(src_path, "cmake")
313-
generate_build_cmake()
314-
run_make()
346+
log.info("*** Defunct: build scriptableapplication using cmake.")
347+
# log.info("Attempting to build scriptableapplication using cmake.")
348+
# src_path = os.path.join(examples_dir, "scriptableapplication")
349+
# prepare_build_folder(src_path, "cmake")
350+
# generate_build_cmake()
351+
# run_make()
315352

316353
log.info("Attempting to build scriptableapplication using qmake.")
317354
src_path = os.path.join(examples_dir, "scriptableapplication")

0 commit comments

Comments
 (0)