Hook inherit from base class and multiple location

I had asked the following question in support forum but I was advised to post here for general knowledge

For the loader/shotgun panel actions and collections hooks, we have these spread across many locations. The path of these are stored in various environment variables. How do we register these hooks without using “:”, which according to the documentation states denotes inheritance chain.

The answer I got from Shotgun was

You can configure the app to get the hook from a path using an environment variable using the following:

  • {$HOOK_PATH}/path/to/foo.py – expression based around an environment variable. taken from our core documentation

I don’t think this has answered my question.

What I was wondering if the following hook configuration was supported.
{$HOOK_PATH}/path/to/foo.py;{$HOOK_LOCATION_2}/path/to/fooBar.py;{$HOOK_PATH}/path/to/foo.py:{$HOOK_LOCATION_50/path/to/fooChild.py

1 Like

Hi Pritish

Welcome to the forums and thanks for posting this here!

The following is supported:

"{$HOOK_PATH}/path/to/foo.py:{$HOOK_LOCATION_50}/path/to/fooChild.py"

This will mean that the hook class in fooChild.py will derive from the class in foo.py.

However, this syntax isn’t supported:

"{$HOOK_PATH}/path/to/foo.py;{$HOOK_LOCATION_2}/path/to/fooBar.py;"

I assume by the syntax you would like to provide a list of locations in which to look for the hook?
If that is the case then I think you could make use of the template.py hook to resolve the path you want to use.

Here is a simple example of how to do that. Using the publisher collector hook as an example you could set the publisher settings to:

settings.tk-multi-publish2.standalone:
  collector: "hook:find_hook_location:{$BROKEN_PATH}/broken_collector.py:{$FIRST_PATH}/first_collector.py:{$SECOND_PATH}/second_collector.py"

And copy the template hook to your config/core/hooks directory and rename it to find_hook_location.py.
Then inside the hook you could check each passed path to see if it exists, and if it does then you could stop and return it. You could expand upon this and get more complicated if you needed hook inheritance and multiple paths.

Note: If you are using the template hook, the : characters don’t represent inheritance anymore. Instead, all colons after the hook name represent separate parameters to be passed to the hook.

Here is an example of the hook which loops over the provided paths, checks if they exist and returns the first one that does: find_hook_location.py (3.0 KB)

Hope that helps?

Thanks
Phil

3 Likes

Thank for that. We would look into this. Is there anything on the roadmap to support this?

2 Likes

I don’t believe we have any plans to natively support lists of search paths, but you could submit a request here:
https://www.shotgunsoftware.com/roadmap/

Best
Phil

2 Likes