Version Hooks

Goal

Run version specific code before or after an update.

Motivation

Conversation on Discord; Discord

A case for us was to be able to update a rig but change some behaviour of controllers while preserving the animation, for example changing a controller to go in y direction instead of negative x direction. The code for updating the rig while preserving the animation is relatively simple but ensuring it gets executed is very prone to error, so why not use the update mechanism of OpenPype?

Implementation

To be as flexible as possible we could offer code execution before and after the asset version is updated; pre and post hooks.

These pre/post hooks would take the form of python scripts, which reside in the version folder alongside the rest of the asset versions representations.

# pseudo code
class CustomFixRig(VersionPostUpdateHook):
    host = "maya"
    def process(self):
        if not self.current_version == 2 and self.update_version 3:
           return
        # do your magic
        ...

Discussion

How we specify the python scripts when publishing is up for debate. An idea is to just to the new publisher which has the ability to generate temporary instances from (external) files.
Maybe the python script path should be persistent in the workfile?

How do we account for version downgrading and skipping?

How do we deal with version hooks that are wrong or missing code?

Should this be an opt-in feature, so ask users to run pre/post hooks every time they exist?

How do we account for version downgrading and skipping?

This might have to be a learning experience, where we need to use it production to find a consensus for best practice.

How do we deal with version hooks that are wrong or missing code?

Maybe you just publish another version with the correct code.

Should this be an opt-in feature, so ask users to run pre/post hooks every time they exist?

Might be good to have this as a fail-safe, so we can update versions and test code. Or if the version is fine but the code is messing up, the production could still continue.

I’ve moved this to discussions for now as it’s better suited here, until ready for more concrete solution