Tk-desktop "launch_python" hook implementation

Hi!

I tried to implement the tk-desktop “launch_python” hook in my config,
where I put the hook information in the tk-desktop.yml like this:

# site
settings.tk-desktop.site:
  ...
  hook_launch_python: "{config}/tk-desktop/launch_python.py"

# project
settings.tk-desktop.project:
    ...
  hook_launch_python: "{config}/tk-desktop/launch_python.py"

but it does not seem to get executed at all.

When I have a look into the dev console,
it shows this line at some point:

[ DEBUG] : Resolved hook expression (associated with setting 'hook_launch_python'): '{self}/launch_python.py' -> ['C:\\Program Files\\Shotgun\\Resources\\Python\\bundle_cache\\app_store\\tk-desktop\\v2.4.12\\hooks\\launch_python.py']

Did I just implement it in a wrong way or what is happening here?
The custom launch_python.py in my config/hooks/tk-desktop is not being called unfortunately.
It would be nice to get some insight here,

thanks for the help,

cheers
Sebastian

2 Likes

Have you configured your hook on the site config or project config level?

The site wide one is normally updated automatically (pointing to tk-config-basic) and runs before the per-pipeline-config level.

There are some useful docs here about it https://github.com/shotgunsoftware/tk-desktop/wiki/Documentation

I think that in order for you to use the hook_launch_python you would need to take control of the site configuration and add the hook in there.

I’m looking into something like this at the moment too. Trying to avoid having to override the site config but it’s looking inevitable.

5 Likes

Hi, thanks for the infos!

It also looks like I had some serious cache problems with my config yesterday,
but now i got the launch_python working, at least for the py file configured in
“settings.tk-desktop.site”

It looks like that hook gets executed any time a project is chosen in sg desktop.
I will try to check out if thats enough for my purposes,
but just out of interest:

how could I override the site config as you described?
I think thats more what I need in my case right now

Thanks a lot!
cheers

2 Likes

Oh that’s interesting, maybe I was having similar caching issues. It would be really useful to be able to run that hook from the project level! I wasn’t changing the project, just the pipeline config within the project (maybe that makes a difference).

I think you can override the config using TK_BOOTSTRAP_CONFIG_OVERRIDE but I’ve never done it myself.

I’m looking at these docs https://developer.shotgunsoftware.com/tk-core/initializing.html#environment-variables

and I think the framework that handles it is tk-framework-desktopstartup so I’m looking here in the code https://github.com/shotgunsoftware/tk-framework-desktopstartup/blob/3996c3e8e9df3fcbcc3b1ec323c3ba0bc6c3bc62/python/tk-core/python/tank/bootstrap/manager.py#L969

Again I haven’t tried it out, I’m planning to investigate it further as soon as I get a chance.

2 Likes

Yeah I was able to get the hook working by cleaning up my %appdata%/Shotgun and then
restart SG Desktop completely.
It kind of runs with some project/config information, at least it works for me now because it
directly resolves the python interpreter from the configs core .cfg file before running, so I can mess with it a bit :slight_smile:

Anyways, I will have a look into the tk-framework-desktopstartup because that seems pretty interesting for my purposes.
Thanks,

Sebastian

2 Likes

To override the site config, you just need to create a PipelineConfiguration entity on your Shotgun site with no Project assigned in the project field. You could download a copy of the tk-config-basic, make your changes and then upload the config to your PipelineConfiguration entity or use a descriptor to point to it.
A bit like this

4 Likes

Thanks @philip.scadding that is so much easier than what I was planning!

3 Likes

jep, thanks, that helps a lot!

1 Like