Nuke Python Stubs v1.1


 
This location is for Registered Users Only.
Perhaps you need to login or register.
Contributor: Virgil Sisoe
Nuke/Hiero Python stubs files to support auto-complete in text editors.
Requirements:
14.0, 13.2, 13.1, 13.0 or later
Linux, Mac, Windows
17 Oct 2023
30

1. Nuke python stubs file

A quick and dirty script to create Nuke Python file stubs to support auto-complete in text editors.

1.1. Description

A stub file generator for Nuke & Hiero Python 3. Besides including the public API, the script will generate stubs for:

  • Classes.
  • Built-in methods.
  • Constant.
  • Arguments types.
  • Return statements.

1.2. Usage

1.2.1. Generate the stubs

You can use the stub files inside the repository, but if you want to generate them, copy the nukestubsgen.py file inside the Nuke Script Editor and run it.

When generating the stubs, it is preferable to use Nuke Studio, as doing it inside Nuke will cause the Hiero stubs to be incomplete.

Once done, you can find the stubs inside ~/.nuke/nuke-python-stubs/stubs.

There are a couple of settings you can modify inside the main() function:

  • StubsRuntimeSettings.log: Defaults to False. Log everything to console
  • StubsRuntimeSettings.log_to_file: Defaults to False. Log everything to file
  • StubsRuntimeSettings.nuke_extras: A list of existing nuke plugin modules to include in the stubs generation.

1.2.2. Use the stubs

Using the stubs will vary based on your text editor since most of them have their way of adding stubs to the environment.

Alternatively, you can use NukeTools and call the Nuke Tools: Add Python Stubs command.

1.3. Type guess

The script tries to guess the data type by parsing the function signature/documentation. This method is not 100% precise, and some types are unknown or wrong.

  • The type Any means it could be any we don't know and not: any type is valid.
  • The type Number means it could be a float or an int we don't know and not: any number type is valid.
  • Optional arguments are signed as x:type=None for guessed types and x=None for the unguessed.

If arguments do not have any type annotation, it probably means that it was not possible to parse the function documentation.

The wrong types are likely due to the parser identifying valid keywords inside the documentation, which uses them to make a guess.

Example:

In the string: -> switch to next view in settings Views list, the parser will identify list as a match.

You can enable the log or log_to_file options to check what wasn't guessed. You can also disable the guess filter by setting StubsRuntimeSettings.guess to False.

As a workaround, there is a post-fix mechanism which allows you to 'manually' point to the wrong value and substitute it with a new one. You can look at the NUKE_POST_FIXES dictionary for more information.

1.4. Contributing

Although the script is a mess, you can still contribute by adding post-fixes information when you find wrong values.

If you would like to add some code, you need pre-commit installed in your repo.

For convenience, place the repo inside ~/.nuke since the stubs are created inside ~/.nuke/nuke-python-stubs/stubs. This way, git catches any change in the stubs files. Once you generate the stubs, run pre-commit run -a to apply the pre-commit hooks to each file to see the 'real' difference of your new commits.

1.5. Acknowledgment

Pycharm Stub generator inspired the creation of this script.

1.6. Screenshot

Nuke Tools for Visual Studio Code will include the stubs files by default.

Alt text

MIT License Copyright (c) [2021] [Virgil Sisoe] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Please login in order to download these files.

You have no rights to post comments

We have 2786 guests and 41 members online