Last active
June 15, 2025 09:31
-
-
Save artandmath/af1d82b0b71440533033b1cbbaf3c008 to your computer and use it in GitHub Desktop.
Cursor rule for running tests when creating Qt based user interfaces in Foundry Nuke.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # General guidelines | |
| Keep it simple | |
| Use as few lines as possible, but not at the sacrifice of readibility, safety and functionality. | |
| When planning a complex code change, always start with a plan of action and then ask me for approval on that plan. | |
| For simple changes, just make the code change but always think carefully and step-by-step about the change itself. | |
| When a function becomes too long, split it into smaller functions. | |
| When debugging a problem, make sure you have sufficient information to deeply understand the problem. | |
| More often than not, opt in to adding more logging and tracing to the code to help you understand the problem before making any changes. If you are provided logs that make the source of the problem obvious, then implement a solution. If you're still not 100% confident about the source of the problem, then reflect on 4-6 different possible sources of the problem, distill those down to 1-2 most likely sources, and then implement a solution for the most likely source - either adding more logging to validate your theory or implement the actual fix if you're extremely confident about the source of the problem. | |
| # Python code style is PEP8: | |
| https://peps.python.org/pep-0008/ | |
| # Qt/PySide Development for Nuke | |
| ## Testing Qt Applications in Nuke | |
| When creating or testing Qt/PySide applications that need to run in Nuke: | |
| ### Use Nuke Terminal Mode Instead of Python | |
| Replace standard `python script.py` commands with Nuke's terminal GUI mode: | |
| ```powershell | |
| & 'C:\Program Files\Nuke15.1v1\Nuke15.1.exe' --tg script.py | |
| ``` | |
| ### When to Use Nuke Terminal Mode | |
| - Testing Qt widgets and panels that will be integrated into Nuke | |
| - Debugging PySide2/PySide6 compatibility issues | |
| - Testing inheritance systems that depend on Nuke's Qt environment | |
| - Validating UI behavior in Nuke's specific Qt context | |
| - Avoiding relative import issues when testing Nuke plugins | |
| ### Nuke Qt Best Practices | |
| 1. **PySide Version Detection**: Always detect Nuke version for correct PySide import: | |
| ```python | |
| import nuke | |
| if nuke.NUKE_VERSION_MAJOR >= 16: | |
| from PySide6 import QtWidgets, QtCore, QtGui | |
| else: | |
| from PySide2 import QtWidgets, QtCore, QtGui | |
| ``` | |
| 2. **Keep Windows Responsive**: In Nuke terminal mode, process Qt events in a low code manner to maintain responsiveness. | |
| Use the time.sleep method for low code tests only, don't use it in production: | |
| ```python | |
| while True: | |
| QtWidgets.QApplication.processEvents() | |
| time.sleep(0.001) | |
| if not window.isVisible(): | |
| break | |
| ``` | |
| 3. **Prevent Garbage Collection in tests**: Store global references to prevent Qt widgets from being destroyed: | |
| ```python | |
| globals()['_widget_reference'] = widget | |
| ``` | |
| 4. **Path Resolution**: When testing from subdirectories, adjust import paths: | |
| ```python | |
| path = os.path.join(os.path.dirname(__file__), '..', '..', 'dev_module_parent') | |
| # or be more direct: path = "/path/to/dev_module_parent" | |
| sys.path.insert(0, path) | |
| ``` | |
| ### Nuke Command Line Options | |
| - `--tg`: Terminal GUI mode (keeps Qt event loop active) | |
| - `--nc`: No crash reporter | |
| - `--safe`: Safe mode (minimal plugins) | |
| ### Example Test Structure | |
| ```python | |
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| """Qt test for Nuke environment.""" | |
| import sys | |
| import os | |
| import time | |
| # Path setup for Nuke testing | |
| # Qt tests to located in /dev_module_parent/tests/qt | |
| path = os.path.join(os.path.dirname(__file__), '..', '..', 'dev_module_parent') | |
| sys.path.insert(0, path) | |
| # Nuke-compatible PySide imports | |
| import nuke | |
| if nuke.NUKE_VERSION_MAJOR >= 16: | |
| from PySide6 import QtWidgets, QtCore, QtGui | |
| else: | |
| from PySide2 import QtWidgets, QtCore, QtGui | |
| def main(): | |
| widget = MyQtWidget() | |
| widget.show() | |
| # Keep alive for Nuke terminal mode | |
| globals()['_test_widget'] = widget | |
| try: | |
| while True: | |
| QtWidgets.QApplication.processEvents() | |
| time.sleep(0.001) | |
| if not widget.isVisible(): | |
| break | |
| except KeyboardInterrupt: | |
| pass | |
| return widget | |
| if __name__ == "__main__": | |
| main() | |
| ``` | |
| ### Testing Commands | |
| - **Nuke Qt Test**: `& 'C:\Program Files\Nuke15.1v1\Nuke15.1.exe' --tg tests/qt/test_file.py` | |
| - **Logic Only Test**: `python tests/logic_test.py` (no Qt dependencies) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment