Python 3 support

Starting with version 0.59.0.0, Python 3.7 is officially supported by Gaffer (whoop!).

We’ve had to make a few changes here and there to support this, but every day life should be largely unaffected. However, if you have issues loading older script, read on for more details…

None_, Nadda, Nowt

One of the changes in Python 3 is that None is fully enforced as a reserved word. There are many cases in Gaffer (and Cortex) where we used None as a possible value for an enum, for example, GafferUI.Frame.BorderStyle. This would typically be used as follows:

frame = GafferUI.Frame( borderStyle = GafferUI.Frame.BorderStyle.None )

This throws a SyntaxError in Python 3.

We toyed with a variety of alternate colloquial alternatives for None, but ultimately ended up with the somewhat conventional None_.

Since version 0.58.0.0 all enums that used to use None, have been updated to use None_ instead. In the Python 2 builds of Gaffer, we provide a compatibility shim that supports the loading of older scripts, writing updated values when they are re-saved.

Oy vey

In Python 3 builds of Gaffer, we’re unable to support None as an enum value. If you attempt to open a script saved from Gaffer 0.57 or older, you may see an error such as this:

Fortunately, this is relatively easy to fix. You can either:

  • Open and re-save the script using a Python 2 build of Gaffer 0.58 or later.
  • Manually fix the script with a little sed help on the command line.

Sed

sed is a very helpful command line tool that allows you to search and replace within a file. The following one-liner should update make a copy of an existing script ready to go :

sed 's/\.None\([ ),]\)/.None_\1/g' myOldScript.gfr > myOldScript-py3.gfr

Further Reading

Leave a Reply