Configuring env vars on a per-project basis, rather than per-app basis

I have some env vars I would like to set up by project (and not by app) when launching apps from Shotgun Desktop. I’m able to set up my env vars via the before_launch_app hook of the tk-multi-launchapp (as detailed here), but it seems this needs to be replicated on every app’s configuration.

Is there a way I could achieve the same goal by configuring it only once, ie one hook per pipeline configuration? I’ve tried overriding the launch_python hook in tk_desktop but I’m not sure it was designed for that purpose (and on top it doesn’t seem to work, for reasons unknown to me it always launches {self}/launch_python.py, skipping my custom hook configuration).

2 Likes

Hey @ruyman! Welcome to the forums =)

The before_app_launch hook on tk-multi-launchapp is still the way to go, but you should only need to maintain one copy of the customized hook.

The idea is that you make a single copy of before_app_launch, make your modifications there, then in your configuration, just point to that customized hook wherever it’s relevant – and that can be across environments and/or engines (Toolkit engines correspond to DCCs – Maya, Nuke, etc.).

Additionally, Toolkit configurations support the concept of includes, so you can set that value in one place in your config, and then just include it into the different environments/engines. This might be the way to go for minimal configuration maintenance.

This is the configuration block for tk-multi-launchapp in our Default Config that’s included into various environments/engines:

# auto discover DCCs for launch
settings.tk-multi-launchapp:
  use_software_entity: true
  hook_before_register_command: "{config}/tk-multi-launchapp/before_register_command.py"
  location: "@apps.tk-multi-launchapp.location"

So, in a simple example, you’d store your modified copy of the hook at config/env/hooks/before_app_launch.py. Then, you’d just add the following line to the above block:

hook_before_app_launch: "{config}/tk-multi-launchapp/before_app_launch.py"

Of course, there may be other places where you need to make the change (not all instances of tk-multi-launchapp in your config necessarily include from this block), so it’s important to be mindful of that.

A couple side notes:

  • The Software Entity: While you can have individual tk-multi-launchapp instances for each piece of software you want to provide a launcher for, you can also use Software entities in Shotgun to manage your software, then use a single instance of tk-multi-launchapp, with the use_software_entity configuration setting set to True'. You’ll still need to configure the app per-engine and environment (eg, in the project environment, I want to make tk-multi-launchapp available in the tk-desktop engine), but within each engine/environment, you’ll only have one instance, rather than one for Maya, one for Nuke, one for Photoshop, etc. More on the Software entity here.
  • You have a lot of different storage options for your customized hook. {config is just one of them. More about that here

Hopefully that clears things up. Let me know if you still have questions.

1 Like

Hi @tannaz, thank you for detailed explanation and your warm welcome. :blush:

Yes, I’m already using includes, I have one for tk-multi-launchapp where I have all my engines, I was actually looking for a way to avoid having to specify the before_app_launch hook on every engine (even when they all point to same file of course), that’s what I meant by project-based environment. So if I’m understanding correctly your example, my configuration will look something like this:

settings.tk-multi-launchapp.maya:
  ...
  hook_before_app_launch: "{config}/tk-multi-launchapp/before_app_launch.py"


settings.tk-multi-launchapp.nuke:
  ...
  hook_before_app_launch: "{config}/tk-multi-launchapp/before_app_launch.py"


settings.tk-multi-launchapp.my_other_dcc:
  ...
  hook_before_app_launch: "{config}/tk-multi-launchapp/before_app_launch.py"

My last question would be, if I ever have to add some app-specific logic, can I specify a second file for the before_app_launch hook? If yes, what would be the syntax?

1 Like

Ah, I think I’ve found it, that would be the inheritance case, right?

hook_before_app_launch: "{config}/tk-multi-launchapp/before_app_launch.py:{config}/my_second_file.py'

Thanks for your help!

1 Like

Yep, that’s correct!

And again, if you are using the software entity, you’ll have fewer instances of tk-multi-launchapp. So rather than having separate ones for maya, nuke, my_other_dcc, you’ll just have a single one, with use_software_entity set to true, which will generate launchers for all Software that have entities defined and are configured for the current environment.

2 Likes