Faulty `sgtk.bootstrap.ToolkitManager` when bootstrapping a tk-engine


sometimes we want to initialize and bootstrap the tk-engine for DCC ourself.

There seems to be a problem when using sgtk.bootstrap.ToolkitManager.

Simply running this causes an error

mgr = sgtk.bootstrap.ToolkitManager()
engine = mgr.bootstrap_engine("tk-maya", entity=<sg_entity>)

../../../../../../../SG_CONF/p3/install/core/python/tank/api.py:798: in context_from_entity
    return context.from_entity(self, entity_type, entity_id)
../../../../../../../SG_CONF/p3/install/core/python/tank/context.py:1264: in from_entity
    return _from_entity_type_and_id(tk, dict(type=entity_type, id=entity_id))
../../../../../../../SG_CONF/p3/install/core/python/tank/context.py:1315: in _from_entity_type_and_id
    task_context = _task_from_sg(tk, entity_id)
../../../../../../../SG_CONF/p3/install/core/python/tank/context.py:1811: in _task_from_sg
    additional_fields = tk.execute_core_hook("context_additional_entities").get(
../../../../../../../SG_CONF/p3/install/core/python/tank/api.py:111: in execute_core_hook
    hook_name, parent=self, **kwargs
../../../../../../../SG_CONF/p3/install/core/python/tank/pipelineconfig.py:1218: in execute_core_hook_internal
    return_value = hook.execute_hook(hook_path, parent, **kwargs)
../../../../../../../SG_CONF/p3/install/core/python/tank/hook.py:577: in execute_hook
    return execute_hook_method([hook_path], parent, None, **kwargs)
../../../../../../../SG_CONF/p3/install/core/python/tank/hook.py:618: in execute_hook_method
    hook = create_hook_instance(hook_paths, parent, base_class=base_class)
../../../../../../../SG_CONF/p3/install/core/python/tank/hook.py:710: in create_hook_instance

E           tank.util.loader.TankLoadPluginError: Error loading the file '/mnt/ps-storage01/vfx_hgd_000/SG_CONF/p3/install/core/hooks/context_additional_entities.py'. Couldn't find a single class deriving from 'Hook'. You need to have exactly one class defined in the file deriving from that base class. If your file looks fine, it is possible that the cached .pyc file that python generates is invalid and this is causing the error. In that case, please delete the .pyc file and try again.

../../../../../../../SG_CONF/p3/install/core/python/tank/util/loader.py:136: TankLoadPluginError

Also previously in older sgtk versions I think it would pick the pipeline configuration alphabetically instead of taking it from the current sgtk module.

form pprint import pprint
mgr = sgtk.bootstrap.ToolkitManager()
pcs = mgr.get_pipeline_configurations(<project_entity>)

# would always take config in `pcs[0]`(Primary) here instead for example `pc[1]`(my_dev_config)

I found the workaround by setting a member variable on the mgr object yourself.
This would fix the wrong alphabetical look up I encountered earlier and the error that I am getting at when this variable is not set.

mgr = sgtk.bootstrap.ToolkitManager()
mgr.pipeline_configuration = <pipeline_configuration_id> # (int)

What is the correct way of using sgtk.bootstrap.ToolkitManager for the current pipeline configuration ?

And how should the tk-engine be bootstrapped ?

The issue seems to be with your hook file context_additional_entities, rather than toolkit manager. It says it did not find a single instance of Hook in the module, as it should.

1 Like